/* ==========================================================================
   HUSSLE CRM — Design System (Inspired by ALINA CRM)
   Premium light/dark theme, sidebar layout, full component library
   ========================================================================== */

/* ==========================================================================
   1. CSS Custom Properties
   ========================================================================== */

:root {
  /* Backgrounds — Dark by default (original Hussle) */
  --bg: #1a1a1a;
  --bg-card: #2a2a2a;
  --bg-alt: #212121;
  --bg-hover: #333333;
  --bg-input: #1e1e1e;

  /* Accent (Warm Tan — original Hussle brand) */
  --accent: #d4a27a;
  --accent-hover: #b8896a;
  --accent-light: rgba(212, 162, 122, 0.15);
  --accent-ring: rgba(212, 162, 122, 0.25);

  /* Text */
  --text: #f5f5f5;
  --text-secondary: #d4d4d4;
  --text-tertiary: #a0a0a0;
  --text-inverse: #1a1a1a;

  /* Borders */
  --border: #383838;
  --border-light: #2e2e2e;

  color-scheme: dark;

  /* Status Colors */
  --status-new: #3B82F6;
  --status-qualified: #8B5CF6;
  --status-quoted: #F59E0B;
  --status-awaiting: #F97316;
  --status-booked: #10B981;
  --status-in-progress: #06B6D4;
  --status-completed: #22C55E;
  --status-lost: #EF4444;
  --status-reengage: #EC4899;

  /* Status Backgrounds (dark tints) */
  --status-new-bg: rgba(59, 130, 246, 0.14);
  --status-qualified-bg: rgba(139, 92, 246, 0.14);
  --status-quoted-bg: rgba(245, 158, 11, 0.14);
  --status-awaiting-bg: rgba(249, 115, 22, 0.14);
  --status-booked-bg: rgba(16, 185, 129, 0.14);
  --status-in-progress-bg: rgba(6, 182, 212, 0.14);
  --status-completed-bg: rgba(34, 197, 94, 0.14);
  --status-lost-bg: rgba(239, 68, 68, 0.14);
  --status-reengage-bg: rgba(236, 72, 153, 0.14);

  /* Semantic */
  --danger-bg: rgba(229, 115, 115, 0.1);
  --danger-text: #e57373;
  --warning-bg: rgba(255, 183, 77, 0.1);
  --warning-text: #ffb74d;
  --info-bg: rgba(100, 181, 246, 0.1);
  --info-text: #64b5f6;
  --success-bg: rgba(129, 199, 132, 0.1);
  --success-text: #81c784;

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-xs: 0.75rem;
  --font-sm: 0.8125rem;
  --font-base: 0.875rem;
  --font-md: 1rem;
  --font-lg: 1.125rem;
  --font-xl: 1.25rem;
  --font-2xl: 1.5rem;
  --font-3xl: 1.875rem;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.35);
  --shadow-xl: 0 20px 30px rgba(0, 0, 0, 0.4);

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 64px;
  --bottom-nav-height: 56px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Z-index */
  --z-sidebar: 100;
  --z-topbar: 90;
  --z-overlay: 200;
  --z-modal: 300;
  --z-toast: 400;
}

/* ==========================================================================
   1b. Dark Theme
   ========================================================================== */

