/* ── Design Tokens ────────────────────────────────────────────────────────── */
:root {
  --navy:    #1a3c5e;
  --blue:    #2563eb;
  --sky:     #0ea5e9;
  --teal:    #0d9488;
  --green:   #16a34a;
  --amber:   #d97706;
  --red:     #dc2626;
  --gray-50: #f8fafc;
  --gray-100:#f1f5f9;
  --gray-200:#e2e8f0;
  --gray-400:#94a3b8;
  --gray-600:#475569;
  --gray-800:#1e293b;
  --shadow:  0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --radius:  8px;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; line-height: 1.5; color: var(--gray-800);
  background: var(--gray-50); min-height: 100vh;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Left Sidebar Nav ─────────────────────────────────────────────────────── */
.topnav {
  position: fixed; left: 0; top: 0;
  width: 220px; height: 100vh;
  background: white;
  display: flex; flex-direction: column; gap: 0; padding: 0;
  box-shadow: 1px 0 0 var(--gray-200), 2px 0 8px rgba(0,0,0,.04);
  overflow-y: auto; overflow-x: hidden;
  z-index: 100;
}
.topnav .brand {
  font-weight: 700; font-size: 14px; color: var(--navy); padding: 0 20px;
}

/* Nav links wrapper — fills sidebar, column layout */
.nav-links {
  display: flex; flex-direction: column; flex: 1; overflow-y: auto;
}

/* Logo block — top of sidebar */
.nav-links > a:first-child {
  display: flex !important; align-items: center; justify-content: center;
  padding: 20px 16px 18px; border-bottom: 1px solid var(--gray-100);
  margin-bottom: 8px;
}
.nav-links > a:first-child img { height: auto !important; width: 150px; }
.nav-links > a:first-child:hover { background: none !important; border-left-color: transparent !important; }

/* Regular nav links */
.nav-links a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; font-size: 13px; font-weight: 500;
  color: var(--gray-600); border-left: 3px solid transparent;
  border-radius: 0; transition: all .15s; white-space: nowrap;
}
.nav-links a:hover {
  background: var(--gray-50); color: var(--navy);
  border-left-color: var(--gray-200); text-decoration: none;
}
.nav-links a.active {
  background: #eff6ff; color: var(--blue);
  border-left-color: var(--blue); font-weight: 600;
}
.nav-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }

/* User/logout button — pinned to bottom */
.nav-links > button {
  margin-top: auto !important; flex-shrink: 0;
  border-top: 1px solid var(--gray-100) !important;
  padding: 12px 18px !important; border-radius: 0 !important;
  width: 100% !important; justify-content: flex-start !important;
  font-size: 12px !important; gap: 8px !important; border-left: none !important;
}

/* Page content — offset right of sidebar */
body { padding-left: 220px; }

/* Mobile elements hidden on desktop */
.mobile-topbar { display: none; }
.sidebar-overlay { display: none; }
.nav-hamburger { display: none; }

/* ── Page wrapper ─────────────────────────────────────────────────────────── */
.page { max-width: 1280px; margin: 0 auto; padding: 24px; }
.page-sm { max-width: 900px; margin: 0 auto; padding: 24px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: white; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px;
}
.card-title {
  font-size: 13px; font-weight: 600; color: var(--gray-600);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px;
}

