:root {
  /* Cool off-white palette — replaces the warm taupe scheme.
     Legacy --sand-* / --stone-* tokens are aliased below so all existing
     rules pick up the new colors without rewriting every reference. */
  --bg:           #f5f7fa;  /* page background — very subtle cool gray */
  --surface:      #ffffff;  /* card / pane surface — pure white */
  --surface-alt:  #f9fafb;  /* sticky headers, toolbars */
  --row-hover:    #f3f4f6;  /* table row + list item hover */
  --border:       #e5e7eb;  /* cool light gray border */
  --border-dark:  #d1d5db;  /* input borders, slightly darker */

  --navy:         #1a2538;
  --navy-light:   #2d3a52;
  --royal:        #2952a3;
  --royal-hover:  #3a6bc7;
  --royal-light:  #e8efff;
  --sage:         #6b8e5a;
  --sage-light:   #ecf3e4;
  --gold:         #b8901f;
  --gold-light:   #fdf4d6;
  --danger:       #b54545;
  --text:         var(--navy);
  --text-muted:   #6b7280;

  /* Legacy aliases — existing rules using --sand-*, --stone-* pick up the new palette */
  --sand:         var(--bg);
  --sand-light:   var(--surface-alt);
  --sand-deep:    var(--row-hover);
  --stone:        var(--border);
  --stone-dark:   var(--border-dark);

  --shadow-sm:    0 1px 2px rgba(26, 37, 56, 0.06);
  --shadow:       0 2px 6px rgba(26, 37, 56, 0.08);
  --shadow-md:    0 6px 16px rgba(26, 37, 56, 0.10);
  --radius:       6px;
  --radius-lg:    10px;
  --rail-w:       220px;
  --rail-w-collapsed: 56px;
}

[data-theme="dark"] {
  --sand: #131826;
  --sand-light: #1a2538;
  --sand-deep: #0e1320;
  --stone: #2d3a52;
  --stone-dark: #4a5670;
  --navy: #efe6d2;
  --navy-light: #d9cfb8;
  --royal: #5b8aff;
  --royal-hover: #7aa3ff;
  --royal-light: #1f2c4a;
  --sage: #8fb47a;
  --sage-light: #2a3a26;
  --gold: #e0b840;
  --gold-light: #4a3c10;
  --surface: #1f2940;
  --text: var(--navy);
  --text-muted: #9aa3b3;
  --border: var(--stone);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--sand);
  color: var(--text);
  font-family: 'Aptos', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body {
  display: flex;
  min-height: 100vh;
}

/* Rail uses a deep saturated blue — the inverse of the warm sand canvas. Strong contrast,
   sand-colored text/icons, gold accent for the active item. Reads as "command center" rather
   than the pale-taupe softness of v1. */
.rail {
  width: var(--rail-w);
  background: linear-gradient(180deg, #1e3a8a 0%, #1a2f6b 100%);
  border-right: 1px solid #142560;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  transition: width 0.18s ease;
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.05);
}

.rail.collapsed { width: var(--rail-w-collapsed); }
.rail.collapsed .rail-label,
.rail.collapsed .rail-brand,
.rail.collapsed .rail-badge { display: none; }
.rail.collapsed .rail-divider { margin: 0.5rem 0.5rem; }

.rail-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0.875rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.rail-toggle {
  background: transparent;
  border: none;
  color: var(--sand);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
}

.rail-brand {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--sand);
  letter-spacing: 0.5px;
}

.rail-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.625rem 0.5rem;
  gap: 0.125rem;
  overflow-y: auto;
}

.rail-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  color: #f7f1e1;
  text-decoration: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 500;
  position: relative;
  transition: background 0.1s, color 0.1s;
}

.rail-nav a:hover {
  background: rgba(255,255,255,0.12);
  color: #ffffff;
}

.rail-nav a.active {
  background: var(--gold);
  color: var(--navy);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(184,144,31,0.35);
}

.rail-nav a.active .rail-icon { color: var(--navy); }

.rail-icon {
  font-size: 1.125rem;
  width: 1.5rem;
  text-align: center;
  flex-shrink: 0;
  color: inherit;
}

.rail-label {
  flex: 1;
}

.rail-badge {
  background: var(--gold);
  color: var(--navy);
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  font-variant-numeric: tabular-nums;
}

.rail-nav a.active .rail-badge {
  background: var(--navy);
  color: var(--gold);
}

.rail-divider {
  height: 1px;
  background: rgba(255,255,255,0.12);
  margin: 0.5rem 0.75rem;
}

.rail-foot {
  padding: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.rail-foot-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: var(--sand);
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
}
.rail-foot-btn:hover { border-color: var(--sand); }