[data-theme="light"] {
  --bg: #FAFAF8;
  --bg-card: #FFFFFF;
  --bg-alt: #F7F5F2;
  --bg-hover: #F0EDE8;
  --bg-input: #FFFFFF;

  --accent: #C9A96E;
  --accent-hover: #B8943D;
  --accent-light: rgba(201, 169, 110, 0.10);
  --accent-ring: rgba(201, 169, 110, 0.25);

  --text: #1A1A1A;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --text-inverse: #FFFFFF;

  --border: #E5E7EB;
  --border-light: #F3F4F6;

  --status-new-bg: #EFF6FF;
  --status-qualified-bg: #F5F3FF;
  --status-quoted-bg: #FFFBEB;
  --status-awaiting-bg: #FFF7ED;
  --status-booked-bg: #ECFDF5;
  --status-in-progress-bg: #ECFEFF;
  --status-completed-bg: #F0FDF4;
  --status-lost-bg: #FEF2F2;
  --status-reengage-bg: #FDF2F8;

  --danger-bg: #FEE2E2;
  --danger-text: #DC2626;
  --warning-bg: #FEF3C7;
  --warning-text: #D97706;
  --info-bg: #DBEAFE;
  --info-text: #2563EB;
  --success-bg: #D1FAE5;
  --success-text: #059669;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.06), 0 4px 6px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.08), 0 8px 10px rgba(0, 0, 0, 0.04);

  color-scheme: light;
}

/* Dark overrides */
[data-theme="light"] input,
[data-theme="light"] select,
[data-theme="light"] textarea {
  background-color: var(--bg-input);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] input::placeholder,
[data-theme="light"] textarea::placeholder {
  color: var(--text-tertiary);
}
[data-theme="light"] input:focus,
[data-theme="light"] select:focus,
[data-theme="light"] textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
[data-theme="light"] option {
  background: var(--bg-card);
  color: var(--text);
}
[data-theme="light"] .sidebar {
  background: var(--bg-alt);
  border-color: var(--border);
}
[data-theme="light"] .card,
[data-theme="light"] .table-wrap {
  background: var(--bg-card);
  border-color: var(--border);
}
[data-theme="light"] hr { border-color: var(--border); }

/* Theme toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: block; }
.theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }


/* ==========================================================================
   2. Reset & Base
   ========================================================================== */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-base);
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
img, svg { display: block; max-width: 100%; }

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

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

table { border-collapse: collapse; width: 100%; }

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}
h1 { font-size: var(--font-3xl); }
h2 { font-size: var(--font-2xl); }
h3 { font-size: var(--font-xl); }

p { color: var(--text-secondary); line-height: 1.6; }

::selection {
  background-color: var(--accent-light);
  color: var(--text);
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--border); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background-color: var(--text-tertiary); }

.hidden { display: none !important; }
.overflow-hidden { overflow: hidden !important; }


/* ==========================================================================
   3. Layout: Sidebar + Main + Mobile
   ========================================================================== */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
  transition: transform var(--transition-slow);
}

.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  padding: 24px;
  max-width: 1440px;
}

/* Mobile header */
.mobile-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
}

.mobile-logo {
  font-size: var(--font-lg);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.mobile-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}


/* ==========================================================================
   4. Sidebar: Logo, Nav, User
   ========================================================================== */

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-light);
}

.logo-text {
  font-size: var(--font-lg);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
}

.logo-sub {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--font-sm);
  font-weight: 500;
  transition: all var(--transition-fast);
  position: relative;
  margin: 1px 0;
  text-decoration: none;
}

.nav-item:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text);
}
[data-theme="light"] .nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent-hover);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

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

.nav-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: white;
  font-size: 0.6875rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.nav-badge.danger { background: var(--danger-text); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border-light);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-xs);
  font-weight: 600;
  flex-shrink: 0;
  text-transform: uppercase;
}

.user-info { flex: 1; min-width: 0; }
.user-name {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
}

.logout-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: all var(--transition-fast);
}
.logout-btn:hover {
  background: var(--bg);
  color: var(--danger-text);
}


/* ==========================================================================
   5. Page Top Bar
   ========================================================================== */

.page-top-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-wrap: wrap;
}

.page-title {
  font-size: var(--font-xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  white-space: nowrap;
  margin: 0;
}


/* ==========================================================================
   6. Search & Filters
   ========================================================================== */

.search-box { position: relative; }

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  min-width: 220px;
  height: 40px;
  padding: 0 12px 0 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  font-size: var(--font-sm);
  transition: all var(--transition-fast);
}
.search-input::placeholder { color: var(--text-tertiary); }
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
  background: var(--bg-card);
}