/* ── KPI Cards ────────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 16px; margin-bottom: 24px; }
.kpi {
  background: white; border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border-left: 4px solid var(--blue);
}
.kpi.green  { border-color: var(--green); }
.kpi.amber  { border-color: var(--amber); }
.kpi.red    { border-color: var(--red); }
.kpi.teal   { border-color: var(--teal); }
.kpi-label  { font-size: 12px; font-weight: 600; color: var(--gray-600); text-transform: uppercase; letter-spacing: .4px; }
.kpi-value  { font-size: 28px; font-weight: 700; color: var(--gray-800); margin: 4px 0 2px; line-height: 1.1; }
.kpi-sub    { font-size: 12px; color: var(--gray-400); }

/* ── Grids ────────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ── Section heading ──────────────────────────────────────────────────────── */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-head h2 { font-size: 18px; font-weight: 700; color: var(--navy); }
.section-head h3 { font-size: 15px; font-weight: 600; color: var(--gray-800); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 600; color: var(--gray-600);
  margin-bottom: 5px; text-transform: uppercase; letter-spacing: .3px;
}
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--gray-200);
  border-radius: 6px; font-size: 13px; color: var(--gray-800);
  background: white; transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { resize: vertical; min-height: 72px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent; transition: all .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-navy { background: var(--navy); color: white; }
.btn-navy:hover { background: #152e48; }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #15803d; }
.btn-amber { background: var(--amber); color: white; }
.btn-amber:hover { background: #b45309; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost {
  background: transparent; color: var(--gray-600);
  border-color: var(--gray-200);
}
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-800); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  background: var(--navy); color: white; font-weight: 600;
  padding: 10px 12px; text-align: left; font-size: 12px;
  text-transform: uppercase; letter-spacing: .3px; white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tr:hover td { background: var(--gray-50); }
tr:last-child td { border-bottom: none; }

/* ── Badges / Status ──────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
}
.badge-draft    { background: #e2e8f0; color: #475569; }
.badge-sent     { background: #dbeafe; color: #1e40af; }
.badge-accepted { background: #dcfce7; color: #166534; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-new      { background: #e0f2fe; color: #0c4a6e; }
.badge-contacted{ background: #fef3c7; color: #92400e; }
.badge-qualified{ background: #ede9fe; color: #5b21b6; }
.badge-proposal { background: #fce7f3; color: #9d174d; }
.badge-won      { background: #dcfce7; color: #166534; }
.badge-lost     { background: #fee2e2; color: #991b1b; }
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-done     { background: #dcfce7; color: #166534; }
.badge-snoozed  { background: #e2e8f0; color: #475569; }
.badge-overdue  { background: #fee2e2; color: #991b1b; }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: 6px; font-size: 13px; margin-bottom: 16px;
  display: flex; align-items: flex-start; gap: 10px;
}
.alert-red   { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.alert-amber { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }
.alert-green { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.alert-blue  { background: #eff6ff; border: 1px solid #93c5fd; color: #1e40af; }

/* ── Follow-up Cards ──────────────────────────────────────────────────────── */
.followup-card {
  background: white; border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); border-left: 4px solid var(--amber);
  margin-bottom: 12px; display: flex; gap: 14px; align-items: flex-start;
}
.followup-card.overdue { border-color: var(--red); }
.followup-card.done    { border-color: var(--green); opacity: .7; }
.followup-card.snoozed { border-color: var(--gray-400); opacity: .7; }
.followup-meta { flex: 1; }
.followup-meta .customer { font-weight: 700; font-size: 14px; }
.followup-meta .ref      { font-size: 12px; color: var(--gray-600); margin: 2px 0; }
.followup-meta .note     { font-size: 13px; color: var(--gray-600); margin-top: 4px; }
.followup-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

/* ── Filter Tabs ──────────────────────────────────────────────────────────── */
.filter-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-tab {
  padding: 6px 14px; border-radius: 999px; font-size: 12px; font-weight: 600;
  cursor: pointer; background: var(--gray-100); color: var(--gray-600);
  border: 1px solid var(--gray-200); transition: all .15s;
}
.filter-tab.active { background: var(--navy); color: white; border-color: var(--navy); }

/* ── Spec Sheet ───────────────────────────────────────────────────────────── */
.spec-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px,1fr)); gap: 0;
}
.spec-row { display: contents; }
.spec-label {
  background: var(--gray-100); padding: 9px 14px; font-weight: 600; font-size: 12px;
  color: var(--gray-600); border-bottom: 1px solid var(--gray-200);
  border-right: 1px solid var(--gray-200); text-transform: uppercase;
}
.spec-value {
  padding: 9px 14px; font-size: 13px; color: var(--gray-800);
  border-bottom: 1px solid var(--gray-200); font-weight: 500;
}

/* ── Quote Builder ────────────────────────────────────────────────────────── */
.quote-layout {
  display: grid; grid-template-columns: 1fr 400px; gap: 20px; align-items: start;
}
@media (max-width: 1024px) { .quote-layout { grid-template-columns: 1fr; } }

.items-table td input {
  border: none; padding: 4px 6px; background: transparent;
  font-size: 13px; width: 100%;
}
.items-table td input:focus { background: var(--gray-50); border-radius: 4px; }

/* ── Summary box ──────────────────────────────────────────────────────────── */
.summary-line { display: flex; justify-content: space-between; padding: 7px 0; font-size: 13px; }
.summary-line.total {
  font-weight: 700; font-size: 16px; color: var(--navy);
  border-top: 2px solid var(--navy); margin-top: 4px; padding-top: 10px;
}
.summary-divider { border: none; border-top: 1px solid var(--gray-200); margin: 4px 0; }

/* ── Autocomplete ─────────────────────────────────────────────────────────── */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
  background: white; border: 1px solid var(--gray-200); border-top: none;
  border-radius: 0 0 6px 6px; box-shadow: var(--shadow-md);
  max-height: 220px; overflow-y: auto;
}
.autocomplete-item {
  padding: 9px 12px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
}
.autocomplete-item:hover { background: var(--gray-50); }
.autocomplete-item .sub { font-size: 11px; color: var(--gray-400); }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  background: var(--gray-800); color: white; padding: 12px 20px;
  border-radius: 8px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md); opacity: 0; transition: opacity .25s;
  pointer-events: none; max-width: 320px;
}
#toast.show { opacity: 1; }
#toast.success { background: var(--green); }
#toast.error   { background: var(--red); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: white; border-radius: 10px; padding: 24px;
  width: 90%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 16px; color: var(--navy); }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden        { display: none !important; }
