/* BBL GIS Immobilienportfolio - Design Tokens & Base Styles */
/* Identical in prototype-simple and prototype-tabs (see docs/DESIGN-REVIEW.md); change both copies together. */

/* ===== CSS CUSTOM PROPERTIES ===== */
:root {
  /* Grey Scale - Cold blue-grey */
  --grey-900: #2D3236;
  --grey-800: #3D4347;
  --grey-700: #4E555A;
  --grey-600: #5E666B;
  --grey-500: #6C757D;
  --grey-400: #A0A8AE;
  --grey-300: #C5CCD1;
  --grey-200: #DDE2E6;
  --grey-100: #F3F5F7;
  --grey-50: #F9FAFB;

  /* Brand Colors */
  --accent-panel: #6C757D;
  --primary-red: #c00;
  --primary-red-dark: #a00;
  --primary-red-tint: rgba(204, 0, 0, 0.06);
  --primary-red-tint-hover: rgba(204, 0, 0, 0.08);
  --primary-red-tint-hover: rgba(204, 0, 0, 0.08);
  --primary-red-tint-hover: rgba(204, 0, 0, 0.08);
  --white: #ffffff;

  /* Interactive Blue */
  --interactive-blue: #005ea8;
  --focus-ring: var(--interactive-blue);

  /* Overlays: controls and text on dark surfaces (lightbox, tools panel), veils and scrims */
  --on-dark-rest: rgba(255, 255, 255, 0.1);
  --on-dark-hover: rgba(255, 255, 255, 0.2);
  --on-dark-divider: rgba(255, 255, 255, 0.2);
  --on-dark-muted: rgba(255, 255, 255, 0.5);
  --on-dark-text: rgba(255, 255, 255, 0.85);
  --veil-light: rgba(255, 255, 255, 0.92);   /* loading overlay, map busy pill, carousel buttons */
  --scrim: rgba(0, 0, 0, 0.5);               /* modal and menu backdrops, image labels */
  --scrim-strong: rgba(0, 0, 0, 0.92);       /* lightbox */
  --spinner-track: rgba(128, 128, 128, 0.3);

  /* Status Colors */
  --status-active: #2e7d32;
  --status-active-bg: #e8f5e9;
  --status-active-text: #1b5e20;

  --status-renovation: #ef6c00;
  --status-renovation-bg: #fff3e0;
  --status-renovation-text: #e65100;

  --status-planning: #1976d2;
  --status-planning-bg: #e3f2fd;
  --status-planning-text: #0d47a1;

  --status-inactive: #6C757D;
  --status-inactive-bg: var(--grey-100);
  --status-inactive-text: #5E666B;

  --status-error: #d32f2f;
  --status-error-bg: #ffebee;
  --status-error-text: #c62828;

  --status-warning: #f57c00;
  --status-warning-bg: #fff3e0;
  --status-warning-text: #e65100;

  /* ===== TYPOGRAPHY SYSTEM ===== */
  --text-xs: 0.75rem;     /* 12px */
  --text-sm: 0.875rem;    /* 14px */
  --text-base: 1rem;      /* 16px */
  --text-lg: 1.125rem;    /* 18px */
  --text-xl: 1.25rem;     /* 20px */
  --text-2xl: 1.5rem;     /* 24px */

  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  --tracking-wide: 0.05em;
  --tracking-wider: 0.08em;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;

  /* ===== SPACING SYSTEM ===== */
  --space-0: 0;
  --space-0-5: 0.125rem;  /* 2px  — half steps for hairline gaps and progress bars */
  --space-1: 0.25rem;     /* 4px */
  --space-1-5: 0.375rem;  /* 6px */
  --space-2: 0.5rem;      /* 8px */
  --space-3: 0.75rem;     /* 12px */
  --space-4: 1rem;        /* 16px */
  --space-5: 1.25rem;     /* 20px */
  --space-6: 1.5rem;      /* 24px */
  --space-8: 2rem;        /* 32px */
  --space-10: 2.5rem;     /* 40px */
  --space-12: 3rem;       /* 48px */
  --space-16: 4rem;       /* 64px */

  /* ===== COMPONENT TOKENS ===== */
  --radius-sm: 0.25rem;   /* 4px */
  --radius-md: 0.5rem;    /* 8px */
  --radius-lg: 0.75rem;   /* 12px */
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-xl: 0 4px 16px rgba(0, 0, 0, 0.2);
  --shadow-sheet: 0 -4px 16px rgba(0, 0, 0, 0.18);   /* bottom sheets */
  --shadow-menu: -4px 0 16px rgba(0, 0, 0, 0.15);    /* slide-in menus */

  /* Lines: dividers in three strengths and the rings of floating elements */
  --border-strong: 1px solid var(--grey-300);   /* container edges: panels, inputs, cards, table heads */
  --border-default: 1px solid var(--grey-200);  /* section dividers inside a container */
  --border-subtle: 1px solid var(--grey-100);   /* row dividers */
  --ring-subtle: 0 0 0 1px rgba(0, 0, 0, 0.1);  /* legend swatches */
  --accent-bar: 3px;                            /* left rule of the active tree node and of toasts */
  --opacity-disabled: 0.5;

  --touch-target-min: 44px;
  --control-height: 40px;   /* header controls on desktop (44px on touch screens) */
  --control-2xs: 20px;      /* count badges, tiny round buttons */
  --control-xs: 24px;       /* inline icon buttons in lists and rows */
  --control-sm: 32px;       /* toolbar controls, panel-header icon buttons */
  --control-lg: 48px;       /* lightbox navigation, loading spinner */
  --map-control-size: 29px; /* MapLibre's control buttons */
  --dot-size: 10px;         /* carousel dots, measure markers */

  /* ===== ICON SIZE SYSTEM ===== */
  --icon-xs: 14px;
  --icon-sm: 16px;
  --icon-md: 18px;
  --icon-lg: 20px;
  --icon-xl: 24px;
  --icon-2xl: 36px;
  --icon-display: 48px;
  --icon-hero: 64px;

  /* ===== TRANSITION SYSTEM ===== */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
  --transition-slow: 0.3s ease;

  /* ===== Z-INDEX SCALE ===== */
  --z-map-overlay: 400;   /* print crop preview */
  --z-panel: 500;         /* tools panel, info panel, basemap switcher */
  --z-sheet: 650;         /* info panel as bottom sheet (phones) */
  --z-header: 1000;       /* header, measure display */
  --z-popover: 1001;      /* context menu, prototype banner, dropdown menus */
  --z-drawer: 2000;       /* filter drawer (phones), search results */
  --z-menu: 2100;         /* slide-in menu (phones) and its backdrop (2099) */
  --z-overlay: 9999;      /* loading overlay, lightbox */
  --z-toast: 10000;
  --z-modal: 10001;

  /* ===== LAYOUT SYSTEM ===== */
  --header-main-height: 90px;
  --header-detail-height: 124px;
  --footer-height: 27px;
  --header-total-height: calc(var(--header-main-height) + var(--header-detail-height));

  --side-panel-default-width: 320px; /* matching defaults; each panel can still be resized independently */
  --drawer-width: var(--side-panel-default-width);
  --drawer-min-width: 300px;
  --drawer-max-width: 800px;

  --tools-panel-width: 300px;
  --tree-panel-width: var(--side-panel-default-width);
  --tree-panel-min-width: 240px;
  --tree-panel-max-width: 600px;
  --content-max-width: 1500px;
  --page-gutter: var(--space-10); /* side padding of page views (view nav, detail, API docs): 40px; 20px on laptops, 16px on tablets, 12px on phones */

  /* ===== CHECKBOX ACCENT ===== */
  --checkbox-accent: var(--primary-red);
}

