/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  /* Brand */
  --navy:       #0f1d2f;
  --navy-dark:  #0a1420;
  --primary:    #3b82f6;
  --primary-dk: #2563eb;
  --xero:       #13B5EA;
  --success:    #10b981;
  --warn:       #f59e0b;
  --danger:     #ef4444;
  --danger-dk:  #dc2626;

  /* Neutrals — warm slate */
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-900: #0f172a;
  --border:   rgba(15,23,42,.06);
  --border-light: rgba(255,255,255,.12);

  /* Surfaces */
  --radius:     10px;
  --radius-sm:  6px;
  --radius-lg:  14px;
  --shadow:     0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.06);
  --shadow-md:  0 4px 6px rgba(15,23,42,.04), 0 10px 15px rgba(15,23,42,.06);
  --shadow-lg:  0 10px 25px rgba(15,23,42,.06), 0 20px 50px rgba(15,23,42,.08);
  --glass-bg:   rgba(255,255,255,.78);
  --glass-border: rgba(255,255,255,.3);
  --glass-blur: blur(20px);
  --glass-dark: rgba(15,23,42,.88);
  --glass-dark-border: rgba(255,255,255,.08);

  /* Typography */
  --font:       'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:  'JetBrains Mono', 'SF Mono', Consolas, monospace;

  /* Transitions */
  --ease: cubic-bezier(.4, 0, .2, 1);
  --ease-out: cubic-bezier(0, 0, .2, 1);
}

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

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--gray-900);
  background: #eef2f7;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

/* ── Header ────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 52px;
  background: var(--navy);
  color: #fff;
  flex-shrink: 0;
  gap: 14px;
  z-index: 20;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.header-left  { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.app-logo  { height: 42px; width: auto; display: block; }
.app-title { font-size: 14px; font-weight: 500; color: #fff; opacity: .85; }
.auth-wrap {
  position: relative;
}
.auth-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  background: rgba(255,255,255,.08);
  color: #fff;
  cursor: pointer;
  transition: background .15s;
  font: inherit;
}
.auth-chip:hover { background: rgba(255,255,255,.16); }
.auth-user-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.auth-popover {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: #fff;
  color: var(--gray-900);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-lg);
  padding: 12px 14px;
  z-index: 100;
}
.auth-popover.open { display: block; }
.auth-popover-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}
.auth-popover-email {
  font-size: 11px;
  color: var(--gray-500);
  word-break: break-all;
}
.auth-popover-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}
.auth-popover-action {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 6px 4px;
  font-size: 12px;
  color: var(--gray-700);
  cursor: pointer;
  border-radius: 4px;
  transition: background .12s;
}
.auth-popover-action:hover {
  background: var(--gray-100);
  color: var(--danger);
}


/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 14px;
  border: none; border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 12px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: all .15s var(--ease);
  letter-spacing: 0;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary    { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); box-shadow: 0 2px 8px rgba(59,130,246,.25); }
.btn-secondary  { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.15); }
.btn-secondary:hover { background: rgba(255,255,255,.18); }
.btn-xero       { background: var(--xero); color: #fff; }
.btn-xero:hover { background: #0ea5d0; }
.btn-ghost      { background: #fff; color: var(--gray-700); border: 1px solid var(--gray-200); }
.btn-ghost:hover{ background: var(--gray-50); border-color: var(--gray-300); }
.btn-ghost-light{ background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.12); }
.btn-ghost-light:hover{ background: rgba(255,255,255,.15); }
.btn-danger     { background: var(--danger); color: #fff; }
.btn-danger:hover{ background: var(--danger-dk); }
.btn-icon       { background: transparent; color: rgba(255,255,255,.7); font-size: 17px; padding: 5px 9px; border-radius: var(--radius-sm); }
.btn-icon:hover { background: rgba(255,255,255,.1); color: #fff; }
.btn-sm         { padding: 4px 10px; font-size: 11px; }

/* ── Entity pills ─────────────────────────────────────────── */
.entity-pill {
  display: inline-block;
  font-size: 10px; font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  letter-spacing: .02em;
}

