/**
 * 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;
  overflow: hidden;
}

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

.header-brand-link {
  text-decoration: none;
  color: inherit;
  transition: opacity 0.2s ease;
}

.header-brand-link:hover {
  opacity: 0.8;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-icon {
  width: 28px;
  height: 28px;
  color: var(--color-primary);
}

.brand-text {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
}

.header-stats {
  display: flex;
  gap: var(--space-8);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

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

.stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.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;
}

.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 - Multi-row Layout */
  .app-header {
    flex-wrap: wrap;
    padding: 0;
    gap: 0;
  }

  /* Row 1: Brand/Logo - Full width, centered, different background */
  .header-brand-link {
    width: 100%;
    order: 1;
    display: block;
    text-align: center;
    padding: var(--space-3) var(--space-4);
    background: var(--gray-50);
    border-bottom: 1px solid var(--border-color);
  }

  .header-brand {
    justify-content: center;
    gap: var(--space-2);
  }

  .brand-icon {
    width: 32px;
    height: 32px;
  }

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

  /* Row 2: Stats (left side) */
  .header-stats {
    order: 2;
    flex: 1;
    gap: var(--space-3);
    justify-content: flex-start;
    padding: var(--space-3) 0 var(--space-3) var(--space-4);
  }

  /* Hide "Total Companies" stat (static, never changes) */
  .stat-item:first-child {
    display: none;
  }

  .stat-item {
    align-items: flex-start;
  }

  .stat-value {
    font-size: var(--text-lg);
  }

  .stat-label {
    font-size: 0.7rem;
  }

  /* Row 2: Actions (right side) */
  .header-actions {
    order: 3;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4) var(--space-3) 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); }
}