.filter-select {
  height: 40px;
  padding: 0 32px 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  font-size: var(--font-sm);
  color: var(--text);
  appearance: none;
  background-image: 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='%236B7280' d='M6 8.825a.5.5 0 0 1-.354-.146l-3.5-3.5a.5.5 0 1 1 .708-.708L6 7.618l3.146-3.147a.5.5 0 1 1 .708.708l-3.5 3.5A.5.5 0 0 1 6 8.825z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: all var(--transition-fast);
  cursor: pointer;
  white-space: nowrap;
}
.filter-select:hover { border-color: var(--text-tertiary); }
.filter-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}


/* ==========================================================================
   7. Stats Strip
   ========================================================================== */

.stats-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:active { transform: scale(0.98); }

.stat-label {
  font-size: var(--font-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.stat-value {
  font-size: var(--font-2xl);
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.stat-value.alert { color: var(--danger-text); }


/* ==========================================================================
   8. Stage Pills Bar
   ========================================================================== */

.stage-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stage-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--font-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  cursor: pointer;
  text-decoration: none;
}
.stage-pill:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-light);
}
.stage-pill.active {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--accent-light);
  font-weight: 600;
}
.stage-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.stage-pill .cnt {
  font-weight: 600;
  color: var(--text);
  font-size: var(--font-xs);
}

.unc-count {
  background: var(--danger-text);
  color: #fff;
  border-radius: var(--radius-full);
  padding: 1px 7px;
  font-size: 0.6875rem;
  font-weight: 600;
}


/* ==========================================================================
   9. Data Table
   ========================================================================== */

.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-scroll { overflow-x: auto; }

table { width: 100%; }

thead th {
  padding: 10px 16px;
  font-size: var(--font-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
  user-select: none;
}

tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition-fast);
  cursor: pointer;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

tbody td {
  padding: 12px 16px;
  font-size: var(--font-sm);
  color: var(--text);
  vertical-align: middle;
}

tr.duplicate td { opacity: 0.45; }


/* ==========================================================================
   10. Status Badges
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.04em;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-new        { background: var(--status-new-bg); color: var(--status-new); }
.badge-qualified  { background: var(--status-qualified-bg); color: var(--status-qualified); }
.badge-quoted     { background: var(--status-quoted-bg); color: var(--status-quoted); }
.badge-awaiting_decision { background: var(--status-awaiting-bg); color: var(--status-awaiting); }
.badge-booked     { background: var(--status-booked-bg); color: var(--status-booked); }
.badge-in_progress { background: var(--status-in-progress-bg); color: var(--status-in-progress); }
.badge-completed  { background: var(--status-completed-bg); color: var(--status-completed); }
.badge-lost       { background: var(--status-lost-bg); color: var(--status-lost); }
.badge-reengage   { background: var(--status-reengage-bg); color: var(--status-reengage); }

.dupe-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--danger-bg);
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  color: var(--danger-text);
  margin-left: 6px;
  font-weight: 500;
}


/* ==========================================================================
   11. Contact Cell
   ========================================================================== */

.contact-name {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text);
}
.contact-phone {
  font-size: var(--font-xs);
  color: var(--text-secondary);
  margin-top: 1px;
}
.vehicle {
  font-size: var(--font-sm);
  color: var(--text-secondary);
}
.channel-tag {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
}
.time {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
}


/* ==========================================================================
   12. SLA Badges
   ========================================================================== */

.sla {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 600;
  white-space: nowrap;
}
.sla-ok   { background: var(--success-bg); color: var(--success-text); }
.sla-warn { background: var(--warning-bg); color: var(--warning-text); }
.sla-crit { background: var(--danger-bg); color: var(--danger-text); }


/* ==========================================================================
   13. Cards
   ========================================================================== */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}