/* ===== RESET ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Form controls do not inherit the font by default (UA: Arial 13.33px); every button, input and
   select uses the app font, size and colour of its context unless a component sets its own. */
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* ===== BASE ===== */
body {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* dynamic viewport: excludes the mobile browser chrome */
  overflow: hidden;
  color: var(--grey-900);
}

/* ===== KEYFRAMES ===== */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== FOCUS & ACCESSIBILITY ===== */
*:focus:not(:focus-visible) {
  outline: none;
}

*:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.view-toggle-btn:focus-visible,
.dropdown-btn:focus-visible,
.header-btn:focus-visible {
  z-index: 1;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--grey-900);
  color: var(--white);
  padding: var(--space-2) var(--space-4);
  z-index: var(--z-toast);
  text-decoration: none;
  font-size: var(--text-sm);
}

.skip-link:focus {
  top: 0;
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .loading-spinner,
  .spinner {
    animation: none;
    opacity: 0.7;
  }
}

/* ===== SHARED PRIMITIVES ===== */

/* Badge — inline status/category label (.status-badge adds the colour variants) */
.badge {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  line-height: 1;
  white-space: nowrap;
}

/* Custom select — consistent dropdown appearance */
.custom-select {
  appearance: none;
  padding: var(--space-2) var(--space-8) var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  border: var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E") no-repeat right var(--space-2) center;
  color: var(--grey-900);
  cursor: pointer;
  min-height: var(--control-sm);
}

