/**
 * Meenira Realty Console Design System
 * Version: 1.0
 * 
 * Indian real-estate broker console optimized for mobile and desktop.
 * Supports light and dark modes via prefers-color-scheme.
 * 
 * No external dependencies — self-contained.
 */

/* ===== IMPORT TOKENS FROM BRAND KIT ===== */
@import url('brand/tokens.css');

/* ===== FONT FACE DECLARATIONS ===== */
@font-face {
  font-family: 'Baloo 2';
  src: url('brand/typography/fonts/Baloo2-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Baloo 2';
  src: url('brand/typography/fonts/Baloo2-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Baloo 2';
  src: url('brand/typography/fonts/Baloo2-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Baloo 2';
  src: url('brand/typography/fonts/Baloo2-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Baloo 2';
  src: url('brand/typography/fonts/Baloo2-ExtraBold.ttf') format('truetype');
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Sans';
  src: url('brand/typography/fonts/NotoSans-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Sans';
  src: url('brand/typography/fonts/NotoSans-Italic.ttf') format('truetype');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Sans';
  src: url('brand/typography/fonts/NotoSans-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Sans';
  src: url('brand/typography/fonts/NotoSans-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Sans';
  src: url('brand/typography/fonts/NotoSans-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ===== CSS CUSTOM PROPERTIES (TOKENS) ===== */
:root {
  /* Brand colors */
  --brand-50: #ecfdf5;
  --brand-100: #d1fae5;
  --brand-200: #a7f3d0;
  --brand-500: #10b981;
  --brand-600: #059669;
  --brand-700: #047857;
  --brand-900: #064e3b;

  /* Neutral scale */
  --gray-0: #ffffff;
  --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;

  /* Semantic colors */
  --success-100: #dcfce7;
  --success-500: #22c55e;
  --success-600: #16a34a;
  --warning-100: #fef3c7;
  --warning-500: #f59e0b;
  --warning-600: #d97706;
  --error-100: #fee2e2;
  --error-500: #ef4444;
  --error-600: #dc2626;
  --info-100: #dbeafe;
  --info-500: #3b82f6;
  --info-600: #2563eb;

  /* Background application */
  --bg-page: #f6f7f8;
  --bg-surface: var(--gray-0);
  --bg-elevated: var(--gray-0);
  --bg-subtle: var(--gray-50);
  --bg-muted: var(--gray-100);

  /* Text-colors */
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-tertiary: var(--gray-500);
  --text-disabled: var(--gray-400);
  --text-on-brand: var(--gray-0);

  /* Borders */
  --border-default: var(--gray-200);
  --border-subtle: var(--gray-100);
  --border-focus: var(--brand-600);

  /* Status colors */
  --status-new-bg: #dbeafe;
  --status-new-fg: #1e40af;
  --status-new-bg: #e0f2fe;
  --status-new-fg: #0369a1;
  --status-qualifying-bg: #dcfce7;
  --status-qualifying-fg: #15803d;
  --status-qualified-bg: #d1fae5;
  --status-qualified-fg: #166534;
  --status-visit_booked-bg: #fef3c7;
  --status-visit_booked-fg: #b45309;
  --status-visited-bg: #ecfdf5;
  --status-visited-fg: #047857;
  --status-negotiating-bg: #fce7f3;
  --status-negotiating-fg: #be185d;
  --status-token-bg: #f3e8ff;
  --status-token-fg: #7c3aed;
  --status-agreement-bg: #ecfeff;
  --status-agreement-fg: #0e7490;
  --status-registry-bg: #eef2ff;
  --status-registry-fg: #4338ca;
  --status-won-bg: #dcfce7;
  --status-won-fg: #166534;
  --status-lost-bg: #fee2e2;
  --status-lost-fg: #991b1b;

  /* Spacing scale (in rem - base is 16px) */
  --space-0: 0;
  --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 */

  /* Border radius */
  --radius-sm: 0.25rem;  /* 4px */
  --radius-md: 0.5rem;   /* 8px */
  --radius-lg: 0.75rem;  /* 12px */
  --radius-xl: 1rem;     /* 16px */
  --radius-full: 9999px;

  /* 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), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

  /* Typography */
  --font-display: "Baloo 2", "Noto Sans", system-ui, sans-serif;
  --font-sans: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, 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 */
  --text-3xl: 1.875rem;  /* 30px */

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

  --line-tight: 1.25;
  --line-normal: 1.5;
  --line-relaxed: 1.75;

  /* Z-index */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal: 300;

  /* Sidebar / Navigation */
  --sidebar-width: 240px;
  --bottom-nav-height: 56px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
}

/* Dark mode override */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #0f1115;
    --bg-surface: #1a1d23;
    --bg-elevated: #22262d;
    --bg-subtle: #16191e;
    --bg-muted: #1f232a;

    --text-primary: #f3f4f6;
    --text-secondary: #a1a7b3;
    --text-tertiary: #6b7280;
    --text-disabled: #4b5563;
    --text-on-brand: #f3f4f6;

    --border-default: #374151;
    --border-subtle: #1f2937;
    --border-focus: var(--brand-500);
    
    /* Higher contrast in dark mode for secondary text */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #a1a7b3;
    --gray-600: #c1c5cc;
    --gray-700: #d1d5db;
    --gray-800: #e5e7eb;
    --gray-900: #f3f4f6;

    --status-new-bg: #1e3a5f;
    --status-new-fg: #60a5fa;
    --status-qualifying-bg: #14532d;
    --status-qualifying-fg: #86efac;
    --status-qualified-bg: #166534;
    --status-qualified-fg: #bbf7d0;
    --status-visit_booked-bg: #78350f;
    --status-visit_booked-fg: #fcd34d;
    --status-visited-bg: #064e3b;
    --status-visited-fg: #6ee7b7;
    --status-negotiating-bg: #831843;
    --status-negotiating-fg: #fbcfe8;
    --status-token-bg: #5b21b6;
    --status-token-fg: #ddd6fe;
    --status-agreement-bg: #164e63;
    --status-agreement-fg: #a5f3fc;
    --status-registry-bg: #312e81;
    --status-registry-fg: #c7d2fe;
    --status-won-bg: #14532d;
    --status-won-fg: #86efac;
    --status-lost-bg: #7f1d1d;
    --status-lost-fg: #fca5a5;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
  }
}

/* ===== BASE RESET ===== */
*, *::before, *::after {
  box-sizing: border-box;
}

* { margin: 0; }

html {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: var(--line-normal);
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  background: var(--bg-page);
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

a {
  color: var(--brand-600);
  text-decoration: none;
}

@media (prefers-color-scheme: dark) {
  a { color: var(--brand-500); }
}

a:hover {
  text-decoration: underline;
}

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

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== UTILITY CLASSES ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-1 { flex: 1 1 0%; }

.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 640px) {
  .sm\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
  .sm\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 768px) {
  .md\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
  .md\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
  .lg\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
  .lg\:grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
}

.w-full { width: 100%; }
.h-full { height: 100%; }
.min-h-screen { min-height: 100vh; }

.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }

.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }

.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-disabled { color: var(--text-disabled); }
.text-error { color: var(--error-500); }
@media (prefers-color-scheme: dark) { .text-error { color: var(--error-400); } }
.text-success { color: var(--success-600); }

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== APP SHELL ===== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Desktop sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sticky);
}

.sidebar-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

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

.brand-logo {
  width: 32px;
  height: 32px;
  background: var(--brand-600);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-on-brand);
  font-weight: var(--font-bold);
  font-size: var(--text-sm);
}

.brand-logo-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.brand-logo-icon svg {
  width: 100%;
  height: 100%;
}

.brand-name {
  font-weight: var(--font-semibold);
  font-size: var(--text-base);
  color: var(--text-primary);
  line-height: var(--line-tight);
}

.brand-tagline {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  transition: background var(--transition-fast), color var(--transition-fast);
  margin-bottom: var(--space-1);
}

.nav-item:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-item.active {
  background: var(--brand-50);
  color: var(--brand-700);
}

@media (prefers-color-scheme: dark) {
  .nav-item.active {
    background: var(--brand-900);
    color: var(--brand-200);
  }
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

.user-info {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--brand-100);
  color: var(--brand-700);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
}

@media (prefers-color-scheme: dark) {
  .user-avatar {
    background: var(--brand-900);
    color: var(--brand-200);
  }
}

.user-details { flex: 1; min-width: 0; }
.user-name { font-weight: var(--font-medium); font-size: var(--text-sm); color: var(--text-primary); display: block; }
.user-role { font-size: var(--text-xs); color: var(--text-tertiary); }
.user-business { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: 2px; }

.owner-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  background: var(--brand-100);
  color: var(--brand-700);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

@media (prefers-color-scheme: dark) {
  .owner-badge {
    background: var(--brand-900);
    color: var(--brand-200);
  }
}

/* Main content area */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: var(--space-6);
  padding-bottom: calc(var(--space-6) + var(--bottom-nav-height));
  min-height: 100vh;
  max-width: 1400px;
}

/* Desktop: full width with proper max-width */
@media (min-width: 1280px) {
  .main-content {
    padding: var(--space-8);
  }
}

/* Larger type scale for desktop */
@media (min-width: 768px) {
  /* Increase base font size on desktop */
  html {
    font-size: 18px;
  }
  
  /* Larger page titles */
  .page-header h1 {
    font-size: var(--text-3xl);
  }
  
  /* Better table experience */
  .data-table-responsive {
    display: table;
    width: 100%;
  }
}

/* Tables on desktop - full width */
@media (min-width: 768px) {
  .table-container {
    margin: 0 calc(-1 * var(--space-4));
    padding: 0 var(--space-4);
    width: calc(100% + var(--space-8));
  }
}

/* Page header */
.page-header {
  margin-bottom: var(--space-6);
}

.page-header h1 {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: var(--text-base);
}

/* Mobile bottom navigation */
@media (max-width: 767px) {
  .sidebar { display: none; }
  .main-content {
    margin-left: 0;
    padding: var(--space-4);
    padding-bottom: calc(var(--space-6) + var(--bottom-nav-height));
  }
  
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bg-surface);
    border-top: 1px solid var(--border-default);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: var(--z-sticky);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  
  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    height: 100%;
    color: var(--text-tertiary);
    font-size: 10px;
    font-weight: var(--font-medium);
    text-decoration: none;
  }
  
  .bottom-nav-item.active {
    color: var(--brand-600);
  }
  
  .bottom-nav-item svg {
    width: 24px;
    height: 24px;
  }
  
  /* More menu overlay */
  .more-menu {
    display: none;
    position: fixed;
    bottom: var(--bottom-nav-height);
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-default);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
    z-index: var(--z-dropdown);
  }
  
  .more-menu.open { display: block; }
  
  .more-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
  }
}