.card h3 {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

.card-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  font-size: var(--font-sm);
}
.card-row .label { color: var(--text-secondary); min-width: 70px; flex-shrink: 0; }
.card-row .value { color: var(--text); font-weight: 500; text-align: right; min-width: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}


/* ==========================================================================
   14. Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  font-size: var(--font-sm);
  font-weight: 600;
  line-height: 1.4;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  font-family: var(--font-family);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn:active:not(:disabled) { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 2px 8px rgba(201, 169, 110, 0.35);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover {
  border-color: var(--text-tertiary);
  background: var(--bg);
}

.btn-danger {
  color: var(--danger-text);
  border-color: rgba(220, 38, 38, 0.3);
  background: transparent;
}
.btn-danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger-text);
}

.btn-success {
  color: var(--success-text);
  border-color: rgba(5, 150, 105, 0.3);
  background: transparent;
}
.btn-success:hover {
  background: var(--success-bg);
  border-color: var(--success-text);
}

.btn-sm {
  padding: 6px 12px;
  font-size: var(--font-xs);
  border-radius: var(--radius-sm);
}

.btn-xs {
  padding: 4px 10px;
  font-size: 0.6875rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 12px 24px;
  font-size: var(--font-md);
  border-radius: var(--radius-md);
}


/* ==========================================================================
   15. Forms
   ========================================================================== */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group-full { grid-column: 1 / -1; }

.form-label {
  display: block;
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}
.form-label .required {
  color: var(--danger-text);
  margin-left: 2px;
}

.form-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  font-size: var(--font-sm);
  color: var(--text);
  transition: all var(--transition-fast);
  font-family: var(--font-family);
}
.form-input::placeholder { color: var(--text-tertiary); }
.form-input:hover { border-color: var(--text-tertiary); }
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.form-input.input-error {
  border-color: var(--danger-text) !important;
}

select.form-input {
  appearance: none;
  background-image: 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='%236B7280' d='M6 8.825a.5.5 0 0 1-.354-.146l-3.5-3.5a.5.5 0 1 1 .708-.708L6 7.618l3.146-3.147a.5.5 0 1 1 .708.708l-3.5 3.5A.5.5 0 0 1 6 8.825z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.form-textarea {
  min-height: 100px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.6;
  height: auto;
}

.form-section-title {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
  margin-top: 8px;
  margin-bottom: 16px;
}


/* ==========================================================================
   16. Sections (Lead detail page)
   ========================================================================== */

.section { margin-bottom: 32px; }

.section h2 {
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}


/* ==========================================================================
   17. Notes
   ========================================================================== */

.note {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.note.ai-note {
  border-left: 3px solid var(--accent);
}
.note-meta {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.note-body {
  font-size: var(--font-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text);
}


/* ==========================================================================
   18. Tasks
   ========================================================================== */

.task {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  font-size: var(--font-sm);
  box-shadow: var(--shadow-sm);
}
.task-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.task-due {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  margin-left: auto;
  white-space: nowrap;
}
.task.overdue { border-color: rgba(220, 38, 38, 0.25); }
.task.overdue .task-due { color: var(--danger-text); }
.task.done { opacity: 0.5; }


/* ==========================================================================
   19. Activity Log
   ========================================================================== */

.event {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  font-size: var(--font-sm);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  align-items: center;
}
.event-type {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: var(--font-xs);
  background: var(--bg-alt);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.event-time {
  margin-left: auto;
  white-space: nowrap;
  font-size: var(--font-xs);
  color: var(--text-tertiary);
}


/* ==========================================================================
   20. Lead Header
   ========================================================================== */

.lead-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.lead-header h1 {
  font-size: var(--font-2xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.lead-header .meta {
  font-size: var(--font-sm);
  color: var(--text-tertiary);
  margin-top: 4px;
}
.lead-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}


/* ==========================================================================
   21. Stage Form
   ========================================================================== */

.stage-form {
  display: flex;
  gap: 10px;
  align-items: center;
}
.stage-form select {
  padding: 8px 32px 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--font-sm);
  font-family: var(--font-family);
  appearance: none;
  background-image: 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='%236B7280' d='M6 8.825a.5.5 0 0 1-.354-.146l-3.5-3.5a.5.5 0 1 1 .708-.708L6 7.618l3.146-3.147a.5.5 0 1 1 .708.708l-3.5 3.5A.5.5 0 0 1 6 8.825z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}


/* ==========================================================================
   22. Follow-up Box
   ========================================================================== */

.followup-box {
  background: var(--success-bg);
  border: 1px solid rgba(5, 150, 105, 0.25);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 28px;
}
.followup-box h2 { color: var(--success-text); }


/* ==========================================================================
   23. Back Link
   ========================================================================== */

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  transition: all var(--transition-fast);
}
.back:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-light);
}


/* ==========================================================================
   24. Copy Button
   ========================================================================== */

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-tertiary);
  font-size: var(--font-xs);
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-left: auto;
}
.copy-btn:hover { border-color: var(--text-tertiary); color: var(--text-secondary); }
.copy-btn svg { width: 14px; height: 14px; }
.copy-btn.copied {
  border-color: rgba(5, 150, 105, 0.4);
  color: var(--success-text);
  background: var(--success-bg);
}


