/* ── Reset & tokens ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w:   220px;
  --sidebar-bg:  #0f172a;
  --sidebar-txt: #94a3b8;
  --sidebar-act: #f97316;
  --sidebar-hov: #1e293b;

  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --border:      #e2e8f0;
  --border-dark: #cbd5e1;

  --txt:         #0f172a;
  --txt-sub:     #64748b;
  --txt-dim:     #94a3b8;

  --accent:      #f97316;
  --accent-dark: #ea580c;

  --green:       #22c55e;
  --yellow:      #f59e0b;
  --red:         #ef4444;
  --blue:        #3b82f6;

  --radius:      8px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 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);

  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--txt);
}

/* ── Layout ───────────────────────────────────────────────────────────── */
body { background: var(--bg); }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  z-index: 100;
}

.brand {
  display: flex;
  justify-content: center;
  padding: 20px 16px 16px;
  text-decoration: none;
  border-bottom: 1px solid #1e293b;
}
.brand-logo-text {
  width: 100%;
  max-width: 160px;
  height: auto;
  object-fit: contain;
  opacity: .95;
}

.nav-links {
  list-style: none;
  padding: 12px 8px;
  flex: 1;
}
.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  color: var(--sidebar-txt);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-links a svg {
  width: 16px; height: 16px;
  fill: currentColor;
  flex-shrink: 0;
  opacity: .75;
}
.nav-links a:hover    { background: var(--sidebar-hov); color: #e2e8f0; }
.nav-links a.active   { background: #1e293b; color: var(--accent); }
.nav-links a.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 12px 16px;
  border-top: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}
.sidebar-user-name {
  font-size: 12px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}
.sidebar-logout {
  font-size: 11px;
  color: #64748b;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.sidebar-logout:hover { color: #f97316; }
.btn-new-quote {
  display: block;
  background: var(--accent);
  color: white;
  text-align: center;
  text-decoration: none;
  padding: 9px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  transition: background .15s;
}
.btn-new-quote:hover { background: var(--accent-dark); }

/* ── Main content ─────────────────────────────────────────────────────── */
.main-content {
  grid-column: 2;
  padding: 28px 32px;
  min-height: 100vh;
  min-width: 0;
}

/* ── Alerts ───────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13.5px;
  font-weight: 500;
}
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.alert-error   { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* ── Page header ──────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-header h1 { font-size: 22px; font-weight: 700; line-height: 1.2; }
.page-sub { color: var(--txt-sub); font-size: 13px; margin-top: 3px; }
.header-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ── Year tab bar ─────────────────────────────────────────────────────── */
.year-tab-bar { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.year-tab {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--txt-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  transition: background .15s, color .15s;
}
.year-tab:hover { color: var(--txt); background: var(--hover); }
.year-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: background .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost {
  background: white; color: var(--txt);
  border: 1px solid var(--border-dark);
  box-shadow: var(--shadow);
}
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-sm  { padding: 5px 10px; font-size: 12.5px; }
.btn-xs  { padding: 3px 8px;  font-size: 11.5px; }
.btn-full { width: 100%; justify-content: center; }
.btn-remove {
  background: none; border: none; cursor: pointer;
  color: var(--txt-dim); font-size: 14px; padding: 2px 6px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}
.btn-remove:hover { color: var(--red); background: #fee2e2; }

/* ── Cards / sections ─────────────────────────────────────────────────── */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 20px;
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--txt-sub);
  margin-bottom: 14px;
}
.section-header .section-title { margin-bottom: 0; }
.section-title.warn { color: var(--yellow); }
.see-all { display: block; font-size: 12.5px; color: var(--accent); margin-top: 12px; text-decoration: none; }
.see-all:hover { text-decoration: underline; }
.scroll-table-wrap { max-height: 320px; overflow-y: auto; }

/* ── Stat grid ────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.stat-card.stat-revenue { border-left: 4px solid var(--accent); }
.stat-card.stat-warn    { border-left: 4px solid var(--yellow); }
a.stat-card.stat-link   { display: block; text-decoration: none; color: inherit; cursor: pointer; }
a.stat-card.stat-link:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.stat-clickable { cursor: pointer; user-select: none; transition: border-color .15s, box-shadow .15s; }
.stat-clickable:hover { border-color: var(--accent); }
.stat-active { border-color: var(--accent) !important; box-shadow: 0 0 0 2px var(--accent) !important; }
.stat-label  { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--txt-sub); }
.stat-value  { font-size: 28px; font-weight: 700; margin: 4px 0 2px; line-height: 1; }
.stat-sub    { font-size: 12px; color: var(--txt-dim); }

/* ── Two-column layouts ───────────────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.two-col-wide { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.col-main { min-width: 0; }
.col-side { }
.sticky-totals { position: sticky; top: 20px; }

/* ── Tables ───────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table th {
  background: var(--bg);
  text-align: left;
  padding: 9px 12px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--txt-sub);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table .clickable { cursor: pointer; }
.data-table .clickable:hover { background: #f0f9ff; }
.data-table th.num { text-align: right; }
.data-table tfoot tr.total-row td {
  border-top: 2px solid var(--border-dark);
  border-bottom: none;
  font-weight: 600;
  background: var(--bg);
}
.data-table tfoot tr.balance-row td { color: var(--red); }

.table-footer {
  font-size: 12px;
  color: var(--txt-dim);
  padding: 10px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}
.num   { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; }
.dim   { color: var(--txt-dim); }
.red   { color: var(--red); }
.mono  { font-family: 'SF Mono', 'Menlo', 'Monaco', monospace; font-size: 12.5px; }
.empty { text-align: center; padding: 32px !important; color: var(--txt-dim); font-style: italic; }

.action-cell { text-align: right; white-space: nowrap; }
.row-inactive { opacity: .45; }
.row-highlight-danger { background: #fff5f5 !important; }
.row-highlight-danger:hover { background: #fee2e2 !important; }
.row-highlight-warn   { background: #fffbeb !important; }
.row-highlight-warn:hover   { background: #fef3c7 !important; }

/* ── Badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-sold      { background: #dcfce7; color: #15803d; }
.badge-sold_owed { background: #fef3c7; color: #b45309; }
.badge-quote     { background: #dbeafe; color: #1d4ed8; }
.badge-invoice   { background: #e0e7ff; color: #4338ca; }
.badge-draft     { background: #f1f5f9; color: #64748b; }
.badge-lost      { background: #fee2e2; color: #b91c1c; }
.badge-prospect { background: #f1f5f9; color: #475569; }
.badge-active   { background: #fef3c7; color: #92400e; }
.badge-client   { background: #dcfce7; color: #15803d; }
.badge-ulc      { background: #ede9fe; color: #6d28d9; }
.badge-inv-available { background: #dcfce7; color: #15803d; }
.badge-inv-reserved  { background: #fef3c7; color: #92400e; }
.badge-inv-sold      { background: #f1f5f9; color: #64748b; }

/* ── Tags ─────────────────────────────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 11px;
  background: var(--bg);
  color: var(--txt-sub);
  border: 1px solid var(--border);
}
.tag-notax { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }

/* ── Progress bars ────────────────────────────────────────────────────── */
.pct-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.pct-bar {
  height: 8px;
  border-radius: 4px;
  transition: width .3s;
  min-width: 2px;
}
.pct-bar.danger { background: var(--red); }
.pct-bar.warn   { background: var(--yellow); }
.pct-bar.low    { background: var(--accent); }
.pct-label { font-size: 11.5px; color: var(--txt-sub); white-space: nowrap; }

/* ── Filters ──────────────────────────────────────────────────────────── */
.filters { margin-bottom: 16px; }
.filter-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.input-search {
  padding: 7px 12px;
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  font-size: 13.5px;
  background: white;
  min-width: 220px;
  outline: none;
}
.input-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(249,115,22,.1); }
.input-select {
  padding: 7px 10px;
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  font-size: 13.5px;
  background: white;
  cursor: pointer;
}

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-label {
  display: block;
  width: 100%;
  font-size: 13px;
  font-weight: 500;
  color: var(--txt-muted);
  margin-bottom: 2px;
}
.input {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  font-size: 13.5px;
  background: white;
  color: var(--txt);
  margin-top: 4px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(249,115,22,.12); }
textarea.input { resize: vertical; }
.input-sm { padding: 5px 7px; font-size: 12.5px; }

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--txt-sub); }
.checkbox-label { display: flex; align-items: center; gap: 7px; font-weight: 500; color: var(--txt); cursor: pointer; }
.checkbox-label input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; margin: 0; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.form-row    { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.form-stack  { display: flex; flex-direction: column; gap: 12px; }
.form-inline { display: flex; align-items: center; gap: 8px; }
.form-inline span { font-size: 12px; font-weight: 600; color: var(--txt-sub); white-space: nowrap; }
.span-2 { grid-column: span 2; }

.inline-form {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.inline-edit-form { padding: 12px 0; }

/* ── Info list (key-value pairs) ──────────────────────────────────────── */
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.info-list dt { font-size: 11.5px; font-weight: 700; color: var(--txt-sub); text-transform: uppercase; letter-spacing: .04em; align-self: start; padding-top: 1px; }
.info-list dd { font-size: 13.5px; }

/* ── Totals sidebar ───────────────────────────────────────────────────── */
.totals-list { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; }
.totals-list dt { font-size: 13.5px; color: var(--txt-sub); }
.totals-list dd { font-size: 13.5px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.totals-list dt.total-line,
.totals-list dd.total-line {
  font-size: 17px;
  font-weight: 700;
  color: var(--txt);
  border-top: 2px solid var(--border-dark);
  padding-top: 8px;
  margin-top: 4px;
}

/* ── Quote builder ────────────────────────────────────────────────────── */
.builder-table td { padding: 5px 6px; }
.builder-table .num input { text-align: right; }
.builder-footer { margin-top: 10px; display: flex; gap: 8px; }
.line-total-cell { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tax-status { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px; }
.tax-on     { background: #fef3c7; color: #92400e; }
.tax-off    { background: #f1f5f9; color: #64748b; }
.tax-exempt { background: #dcfce7; color: #15803d; }

/* ── Alert card ───────────────────────────────────────────────────────── */
.alert-card { border-left: 4px solid var(--yellow); }
.notice {
  font-size: 12.5px;
  color: var(--txt-sub);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  margin-top: 16px;
}

/* ── Nexus table ──────────────────────────────────────────────────────── */
.nexus-table .pct-bar-wrap { min-width: 120px; }

/* ── Alert card in dashboard ──────────────────────────────────────────── */
.alert-card .section-title.warn { color: #92400e; }

/* ── Permission grid (Users page) ────────────────────────────────────── */
.perm-grid-wrap {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 16px 20px;
  margin-top: 12px;
}
.perm-grid-header {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #64748b;
  margin-bottom: 12px;
}
.perm-grid {
  display: grid;
  grid-template-columns: 120px 80px 80px;
  align-items: center;
  row-gap: 10px;
  column-gap: 8px;
}
.perm-col-head {
  font-size: .72rem;
  font-weight: 600;
  color: #94a3b8;
  text-align: center;
}
.perm-row-label {
  font-size: .85rem;
  color: #cbd5e1;
  font-weight: 500;
  text-transform: capitalize;
}
.perm-grid input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  display: block;
  margin: 0 auto;
}
.perm-grid input[type=checkbox]:disabled { opacity: .3; cursor: not-allowed; }

/* ── Mobile menu button (hidden on desktop) ───────────────────────────── */
.mobile-menu-btn {
  display: none;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 999;
}

/* ── Mobile responsive ────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
  .main-content { grid-column: 1; padding: 64px 14px 16px; }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    display: flex !important;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .sidebar-overlay.mobile-open {
    display: block;
  }

  /* Hamburger button */
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 12px; left: 12px;
    z-index: 998;
    width: 40px; height: 40px;
    background: var(--sidebar-bg);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
  }
  .mobile-menu-btn svg {
    width: 22px; height: 22px;
    fill: #94a3b8;
  }
}