@media (min-width: 768px) {
  .bottom-nav { display: none; }
  .more-menu { display: none !important; }
}

/* ===== COMPONENTS ===== */

/* Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: var(--space-4) var(--space-4) var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}

.card-body {
  padding: var(--space-4);
}

.card-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* KPI/Stat tiles */
.kpi-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

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

.kpi-value.positive { color: var(--success-600); }
.kpi-value.negative { color: var(--error-500); }

.kpi-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

.kpi-caption {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-1);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.625rem var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1.25;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: var(--text-on-brand);
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-700);
  border-color: var(--brand-700);
}

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-default);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-muted);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-default);
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--error-500);
  border-color: var(--error-500);
  color: var(--gray-0);
}

.btn-danger:hover:not(:disabled) {
  background: var(--error-600);
  border-color: var(--error-600);
}

.btn-outline-danger {
  background: transparent;
  border-color: var(--error-500);
  color: var(--error-500);
}

.btn-outline-danger:hover:not(:disabled) {
  background: var(--error-50);
  color: var(--error-600);
}

.btn-sm { padding: 0.375rem var(--space-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-base); }
.btn-icon { padding: var(--space-2); }

/* Form controls */
.form-group { margin-bottom: var(--space-4); }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.form-label .required::after {
  content: ' *';
  color: var(--error-500);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-1);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--error-500);
  margin-top: var(--space-1);
}