.main {
  flex: 1;
  padding: 2rem 2.5rem;
  overflow-x: hidden;
}

h1, h2, h3 { color: var(--navy); margin: 0 0 1rem; font-weight: 600; }
h1 { font-size: 1.75rem; letter-spacing: -0.01em; }
h2 { font-size: 1.375rem; margin-top: 2rem; }
h3 { font-size: 1.125rem; }

p { color: var(--text); }

.muted { color: var(--text-muted); font-size: 0.9375rem; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.625rem 0.875rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  display: flex;
  flex-direction: column;
  gap: 0.1875rem;
  text-decoration: none;
  color: var(--text);
}

.tile:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.tile-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
}

.tile-count {
  font-size: 1.625rem;
  font-weight: 600;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.tile-count.attention { color: var(--gold); }
.tile-count.success { color: var(--sage); }

.tile-foot { font-size: 0.75rem; color: var(--text-muted); }

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

.activity {
  list-style: none;
  margin: 0;
  padding: 0;
}

.activity li {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 1rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--stone);
  font-size: 0.9375rem;
}

.activity li:last-child { border-bottom: none; }

.activity .ts {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.activity .ev { color: var(--navy); }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

table.data thead th {
  position: sticky;
  top: 0;
  background: var(--sand-deep);
  color: var(--navy);
  text-align: left;
  padding: 0.625rem 0.875rem;
  font-weight: 600;
  border-bottom: 2px solid var(--stone-dark);
  font-size: 0.875rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

table.data tbody td {
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid var(--stone);
  color: var(--text);
}

table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--sand-light); }
table.data tbody tr.selected { background: var(--royal-light); }

table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

.btn {
  background: var(--royal);
  color: var(--sand-light);
  border: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 500;
}

.btn:hover { background: var(--royal-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--stone-dark);
}

.btn-ghost:hover { background: var(--sand-light); }

.btn-success { background: var(--sage); }
.btn-success:hover { background: #7ea16d; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #c95e5e; }

.btn-sm { padding: 0.3125rem 0.625rem; font-size: 0.875rem; }

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--stone-dark);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--royal);
  outline-offset: -1px;
}

label {
  display: block;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--navy);
  margin-bottom: 0.25rem;
}

.form-row {
  margin-bottom: 1rem;
}

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

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.score-pill.high { background: var(--sage-light); color: var(--sage); }
.score-pill.mid  { background: var(--royal-light); color: var(--royal); }
.score-pill.low  { background: var(--gold-light); color: var(--gold); }

.match-layout {
  display: grid;
  grid-template-columns: 340px 1fr 360px;
  gap: 1rem;
  height: calc(100vh - 4rem);
}

.match-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.match-pane h3 { margin: 0; padding: 0.875rem 1rem; border-bottom: 1px solid var(--stone); background: var(--sand-deep); font-size: 1rem; }

.match-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.match-list li {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--stone);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.match-list li.selected { background: var(--royal-light); border-left: 3px solid var(--royal); }
.match-list li:hover { background: var(--sand-light); }
.match-list .invoice-meta { font-size: 0.875rem; color: var(--text-muted); }

.pdf-frame { flex: 1; border: none; background: var(--sand-deep); }

.candidates {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.mq-dispo {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--stone);
  background: var(--sand-deep);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.mq-dispo-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-right: auto;
}

.mq-edit {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--stone);
  background: var(--sand-light);
}

.mq-edit-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.mq-edit-row label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0;
  font-weight: 500;
}

.mq-edit-row input {
  padding: 0.3125rem 0.5rem;
  font-size: 0.875rem;
  width: auto;
}

.mq-edit-row input#mq-edit-amount { width: 110px; }
.mq-edit-row input#mq-edit-invnum { width: 140px; flex: 1; min-width: 80px; }

.candidate {
  border: 1px solid var(--stone);
  border-radius: var(--radius);
  padding: 0.75rem 0.875rem;
  background: var(--sand-light);
}

.candidate .row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.candidate .signals { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.375rem; display: flex; flex-wrap: wrap; gap: 0.375rem; }
.candidate .signal-chip { background: var(--stone); padding: 1px 6px; border-radius: 999px; }
.candidate .signal-chip.on { background: var(--sage-light); color: var(--sage); }

.match-actions {
  padding: 0.75rem;
  border-top: 1px solid var(--stone);
  display: flex;
  gap: 0.5rem;
}

.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.125rem;
  border-radius: var(--radius);
  background: var(--navy);
  color: var(--sand-light);
  box-shadow: var(--shadow-md);
  font-size: 0.9375rem;
  z-index: 100;
}