.mt-8          { margin-top: 8px; }
.mt-16         { margin-top: 16px; }
.mt-24         { margin-top: 24px; }
.mb-16         { margin-bottom: 16px; }
.flex          { display: flex; }
.flex-center   { display: flex; align-items: center; }
.gap-8         { gap: 8px; }
.gap-12        { gap: 12px; }
.gap-16        { gap: 16px; }
.justify-between { justify-content: space-between; }
.text-right    { text-align: right; }
.text-center   { text-align: center; }
.text-sm       { font-size: 12px; }
.text-muted    { color: var(--gray-400); }
.font-bold     { font-weight: 700; }
.w-full        { width: 100%; }
.empty-state {
  text-align: center; padding: 48px 20px; color: var(--gray-400);
}
.empty-state .icon { font-size: 40px; margin-bottom: 8px; }
.spinner {
  border: 3px solid var(--gray-200); border-top-color: var(--blue);
  border-radius: 50%; width: 24px; height: 24px;
  animation: spin .6s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Print ────────────────────────────────────────────────────────────────── */
@media print {
  .topnav, .no-print { display: none !important; }
  body { background: white; font-size: 11pt; }
  .card { box-shadow: none; }
  .page, .page-sm { padding: 0; max-width: 100%; }
}

/* ══════════════════════════════════════════════════════════════════════════════
   MOBILE  (≤ 768px) — sidebar becomes a slide-in drawer
   ══════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Remove desktop sidebar offset ──────────────────────────────────── */
  body { padding-left: 0 !important; padding-top: 56px; }

  /* ── Fixed mobile top bar ────────────────────────────────────────────── */
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    position: fixed; top: 0; left: 0; right: 0; height: 56px;
    background: white; border-bottom: 1px solid var(--gray-200);
    padding: 0 16px; z-index: 99; box-shadow: var(--shadow);
  }
  .mobile-topbar img { height: 30px; }

  /* ── Sidebar: slide in from left ─────────────────────────────────────── */
  .topnav {
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    z-index: 200; width: 260px; top: 0;
    box-shadow: 4px 0 24px rgba(0,0,0,.15);
  }
  .topnav.open { transform: translateX(0); }

  /* ── Dim overlay ──────────────────────────────────────────────────────── */
  .sidebar-overlay {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 150;
    opacity: 0; pointer-events: none; transition: opacity .28s;
  }
  .sidebar-overlay.open { opacity: 1; pointer-events: auto; }

  /* ── Hamburger button ────────────────────────────────────────────────── */
  .nav-hamburger {
    display: flex; flex-direction: column; gap: 5px; flex-shrink: 0;
    background: none; border: none; cursor: pointer;
    padding: 8px; border-radius: 6px;
  }
  .nav-hamburger:hover { background: var(--gray-100); }
  .nav-hamburger span {
    display: block; width: 22px; height: 2px;
    background: var(--navy); border-radius: 2px;
    transition: transform .25s, opacity .25s;
  }
  .nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-hamburger.open span:nth-child(2) { opacity: 0; }
  .nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* ── Page padding ────────────────────────────────────────────────────── */
  .page, .page-sm { padding: 12px; }

  /* ── Section heads stack ─────────────────────────────────────────────── */
  .section-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .section-head .btn, .section-head button { width: 100%; justify-content: center; }

  /* ── KPI grid: 2-col ─────────────────────────────────────────────────── */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 22px; }
  .card { padding: 14px; }

  /* ── Tables: horizontal scroll ───────────────────────────────────────── */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 540px; }
  th, td { padding: 8px 10px; }

  /* ── Modals: bottom sheet ────────────────────────────────────────────── */
  .modal-overlay, .modal-overlay.open { align-items: flex-end !important; }
  .modal-overlay.hidden { display: none !important; }
  .modal {
    width: 100%; max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    padding: 20px 16px 36px !important;
    max-height: 92vh; overflow-y: auto;
  }

  /* ── Toast ───────────────────────────────────────────────────────────── */
  #toast { bottom: 16px; left: 12px; right: 12px; text-align: center; max-width: none; }

  /* ── Quote / Forms ───────────────────────────────────────────────────── */
  .quote-layout { grid-template-columns: 1fr !important; }
  .form-row     { grid-template-columns: 1fr !important; }

  /* ── Grids ───────────────────────────────────────────────────────────── */
  .grid-2, .grid-3 { grid-template-columns: 1fr !important; }

  /* ── Stat chips ──────────────────────────────────────────────────────── */
  .stat-bar { gap: 6px; }
  .stat-chip { padding: 7px 12px; font-size: 12px; }
  .stat-chip .cnt { font-size: 15px; }

  /* ── Follow-up cards ─────────────────────────────────────────────────── */
  .fu-card, .followup-card { flex-direction: column; gap: 10px; }
  .fu-actions, .followup-actions { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; }

  /* ── Admin ───────────────────────────────────────────────────────────── */
  .stat-row { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .stat-card { padding: 12px 14px; }
  .stat-card .val { font-size: 22px; }
  .action-btns { flex-wrap: wrap; gap: 4px; }

  /* ── Unsaved bar ─────────────────────────────────────────────────────── */
  .unsaved-bar { flex-direction: column; gap: 8px; padding: 12px 16px; text-align: center; }
  .unsaved-bar .flex { justify-content: center; }

  /* ── Utils ───────────────────────────────────────────────────────────── */
  .hide-mobile { display: none !important; }
  .full-mobile { width: 100% !important; }
}

/* Extra-small (< 400px) */
@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 20px; }
}