.form-success {
  font-size: var(--text-sm);
  color: var(--success-700, #15803d);
  margin-top: var(--space-1);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 0.625rem var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: var(--text-sm);
  line-height: 1.5;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border-focus);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--brand-100);
}

@media (prefers-color-scheme: dark) {
  .input:focus,
  .select:focus,
  .textarea:focus {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
  }
}

.input:disabled,
.select:disabled {
  background: var(--bg-muted);
  cursor: not-allowed;
}

.input::placeholder { color: var(--text-disabled); }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
}

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
  padding: var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
}

.filter-group { flex: 1; min-width: 160px; max-width: 280px; }
.filter-group label { 
  display: block; 
  font-size: var(--text-xs); 
  font-weight: var(--font-medium); 
  color: var(--text-secondary); 
  margin-bottom: var(--space-1);
}

.filter-actions { display: flex; gap: var(--space-2); }

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  line-height: 1.25;
  white-space: nowrap;
}

.badge-new { background: var(--status-new-bg); color: var(--status-new-fg); }
.badge-qualifying { background: var(--status-qualifying-bg); color: var(--status-qualifying-fg); }
.badge-qualified { background: var(--status-qualified-bg); color: var(--status-qualified-fg); }
.badge-visit_booked { background: var(--status-visit_booked-bg); color: var(--status-visit_booked-fg); }
.badge-visited { background: var(--status-visited-bg); color: var(--status-visited-fg); }
.badge-negotiating { background: var(--status-negotiating-bg); color: var(--status-negotiating-fg); }
.badge-token { background: var(--status-token-bg); color: var(--status-token-fg); }
.badge-agreement { background: var(--status-agreement-bg); color: var(--status-agreement-fg); }
.badge-registry { background: var(--status-registry-bg); color: var(--status-registry-fg); }
.badge-won { background: var(--status-won-bg); color: var(--status-won-fg); }
.badge-lost { background: var(--status-lost-bg); color: var(--status-lost-fg); }