/* ── Document type pills ──────────────────────────────────── */
.doc-type-pill {
  display: inline-block;
  font-size: 10px; font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.inv-pill {
  background: var(--inv-pill-bg, #dbeafe);
  color: var(--inv-pill-color, #1d4ed8);
}
.cn-pill {
  background: var(--cn-pill-bg, #fef3c7);
  color: var(--cn-pill-color, #92400e);
}

/* ── WYSIWYG editor ───────────────────────────────────────── */
#tmpl-visual {
  cursor: text;
}
#tmpl-visual:focus { outline: none; }
#tmpl-visual p { margin-bottom: 0.5em; }
#tmpl-visual h2 { font-size: 16px; font-weight: 700; margin: 0.5em 0 0.3em; }
#tmpl-visual h3 { font-size: 14px; font-weight: 700; margin: 0.5em 0 0.3em; }

/* ── HTML toolbar ─────────────────────────────────────────── */
.html-btn {
  background: #fff; border: 1px solid var(--gray-200);
  border-radius: 4px; padding: 2px 8px;
  font-size: 11px; cursor: pointer; color: var(--gray-500);
  line-height: 1.4;
  transition: all .1s var(--ease);
}
.html-btn:hover { background: var(--gray-50); border-color: var(--gray-300); color: var(--gray-700); }

/* ── Copy button ──────────────────────────────────────────── */
.btn-copy {
  background: none; border: none; cursor: pointer;
  color: var(--gray-400); font-size: 11px; padding: 0 3px;
  vertical-align: middle; opacity: .5;
  transition: opacity .1s;
}
.btn-copy:hover { opacity: 1; color: var(--primary); }

/* ── Navigation ────────────────────────────────────────────── */
.nav-bar {
  display: flex;
  align-items: center;
  background: #162336;
  padding: 0 16px;
  gap: 2px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
  height: 40px;
}
.nav-section {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
}
.nav-section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
  color: rgba(255,255,255,.5);
  padding: 0 12px;
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  height: 100%;
  display: flex;
  align-items: center;
  border-radius: 0;
  transition: all .15s var(--ease);
}
.nav-section-label::after {
  content: '▾';
  margin-left: 5px;
  font-size: 9px;
  opacity: .5;
}
.nav-section-label:hover,
.nav-section.open .nav-section-label {
  color: rgba(255,255,255,.9);
  background: rgba(255,255,255,.08);
}
.nav-section.has-active > .nav-section-label {
  color: rgba(255,255,255,.95);
  font-weight: 700;
}
.nav-segment {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 200;
  flex-direction: column;
  background: #1e2d42;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: 4px;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  gap: 1px;
}
.nav-section.open > .nav-segment {
  display: flex;
}
.nav-btn {
  padding: 7px 14px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,.55);
  font-family: var(--font);
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  border-radius: 5px;
  transition: all .15s var(--ease);
  white-space: nowrap;
  letter-spacing: 0;
  text-align: left;
  width: 100%;
}
.nav-btn:hover  { color: rgba(255,255,255,.9); background: rgba(255,255,255,.08); }
.nav-btn.active { color: #fff; background: var(--primary); box-shadow: 0 1px 4px rgba(59,130,246,.3); font-weight: 600; }

/* ── Filter bar ────────────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.search-input, .filter-select {
  padding: 7px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 12.5px;
  background: #fff;
  outline: none;
  cursor: pointer;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.search-input:focus, .filter-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
.search-input { width: 220px; }
.search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.search-wrap .search-input { padding-right: 26px; }
.search-clear {
  position: absolute;
  right: 6px;
  background: none; border: none;
  color: var(--gray-400); font-size: 15px;
  cursor: pointer; padding: 0 2px;
  line-height: 1; display: none;
}
.search-clear:hover { color: var(--gray-700); }
.search-wrap .search-input:not(:placeholder-shown) + .search-clear { display: block; }
.filter-summary { margin-left: auto; font-size: 12px; color: var(--gray-500); font-weight: 500; }

/* ── Main layout ───────────────────────────────────────────── */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Table wrapper ─────────────────────────────────────────── */
.table-wrapper {
  flex: 1;
  overflow: auto;
  padding-bottom: 58px; /* bulk bar */
}

/* ── Invoice table ─────────────────────────────────────────── */
.inv-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}
.inv-table thead {
  position: sticky; top: 0; z-index: 10;
  background: var(--gray-50);
}
.inv-table th {
  padding: 8px 12px;
  font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--gray-400);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap; text-align: left;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--gray-700); }