/* ==========================================================================
   25. Delete Confirm
   ========================================================================== */

.delete-confirm {
  display: none;
  background: var(--danger-bg);
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 24px;
}
.delete-confirm.show { display: block; }
.delete-confirm p { font-size: var(--font-sm); color: var(--danger-text); margin-bottom: 10px; }


/* ==========================================================================
   26. Error Box
   ========================================================================== */

.error-box {
  background: var(--danger-bg);
  border: 1px solid rgba(220, 38, 38, 0.25);
  color: var(--danger-text);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
  margin-bottom: 18px;
}


/* ==========================================================================
   27. Empty State
   ========================================================================== */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
  font-size: var(--font-md);
}


/* ==========================================================================
   28. Login Page
   ========================================================================== */

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  padding: 20px;
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-box h1 {
  font-size: var(--font-xl);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.login-box .sub {
  font-size: var(--font-sm);
  color: var(--text-tertiary);
  margin-bottom: 30px;
}

.login-box .form-group {
  margin-bottom: 16px;
}


/* ==========================================================================
   29. Phone Link
   ========================================================================== */

.phone-link {
  color: var(--accent);
  font-weight: 600;
  transition: color var(--transition-fast);
}
.phone-link:hover { text-decoration: underline; }


/* ==========================================================================
   30. Modals
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: var(--font-lg);
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: all var(--transition-fast);
}
.modal-close:hover { background: var(--bg-alt); color: var(--text); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}


/* ==========================================================================
   31. Bottom Nav (Mobile)
   ========================================================================== */

.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: var(--z-topbar);
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-tertiary);
  font-size: 0.625rem;
  font-weight: 500;
  transition: color var(--transition-fast);
  text-decoration: none;
}
.bottom-nav-item:hover,
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item svg { width: 22px; height: 22px; }


/* ==========================================================================
   32. Mobile FAB
   ========================================================================== */

.fab {
  display: none;
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + 16px + env(safe-area-inset-bottom));
  right: 16px;
  width: 52px;
  height: 52px;
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: var(--radius-full);
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-topbar);
  border: none;
  cursor: pointer;
  transition: all var(--transition-base);
}
.fab:hover { background: var(--accent-hover); transform: scale(1.05); }


/* ==========================================================================
   33. Animations
   ========================================================================== */

@keyframes crm-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes crm-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes crm-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: crm-spin 0.6s linear infinite;
  margin: 40px auto;
}

.alert-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger-text);
  animation: crm-pulse 2s ease-in-out infinite;
}


/* ==========================================================================
   34. Responsive
   ========================================================================== */

