/**
 * Main CSS - Design Tokens, Reset, Base Styles
 * Company Map UK
 */

/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */

/* Default theme (fallback) */
:root {
  /* Colors - Primary */
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-primary-light: #dbeafe;

  /* Colors - Secondary */
  --color-secondary: #8b5cf6;
  --color-secondary-hover: #7c3aed;

  /* Colors - Status */
  --color-success: #10b981;
  --color-error: #ef4444;
  --color-warning: #f59e0b;
  --color-info: #06b6d4;

  /* Grays */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Background */
  --bg-primary: #ffffff;
  --bg-secondary: var(--gray-50);
  --bg-panel: #ffffff;
  --bg-hover: var(--gray-100);

  /* Borders */
  --border-color: var(--gray-200);
  --border-color-hover: var(--gray-300);
  --border-accent: rgba(0, 153, 204, 0.3);

  /* Text */
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-muted: var(--gray-500);

  /* Spacing */
  --space-1: 0.25rem;   /* 4px */
  --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 */

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;

  --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 */

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

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  --shadow-floating: 0 12px 40px rgba(0, 0, 0, 0.12);

  /* Border Radius */
  --radius-sm: 0.25rem;  /* 4px */
  --radius: 0.375rem;    /* 6px */
  --radius-md: 0.5rem;   /* 8px */
  --radius-lg: 0.75rem;  /* 12px */
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;

  /* Z-index */
  --z-header: 100;
  --z-controls: 200;
  --z-modal: 1000;

  /* Layout dimensions */
  --header-height: auto; /* Flexible header height */
}

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

html {
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ============================================
   App Layout
   ============================================ */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;      /* fallback for old browsers */
  height: 100dvh;     /* fit the VISIBLE viewport on mobile so the footer isn't below the browser chrome */
  overflow: hidden;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  padding: var(--space-4) var(--space-6);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  z-index: var(--z-header);
}

/* Home link (top-left) — matches the icon buttons. */
.header-home {
  text-decoration: none;
  flex: 0 0 auto;
}

/* Brand title — desktop only (hidden on mobile where the header is just icons). */
.header-title {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-left: var(--space-3);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

.header-title__name {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: var(--text-primary);
}

.header-title__tag {
  font-size: var(--text-sm);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hero stat — the visible/filtered company count. Sits in the header on desktop
   (right-aligned, next to the actions); wraps to its own full-width row on mobile. */
.visible-bar {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-left: auto;   /* push count + actions to the right */
  min-width: 0;
  white-space: nowrap;   /* single line — never reflow when the number changes */
  overflow: hidden;
}

.visible-bar__count {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.visible-bar__label {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.visible-bar__filtered {
  color: var(--color-primary);
  font-weight: var(--font-semibold);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: var(--space-5);   /* .visible-bar's margin-left:auto right-aligns both */
  flex: 0 0 auto;
}

.export-btn {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  white-space: nowrap;
}

/* Main Content */
.app-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Subtle footer — data attribution + a few links, thin and muted. */
.app-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-6);
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.app-footer__info {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;   /* never grow the bar's height */
}

.app-footer__links {
  display: flex;
  gap: var(--space-4);
  flex: 0 0 auto;
}

.app-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.app-footer a:hover {
  color: var(--color-primary);
}

@media (max-width: 768px) {
  .app-footer {
    padding: var(--space-2) var(--space-4);
    font-size: 0.7rem;
    gap: var(--space-3);
  }
}

.map-section {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.sidebar-section {
  display: none; /* Hidden - no sidebar in map-only mode */
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  /* Mobile header — home (left) + actions (right) on the first row; the
     visible count wraps to its own full-width bar underneath. */
  .app-header {
    padding: var(--space-2) 0 0;
    gap: 0;
    flex-wrap: wrap;
  }

  .visible-bar {
    flex: 1 1 100%;
    order: 10;   /* below home + actions */
    margin: var(--space-2) 0 0;
    padding: var(--space-2) var(--space-4);
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
  }

  .visible-bar__count {
    font-size: var(--text-xl);
  }

  /* Home icon inset from the screen edge on mobile (header has no side padding here). */
  .header-home {
    margin-left: var(--space-3);
    margin-right: var(--space-2);
  }

  /* Icons-only header on mobile — no room for the brand title. */
  .header-title {
    display: none;
  }

  /* Actions (right side) */
  .header-actions {
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4) var(--space-2) 0;
  }

  .export-btn {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
  }

  .help-icon-btn {
    padding: var(--space-2);
  }

  .help-icon-btn .material-icons {
    font-size: 20px;
  }
}

/* ============================================
   Utility Classes
   ============================================ */
.text-muted {
  color: var(--text-muted);
}

.text-error {
  color: var(--color-error);
}

.text-success {
  color: var(--color-success);
}

.hidden {
  display: none !important;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