.toast.success { background: var(--sage); }
.toast.error { background: var(--danger); }

.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.header-bar h1 { margin: 0; }

.sync-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3125rem 0.75rem;
  background: var(--sand-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
}

.sync-bar .btn-sm { padding: 0.1875rem 0.5rem; font-size: 0.8125rem; }
.sync-bar + .sync-bar { margin-bottom: 1rem; }

.filter-bar {
  display: flex;
  gap: 0.625rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.75rem;
  background: var(--sand-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.625rem;
}

.filter-bar input, .filter-bar select {
  padding: 0.4375rem 0.5625rem;
  font-size: 0.9375rem;
  width: auto;
}

.export-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0.875rem;
  margin-bottom: 0.75rem;
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  background: var(--stone);
  color: var(--navy);
}

.tag.section-finishing { background: var(--gold-light); color: var(--gold); }
.tag.section-tops { background: var(--royal-light); color: var(--royal); }
.tag.section-cabinets { background: var(--sage-light); color: var(--sage); }
.tag.section-cabinetry { background: var(--navy); color: #fff; }

.age-green  { color: var(--sage); font-weight: 500; }
.age-yellow { color: var(--gold); font-weight: 500; }
.age-red    { color: var(--danger); font-weight: 500; }

/* ===== Worklist redesign (2026-06) ===== */
.btn-gold { background: var(--gold); color: var(--navy); }
.wl-tag { font-size: .7rem; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; padding: 2px 8px; border-radius: 5px; }
.wl-tag.ar { background: var(--sage-light); color: var(--sage); }
.wl-tag.ap { background: var(--gold-light); color: var(--gold); }

/* GL Accruals view tabs */
.gl-tabs { display: flex; gap: .4rem; margin-bottom: .7rem; }
.view-btn { padding: .4rem .8rem; border: 1px solid var(--border-dark); border-radius: 7px; background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600; font-size: .85rem; font-family: inherit; }
.view-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* Matcher modal */
.overlay { position: fixed; inset: 0; background: rgba(20,30,50,.45); z-index: 900; display: none; align-items: center; justify-content: center; }
.overlay.open { display: flex; }
.modal { background: var(--surface); width: min(960px, 94vw); height: min(640px, 90vh); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.modal-head { padding: .75rem 1rem; border-bottom: 1px solid var(--stone); display: flex; justify-content: space-between; align-items: center; }
.modal-body { flex: 1; display: grid; grid-template-columns: 340px 1fr; overflow: hidden; }
.mcand-pane { border-right: 1px solid var(--stone); overflow-y: auto; padding: .5rem; }
.mprev { display: flex; flex-direction: column; }
.mprev .pdf-frame { flex: 1; width: 100%; border: 0; }
.mcand { border: 1px solid var(--border); border-radius: 8px; padding: .55rem .65rem; margin-bottom: .5rem; cursor: pointer; }
.mcand.sel { border-color: var(--royal); box-shadow: 0 0 0 2px var(--royal-light); }
.mcand.best { border-left: 4px solid var(--sage); }
.mcand-top { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.mbadge { font-size: .64rem; font-weight: 700; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; background: var(--sage-light); color: var(--sage); }
.dispo { display: flex; gap: .3rem; margin-top: .5rem; flex-wrap: wrap; }
.modal-foot { border-top: 1px solid var(--stone); padding: .7rem 1rem; background: var(--surface-alt); display: flex; align-items: center; gap: .5rem; }

/* Lookup slide-in */
.lookup-panel { position: fixed; top: 0; left: 0; height: 100vh; width: 360px; background: var(--surface); border-right: 1px solid var(--border-dark); box-shadow: 6px 0 24px rgba(0,0,0,.18); z-index: 950; transform: translateX(-100%); transition: transform .22s ease; display: flex; flex-direction: column; }
.lookup-panel.open { transform: translateX(0); }
.lookup-head { padding: .85rem 1rem; border-bottom: 1px solid var(--stone); }
.lookup-head input { width: 100%; padding: .5rem .6rem; border: 1px solid var(--border-dark); border-radius: 7px; font-size: .95rem; font-family: inherit; background: var(--surface); color: var(--text); }
.lookup-list { flex: 1; overflow-y: auto; padding: .5rem; }
.file-row { display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border-radius: 7px; cursor: pointer; }
.file-row:hover { background: var(--row-hover); }
.file-name { flex: 1; font-size: .88rem; }
.file-type { font-size: .72rem; color: var(--text-muted); }
.sync { font-size: .72rem; font-weight: 700; white-space: nowrap; }
.sync.ok { color: var(--sage); }
.sync.pending { color: var(--gold); }