@media (max-width: 1200px) {
  .stats-strip {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 1024px) {
  .stats-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar { display: none !important; }
  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-bottom: calc(var(--bottom-nav-height) + 16px + env(safe-area-inset-bottom));
  }

  .mobile-header { display: flex; }
  .bottom-nav { display: flex; }
  .fab { display: flex; }

  .desktop-only { display: none !important; }
  .mobile-only { display: flex !important; }

  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }

  .page-top-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .top-bar-right {
    margin-left: 0;
    flex-wrap: wrap;
  }

  .page-title { font-size: var(--font-lg); }

  .lead-header {
    flex-direction: column;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal-content {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-width: 100%;
    max-height: 90vh;
  }

  .stats-strip {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stat-card { padding: 14px; }
  .stat-value { font-size: var(--font-xl); }
}

@media (max-width: 480px) {
  .main-content { padding: 12px; padding-bottom: calc(var(--bottom-nav-height) + 12px + env(safe-area-inset-bottom)); }
  .stage-bar { gap: 6px; }
  .stage-pill { padding: 5px 10px; font-size: var(--font-xs); }
  .login-box { padding: 28px; }
}


/* ==========================================================================
   35. Utility Classes
   ========================================================================== */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.w-full { width: 100%; }
.text-sm { font-size: var(--font-xs); }
.text-muted { color: var(--text-secondary); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }

/* ==========================================================================
   Dashboard — Action Queue
   ========================================================================== */
.action-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border: 1px solid var(--border);
  border-radius: var(--radius-md); margin-bottom: 8px;
  background: var(--bg); transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  cursor: pointer; text-decoration: none; color: inherit;
}
.action-item:hover { background: var(--bg-hover); border-color: var(--text-tertiary); box-shadow: var(--shadow-sm); }
.action-item:last-child { margin-bottom: 0; }
.action-item.action-critical { border-left: 3px solid var(--danger-text); }
.action-item.action-urgent   { border-left: 3px solid var(--warning-text); }
.action-item.action-today    { border-left: 3px solid var(--info-text); }
.action-item.action-soon     { border-left: 3px solid var(--success-text); }

.action-urgency { flex-shrink: 0; }
.action-badge {
  display: inline-block; padding: 3px 10px;
  font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; border-radius: var(--radius-full);
}
.action-badge.action-critical { background: var(--danger-bg); color: var(--danger-text); animation: pulse-badge 1.5s ease-in-out infinite; }
.action-badge.action-urgent   { background: var(--warning-bg); color: var(--warning-text); }
.action-badge.action-today    { background: var(--info-bg); color: var(--info-text); }
.action-badge.action-soon     { background: var(--success-bg); color: var(--success-text); }

@keyframes pulse-badge { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

.action-body { flex: 1; min-width: 0; }
.action-title { font-size: var(--font-base); font-weight: 600; color: var(--text); margin-bottom: 2px; }
.action-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: var(--font-xs); color: var(--text-tertiary); margin-bottom: 4px; }
.action-reason { font-size: var(--font-sm); color: var(--text-secondary); }
.action-arrow { flex-shrink: 0; color: var(--text-tertiary); }

@media (max-width: 768px) {
  .action-item { padding: 12px; gap: 10px; }
  .action-badge { font-size: 0.625rem; padding: 2px 8px; }
  .action-meta { font-size: 0.6875rem; }
}


/* ==========================================================================
   27. Returning Client Banner
   ========================================================================== */

.returning-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 16px;
}
.returning-banner svg { flex-shrink: 0; color: var(--accent); }


/* ==========================================================================
   28. Reminders
   ========================================================================== */

.reminder {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  font-size: var(--font-sm);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.reminder.overdue { border-color: rgba(220, 38, 38, 0.25); background: var(--danger-bg); }
.reminder.done { opacity: 0.5; }


/* ==========================================================================
   29. Previous Visits
   ========================================================================== */

.prev-visit-card {
  display: block;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  transition: all var(--transition-fast);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}
.prev-visit-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