/* Tables */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table th,
.data-table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table th {
  font-weight: var(--font-semibold);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  background: var(--bg-muted);
  white-space: nowrap;
}

.data-table th:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.data-table th:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; }

.data-table tbody tr:hover {
  background: var(--bg-subtle);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Data cards (mobile-friendly tables) */
.data-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.data-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.data-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-3);
}

.data-card-title {
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.data-card-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

.data-card-field {
  font-size: var(--text-sm);
}

.data-card-field-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-bottom: 2px;
}

/* Responsive: show cards on mobile, table on desktop */
@media (max-width: 1023px) {
  .data-table-responsive { display: none; }
}
@media (min-width: 1024px) {
  .data-cards-responsive { display: none; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-10) var(--space-4);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  color: var(--text-disabled);
}
  
.empty-state-icon svg {
  width: 100%;
  height: 100%;
  stroke-width: 1.5;
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.empty-state-desc {
  color: var(--text-secondary);
  margin-bottom: var(--space-6);
}

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg-muted) 25%, var(--bg-subtle) 50%, var(--bg-muted) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text { height: 1em; margin-bottom: var(--space-2); }
.skeleton-text:last-child { width: 60%; }
.skeleton-avatar { width: 40px; height: 40px; border-radius: var(--radius-full); }
.skeleton-card { height: 120px; }

/* Error state */
.error-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
}

.error-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  color: var(--error-500);
}

.error-state-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.error-state-desc {
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

/* Alert banner */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

.alert-error {
  background: var(--error-100);
  border: 1px solid var(--error-500);
  color: var(--error-600);
}

@media (prefers-color-scheme: dark) {
  .alert-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--error-500);
    color: var(--error-400);
  }
}

.alert-success {
  background: var(--success-100);
  border: 1px solid var(--success-500);
  color: var(--success-600);
}

@media (prefers-color-scheme: dark) {
  .alert-success {
    background: rgba(34, 197, 94, 0.1);
    border-color: var(--success-500);
    color: var(--success-400);
  }
}

.alert-warning {
  background: var(--warning-100);
  border: 1px solid var(--warning-500);
  color: var(--warning-700);
}

@media (prefers-color-scheme: dark) {
  .alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: var(--warning-500);
    color: var(--warning-400);
  }
}

/* Chip/Pill */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
}

/* Timeline */
.timeline {
  position: relative;
  padding-left: var(--space-6);
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border-default);
}

.timeline-item {
  position: relative;
  padding-bottom: var(--space-4);
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: calc(-1 * var(--space-6) + 4px);
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--brand-500);
  border: 2px solid var(--bg-surface);
}