th.sortable .sort-arrow { font-size: 10px; margin-left: 3px; opacity: .4; }
th.sortable.sort-active .sort-arrow { opacity: 1; color: var(--primary); }
.inv-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.inv-table tbody tr:hover { background: #f8fafc; }
.inv-table tbody tr.row-selected { background: #eff6ff; }

/* column widths */
.col-expand{ width: 28px; text-align: center !important; padding: 0 !important; }
.col-chk   { width: 32px; }
.col-client{ white-space: nowrap; }
.col-type  { width: 1%; white-space: nowrap; }
.col-org   { width: 1%; white-space: nowrap; }
.col-ref   { width: 1%; white-space: nowrap; }
.col-date  { width: 88px; }
.col-due   { width: 88px; }
.col-age   { width: 78px; text-align: center !important; }
.col-amt   { width: 105px; text-align: right !important; }
.col-stage { width: 128px; }
/* Ensure data cells align with headers */
.inv-table td:nth-child(9) { text-align: center; }   /* overdue */
.inv-table td:nth-child(10) { text-align: right; }   /* amount */
.inv-table td:nth-child(11) { text-align: right; }   /* paid */
.inv-table td:nth-child(12) { text-align: right; }   /* balance */
.inv-table td:nth-child(13) { text-align: center; }  /* stage */
.col-exp   { width: 95px; }
.col-detail { min-width: 120px; }
.col-note  { min-width: 190px; }
.detail-inline-input {
  font-size: 11px; padding: 3px 6px; border: 1px solid transparent;
  border-radius: var(--radius); background: transparent; width: 100%;
  outline: none; color: var(--gray-700);
}
.detail-inline-input:hover { border-color: var(--border); }
.detail-inline-input:focus { border-color: var(--primary); background: #fff; }

/* ── Client group rows ─────────────────────────────────────── */
.group-row {
  background: var(--gray-50) !important;
  position: sticky;
  top: 36px;
  z-index: 5;
}
.group-row td {
  font-weight: 600; font-size: 12px;
  color: var(--gray-700);
  padding: 6px 12px;
  border-bottom: 1px solid var(--gray-200);
  border-top: 1px solid var(--gray-100);
}
.group-row:hover { background: var(--gray-100) !important; }

.client-link {
  color: var(--primary); cursor: pointer;
  text-decoration: none; font-weight: 600;
}
.client-link:hover { text-decoration: underline; }

/* indent invoice rows */
.inv-row td:nth-child(2) { padding-left: 28px; }
.inv-row td:nth-child(1) { padding-left: 20px; }

/* ── Aging badges ──────────────────────────────────────────── */
.age-badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.age-current { background: #dcfce7; color: #15803d; }
.age-30      { background: #fef9c3; color: #854d0e; }
.age-60      { background: #ffedd5; color: #9a3412; }
.age-90      { background: #fee2e2; color: #991b1b; }

/* ── Stage badges ──────────────────────────────────────────── */
.stage-badge {
  display: inline-block;
  padding: 2px 9px; border-radius: 10px;
  font-size: 11px; font-weight: 500;
}
.s-Waiting         { background: #f3f4f6; color: #6b7280; }
.s-Remittance      { background: #dbeafe; color: #1d4ed8; }
.s-Email           { background: #dbeafe; color: #1d4ed8; }
.s-Call            { background: #ede9fe; color: #6d28d9; }
.s-ReminderNotice  { background: #fef3c7; color: #92400e; }
.s-FinalNotice     { background: #ffedd5; color: #9a3412; }
.s-Default         { background: #fee2e2; color: #991b1b; }
.s-QCAT            { background: #991b1b; color: #fff; }
.s-WriteOff        { background: #1f2937; color: #fff; }

/* ── Amount / mono ─────────────────────────────────────────── */
.mono { font-family: var(--font-mono); font-size: 12px; font-variant-numeric: tabular-nums; font-weight: 500; }

/* ── Note preview ──────────────────────────────────────────── */
.note-preview-text {
  color: var(--gray-600);
  font-style: italic;
  font-size: 12px;
}
.note-meta-tiny { font-size: 10px; color: var(--gray-400); margin-top: 1px; }

/* ── Invoice detail row ────────────────────────────────────── */
.inv-detail-row td { padding: 0; border-bottom: 1px solid var(--gray-100); }
.inv-detail-box {
  display: flex; gap: 24px; align-items: center; flex-wrap: wrap;
  padding: 8px 12px 8px 56px;
  background: var(--gray-50);
  font-size: 12px;
}
.inv-detail-box .detail-item { display: flex; flex-direction: column; gap: 2px; }
.inv-detail-box .detail-label { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-400); font-weight: 600; }
.inv-detail-box .detail-val   { color: var(--gray-900); font-weight: 500; }
.inv-detail-box .detail-val.mono { font-family: var(--font-mono); }
.cn-badge { display:inline-block; font-size:10px; background:#fef3c7; color:#92400e; padding:1px 6px; border-radius:8px; margin-right:4px; font-weight:600; }
.disputed-badge { display:inline-block; font-size:10px; background:#fee2e2; color:#991b1b; padding:1px 6px; border-radius:8px; margin-right:4px; font-weight:600; }

.grp-inv-count {
  font-size: 11px;
  color: var(--gray-400);
  font-weight: 400;
  margin-left: 6px;
}
.grp-org-label {
  font-size: 10px;
  color: rgba(255,255,255,.4);
  font-weight: 400;
  margin-top: 1px;
}
.inv-stage-select {
  font-size: 11px;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--gray-700);
  cursor: pointer;
  max-width: 118px;
}
.inv-stage-select:hover { border-color: var(--border); background: #fff; }
.inv-stage-select:focus { border-color: var(--primary); background: #fff; outline: none; }
.panel-inv-stage {
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--gray-700);
  cursor: pointer;
  margin-left: auto;
}

/* ── Stage checkbox dropdown ─────────────────────────────── */
.dropdown-filter { position: relative; }
button.filter-select {
  background: #fff;
  font-size: 13px;
  font-family: inherit;
  color: var(--gray-900);
  white-space: nowrap;
}
.dropdown-filter-panel {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  min-width: 165px;
  z-index: 200;
  padding: 4px 0;
  max-height: 280px;
  overflow-y: auto;
}
.dropdown-filter-panel.open { display: block; }
.stage-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  user-select: none;
}
.stage-check-label:hover { background: var(--gray-100); }

.collapse-btn {
  background: #fff; border: 1px solid var(--gray-200);
  color: var(--gray-400); font-size: 11px; font-weight: 700;
  cursor: pointer; padding: 0;
  transition: all .12s var(--ease);
  vertical-align: middle;
  font-family: var(--font-mono);
  width: 20px; height: 20px; line-height: 18px;
  text-align: center; border-radius: 999px;
}
.collapse-btn:hover { color: var(--gray-700); border-color: var(--gray-300); }
.expand-all-btn {
  background: #fff; border: 1px solid var(--gray-200);
  color: var(--gray-400); font-size: 11px; font-weight: 700;
  cursor: pointer; padding: 0;
  font-family: var(--font-mono);
  width: 20px; height: 20px; line-height: 18px;
  text-align: center; border-radius: 999px;
}
.expand-all-btn:hover { color: var(--gray-700); border-color: var(--gray-300); }

.inv-num-text {
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  color: var(--gray-700); user-select: text;
}
.inv-num-text:hover { color: var(--primary); }
.xero-arrow {
  font-size: 11px; color: var(--gray-400);
  text-decoration: none; margin-left: 3px;
  vertical-align: middle;
}
.xero-arrow:hover { color: var(--primary); }

/* ── Clients view ──────────────────────────────────────────── */
.clients-table { width:100%; border-collapse:collapse; background: #fff; }
.clients-table th {
  padding: 8px 14px;
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--gray-400); border-bottom: 1px solid var(--gray-200);
  text-align: left; background: var(--gray-50);
  position: sticky; top: 0; z-index: 5;
}
.clients-table td { padding: 8px 14px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.clients-table tbody tr:nth-child(even) { background: var(--gray-50); }
.clients-table tbody tr { cursor: pointer; }
.clients-table tbody tr:hover { background: #f0f7ff; }
.note-count-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px;
  background: var(--gray-100); color: var(--gray-700);
  border-radius: 10px; font-size: 11px; font-weight: 600;
}
.note-count-badge.has-notes { background: #dbeafe; color: #1d4ed8; }

/* ── Bulk bar ──────────────────────────────────────────────── */
.bulk-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px;
  background: var(--navy);
  color: #fff;
  transform: translateY(100%);
  transition: transform .2s var(--ease);
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(15,23,42,.15);
}
.bulk-bar.visible { transform: translateY(0); }
.bulk-bar .bulk-actions { display: flex; gap: 8px; margin-left: auto; }
#bulk-count { font-weight: 600; font-size: 13px; }

/* ── Client panel ──────────────────────────────────────────── */
.client-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 500px;
  background: #fff;
  border-left: 1px solid var(--gray-200);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: translateX(100%);
  transition: transform .22s var(--ease-out);
  z-index: 25;
  box-shadow: var(--shadow-lg);
}
.client-panel.open { transform: translateX(0); }
.client-panel.over-modal { z-index: 250; }
.modal-overlay.panel-open .modal { margin-right: 510px; transition: margin .22s var(--ease-out); }

.panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px;
  background: var(--navy);
  color: #fff;
  font-weight: 600; font-size: 14px;
  flex-shrink: 0;
}
#panel-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-close {
  background: none; border: none; color: #fff;
  font-size: 17px; cursor: pointer; padding: 2px 6px;
  border-radius: 3px; line-height: 1;
}
.panel-close:hover { background: rgba(255,255,255,.2); }
.panel-body { flex: 1; overflow-y: auto; padding: 16px; }

/* panel sections */
.psec { margin-bottom: 20px; }
.psec h4 {
  font-size: 10px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--gray-500);
  font-weight: 700; margin-bottom: 8px;
}
.pstat      { font-size: 22px; font-weight: 700; font-family: var(--font-mono); }
.pstat-sub  { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

.tracking-row { display: flex; gap: 12px; flex-wrap: wrap; }
.track-item   { display: flex; flex-direction: column; gap: 4px; }
.track-label  {
  font-size: 10px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--gray-500); font-weight: 600;
}

.panel-inv-list { display: flex; flex-direction: column; gap: 4px; }
.panel-inv-row  {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px;
  background: var(--gray-50); border-radius: var(--radius-sm);
  border: 1px solid var(--gray-100);
  font-size: 12px; gap: 8px;
}

/* panel notes */
.note-list { display: flex; flex-direction: column; gap: 8px; }
.note-card  {
  padding: 9px 11px;
  background: var(--gray-50); border-radius: var(--radius-sm);
  border: 1px solid var(--gray-100);
  border-left: 3px solid var(--primary);
}
.note-card.client-note { border-left-color: var(--gray-300); }
.note-card-meta {
  display: flex; justify-content: space-between; align-items: flex-start;
  font-size: 10px; color: var(--gray-500); margin-bottom: 5px;
}
.note-delete-btn {
  background: none; border: 1px solid var(--border); cursor: pointer;
  color: var(--gray-500); font-size: 10px; padding: 2px 6px;
  border-radius: 4px;
  opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
.note-card:hover .note-delete-btn,
.note-card:hover .note-edit-btn { opacity: 1; }
.note-delete-btn:hover { color: var(--danger); border-color: var(--danger); }
.note-edit-btn { opacity: 0; transition: opacity .15s; }
.note-card-body {
  font-size: 12px; color: var(--gray-700);
  white-space: pre-wrap; line-height: 1.45;
}
.note-card-tags {
  display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px;
}
.inv-tag {
  display: inline-block; white-space: nowrap;
  font-size: 10px; background: #dbeafe; color: #1d4ed8;
  padding: 1px 6px; border-radius: 8px;
}
.client-note-label { font-size: 10px; color: var(--gray-400); font-style: italic; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-overlay.open .modal { transform: translateY(0); opacity: 1; }

.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 500px; max-width: 92vw;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(15,23,42,.04);
  transform: translateY(12px);
  opacity: 0;
  transition: all .2s var(--ease-out);
}
.modal-header {
  display: flex; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
}
.modal-header h3 { flex: 1; font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none; font-size: 18px;
  color: var(--gray-400); cursor: pointer;
  padding: 4px 8px; border-radius: var(--radius-sm);
  transition: all .12s var(--ease);
}
.modal-close:hover { background: var(--gray-100); color: var(--gray-700); }
.modal-body   { padding: 18px 20px; display: flex; flex-direction: column; gap: 13px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--gray-100);
  display: flex; justify-content: flex-end; gap: 8px;
}

#settings-overlay .modal {
  max-height: 94vh;
  display: flex;
  flex-direction: column;
}
#settings-overlay .modal-body {
  flex: 1;
  min-height: 0;
  max-height: calc(94vh - 128px);
  overflow: auto;
}

.settings-tab-bar {
  display: flex;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.settings-tab-btn {
  border: 1px solid var(--gray-200);
  background: #fff;
  color: var(--gray-500);
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s var(--ease);
}
.settings-tab-btn:hover { border-color: var(--gray-300); color: var(--gray-700); }
.settings-tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.settings-tab-panel { min-height: 220px; }
.settings-section {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}
.settings-section + .settings-section { margin-top: 16px; }
.settings-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-100);
}
.settings-section.collapsed .settings-section-header {
  border-bottom: none;
}
.settings-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-700);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.settings-section-note {
  font-size: 12px;
  color: var(--gray-500);
}
.settings-section-body {
  padding: 14px;
}
.settings-section.collapsed .settings-section-body {
  display: none;
}
.settings-collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--gray-200);
  border-radius: 999px;
  background: #fff;
  color: var(--gray-500);
  cursor: pointer;
  font-size: 12px;
  transition: all .12s var(--ease);
}
.settings-collapse-btn:hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
}
.settings-grid-table {
  width: 100%;
  border-collapse: collapse;
}
.settings-grid-table th,
.settings-grid-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.settings-grid-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-500);
  background: #fff;
}
.settings-grid-table tbody tr.archived-row {
  background: var(--gray-50);
  opacity: .72;
}
.settings-inline-field {
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings-swatch {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.modal-context {
  background: var(--gray-50); border-radius: var(--radius);
  padding: 9px 12px; font-size: 12px; color: var(--gray-700);
  border: 1px solid var(--border);
}
.modal-context strong { display: block; margin-bottom: 4px; font-size: 13px; color: var(--gray-900); }

.form-group   { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--gray-700); }
.form-group label .req { color: var(--danger); }
.form-row     { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

textarea, input[type="text"], input[type="date"], input[type="number"], input[type="email"], select {
  padding: 7px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 12.5px; font-family: var(--font);
  outline: none; width: 100%;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
textarea:focus, input[type="text"]:focus, input[type="date"]:focus, input[type="number"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
textarea:focus, input:focus { border-color: var(--primary); }

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 80px 20px; gap: 12px;
  color: var(--gray-500); text-align: center;
}
.empty-state .icon { font-size: 48px; }
.empty-state h3 { font-size: 17px; color: var(--gray-700); }
.empty-state p  { font-size: 13px; line-height: 1.6; max-width: 420px; }

/* ── Loading ───────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 300; gap: 12px; font-size: 14px; color: var(--gray-700);
}
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 400; display: flex; flex-direction: column; align-items: stretch;
  gap: 0; pointer-events: none;
}
.toast {
  color: #fff;
  padding: 12px 24px;
  font-family: var(--font);
  font-size: 13px; font-weight: 500;
  animation: slideUp .22s var(--ease-out);
  pointer-events: auto;
  text-align: center;
}
.toast:not(.success):not(.error) {
  background: var(--navy);
}
.toast.success { background: #065f46; }
.toast.error   { background: #991b1b; }
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar              { width: 5px; height: 5px; }
::-webkit-scrollbar-track        { background: transparent; }
::-webkit-scrollbar-thumb        { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover  { background: var(--gray-500); }

/* ── Mobile responsive ─────────────────────────────────────── */
@media (max-width: 980px) {
  .auth-wrap { display: none !important; }
  .nav-bar { gap: 0; padding: 0 4px; overflow-x: auto; }
  .nav-section-label { font-size: 11px; padding: 0 8px; }
  .nav-btn { font-size: 11px; padding: 6px 10px; }
  .filter-bar { flex-wrap: wrap; padding: 6px 10px; }
  .search-input { width: 160px; }
}

@media (max-width: 768px) {
  .app-header { padding: 0 12px; height: 48px; }
  .app-logo { height: 32px; }
  .app-title { display: none; }
  .nav-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav-section { flex-shrink: 0; }
  .client-panel {
    width: 100% !important;
    left: 0;
    border-left: none;
    z-index: 50;
  }
  #dashboard-view { padding: 12px !important; }
  #dashboard-view > div:first-child { grid-template-columns: repeat(2, 1fr) !important; }
  #dashboard-view > div:nth-child(2),
  #dashboard-view > div:nth-child(3) { grid-template-columns: 1fr !important; }
  .modal { width: 96vw !important; max-width: 96vw !important; }
  .modal-body { padding: 12px !important; }
  .bulk-bar { padding: 8px 12px; }
  .bulk-bar .bulk-actions { flex-wrap: wrap; gap: 4px; }
}