.custom-select:hover {
  border-color: var(--grey-500);
}

.custom-select:focus {
  outline: none;
  border-color: var(--interactive-blue);
}

/* Checkbox — consistent sizing and brand accent (20px on touch screens, see components.css) */
input[type="checkbox"] {
  width: var(--icon-sm);
  height: var(--icon-sm);
  cursor: pointer;
  accent-color: var(--checkbox-accent);
}

/* Primary Button */
.btn-primary {
  background: var(--grey-900);
  color: var(--white);
  border: none;
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: var(--leading-normal);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: background var(--transition-normal);
  min-height: var(--control-height);
}

.btn-primary:hover { background: var(--grey-700); }
.btn-primary:active { background: var(--grey-900); }

/* Secondary Button */
.btn-secondary {
  background: var(--white);
  color: var(--grey-900);
  border: var(--border-strong);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: var(--leading-normal);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: background var(--transition-normal), border-color var(--transition-normal);
  min-height: var(--control-height);
}

.btn-secondary:hover {
  background: var(--grey-100);
  border-color: var(--grey-500);
}

/* Tertiary Button (text-only) */
.btn-tertiary {
  background: transparent;
  color: var(--grey-700);
  border: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  transition: background var(--transition-normal), color var(--transition-normal);
  min-height: var(--control-height);
}

.btn-tertiary:hover {
  background: var(--grey-100);
  color: var(--grey-900);
}

/* Icon Button — icon only, no border; the title / aria-label carries the name. 32px by default,
   --xs 24px (inline in rows), --md 40px, --lg 48px; --round; --on-dark on dark surfaces (lightbox).
   44px on touch screens (components.css). Rest colour grey-600 (grey-500 for --xs): at least 4.5:1. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: var(--control-sm);
  height: var(--control-sm);
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--grey-600);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.icon-btn:hover {
  background: var(--grey-200);
  color: var(--grey-900);
}

.icon-btn .material-symbols-outlined {
  font-size: var(--icon-lg);
}

.icon-btn--xs {
  width: var(--control-xs);
  height: var(--control-xs);
  color: var(--grey-500);
}

.icon-btn--xs .material-symbols-outlined {
  font-size: var(--icon-md);
}

.icon-btn--md {
  width: var(--control-height);
  height: var(--control-height);
}

.icon-btn--lg {
  width: var(--control-lg);
  height: var(--control-lg);
}

.icon-btn--lg .material-symbols-outlined {
  font-size: var(--icon-2xl);
}

.icon-btn--round {
  border-radius: var(--radius-full);
}

.icon-btn--on-dark {
  background: var(--on-dark-rest);
  color: var(--on-dark-text);
}

.icon-btn--on-dark:hover {
  background: var(--on-dark-hover);
  color: var(--white);
}

/* Panel header (filter drawer, side panels) */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-default);
  background: var(--grey-50);
  flex-shrink: 0;
  gap: var(--space-3);
}

.panel-header-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  line-height: 1;
  color: var(--grey-900);
}

.panel-header-title .material-symbols-outlined {
  font-size: var(--icon-sm);
  color: var(--grey-600);
}

/* Empty & Loading States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-5);
  text-align: center;
  color: var(--grey-600);
}

.empty-state .material-symbols-outlined {
  font-size: var(--icon-hero);
  color: var(--grey-300);
  margin-bottom: var(--space-4);
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--grey-900);
  margin-bottom: var(--space-2);
  line-height: var(--leading-snug);
}

.empty-state-description {
  font-size: var(--text-sm);
  color: var(--grey-600);
  max-width: 400px;
  line-height: var(--leading-normal);
}

.empty-state-action {
  margin-top: var(--space-5);
}

.table-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-5);
  text-align: center;
  color: var(--grey-500);
}

.table-empty-state .material-symbols-outlined {
  font-size: var(--icon-display);
  color: var(--grey-300);
  margin-bottom: var(--space-3);
}

.table-empty-message {
  font-size: var(--text-sm);
  color: var(--grey-600);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--grey-200);
  border-top-color: var(--primary-red);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
  will-change: transform;
}

.loading-text {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  color: var(--grey-600);
}