.timeline-item.incoming::before { background: var(--info-500); }
.timeline-item.outgoing::before { background: var(--brand-500); }
.timeline-item.event::before { background: var(--gray-400); }

.timeline-content {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.timeline-time {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-bottom: var(--space-1);
}

.timeline-title {
  font-weight: var(--font-medium);
  margin-bottom: var(--space-1);
}

.timeline-body {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* Audit detail display — human-readable key-value pairs, no raw JSON */
.audit-detail {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--border-default);
}

.audit-detail-item {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.audit-detail-item:last-child {
  border-bottom: none;
}

.audit-detail-label {
  font-weight: var(--font-medium);
  color: var(--text-tertiary);
  flex-shrink: 0;
  min-width: 80px;
}

.audit-detail-label::after {
  content: ":";
}

.audit-detail-value {
  color: var(--text-secondary);
  word-wrap: break-word;
  font-family: var(--font-mono);
  font-size: 0.875em;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

.pagination-btn {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pagination-btn:hover:not(:disabled) {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination-btn.active {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: var(--text-on-brand);
}

.pagination-info {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* Page actions */
.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

/* Detail view */
.detail-section {
  margin-bottom: var(--space-6);
}

.detail-section-title {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-3);
  color: var(--text-primary);
}

.detail-grid {
  display: grid;
  gap: var(--space-4);
}

@media (min-width: 768px) {
  .detail-grid { grid-template-columns: repeat(2, 1fr); }
}

.detail-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.detail-label {
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
}

.detail-value {
  font-size: var(--text-base);
  color: var(--text-primary);
}

/* Modal/Dialog base */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 100%;
  max-height: calc(100vh - var(--space-8));
  overflow: auto;
}

.modal-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-body {
  padding: var(--space-4);
}

.modal-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* Visits specific */
.visit-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

.visit-status-scheduled { background: var(--info-100); color: var(--info-600); }
.visit-status-confirmed { background: var(--success-100); color: var(--success-600); }
.visit-status-done { background: var(--status-token-bg); color: var(--status-token-fg); }
.visit-status-no_show { background: var(--error-100); color: var(--error-600); }
.visit-status-cancelled { background: var(--warning-100); color: var(--warning-700); }

@media (prefers-color-scheme: dark) {
  .visit-status-scheduled { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
  .visit-status-confirmed { background: rgba(16, 185, 129, 0.2); color: #86efac; }
  .visit-status-done { background: rgba(124, 58, 237, 0.2); color: #c4b5fd; }
  .visit-status-no_show { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
  .visit-status-cancelled { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
}

/* Login specific */
.login-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--bg-page);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  box-shadow: var(--shadow-md);
}

.login-brand {
  text-align: center;
  margin-bottom: var(--space-6);
}

.login-brand-logo {
  width: 48px;
  height: 48px;
  background: var(--brand-600);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-3);
  color: white;
  font-weight: var(--font-bold);
  font-size: var(--text-xl);
}

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

.login-brand-tagline {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* Tooltip (simple attribute-based) */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-2);
  background: var(--gray-800);
  color: white;
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  z-index: var(--z-dropdown);
}

/* Sign out icon sizing (AA2) */
.sidebar-footer .btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Mobile KPI grid 2x2 layout (AA6) */
@media (max-width: 767px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* Hide Quick Actions on mobile - redundant with bottom nav */
  #quickActionsCard {
    display: none !important;
  }
}

/* ===== FUNNEL CHART ===== */
.funnel-chart {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.funnel-bar {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  align-items: center;
  gap: var(--space-3);
}

@media (min-width: 768px) {
  .funnel-bar {
    grid-template-columns: 120px 1fr 60px;
    gap: var(--space-4);
  }
}

.funnel-bar-label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  text-align: right;
}

.funnel-bar-track {
  height: 24px;
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

@media (min-width: 768px) {
  .funnel-bar-track {
    height: 28px;
  }
}

.funnel-bar-fill {
  height: 100%;
  background: var(--brand-500);
  border-radius: var(--radius-sm);
  transition: width 0.3s ease;
}

@media (prefers-color-scheme: dark) {
  .funnel-bar-fill {
    background: var(--brand-600);
  }
}

.funnel-bar-value {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  min-width: 2ch;
  text-align: right;
}


