/* Palette: white, maroon (slightly lightened from #800000), gray #888888, light gray #D3D3D3 */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f5f5;
  --surface-3: #ebebeb;
  --border: #e3e3e3;
  --border-strong: #cfcfcf;
  --text: #333333;
  --text-strong: #111111;
  --muted: #6e6e6e;
  --light-gray: #d3d3d3;
  --maroon: #941c1c;
  --maroon-hover: #a82a2a;
  --maroon-deep: #7a1414;
  --on-maroon: #ffffff;
  --red: #a82a2a;
  --link: #941c1c;
  --radius: 6px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

h1, h2 { font-weight: 600; margin: 0; color: var(--text-strong); }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }
a { color: var(--link); }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px; flex: none;
  background: #fafafa;
  border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh;
}
.brand-row {
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 18px;
  border-bottom: 1px solid var(--border);
}
.logo { display: inline-flex; align-items: center; gap: 3px; }
.logo span { width: 9px; height: 9px; border-radius: 50%; }
.logo span:nth-child(1) { background: var(--maroon); }
.logo span:nth-child(2) { background: #888888; }
.logo span:nth-child(3) { background: var(--light-gray); }
.brand-name { font-weight: 600; color: var(--text-strong); }

.nav { display: flex; flex-direction: column; padding: 10px 0; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--maroon); color: var(--on-maroon); }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 20px;
  background: var(--maroon);
  color: var(--on-maroon);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { color: var(--on-maroon); min-width: 110px; }
.top-search {
  flex: 1; max-width: 520px; margin-left: auto;
  background: rgba(255, 255, 255, .16) !important;
  border-color: transparent !important;
  color: var(--on-maroon) !important;
}
.top-search::placeholder { color: rgba(255, 255, 255, .75); }

.view { flex: 1; }
.page { padding: 18px 20px 48px; }

/* ---------- Controls ---------- */
.btn {
  height: 34px; padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--maroon); border-color: var(--maroon); color: var(--on-maroon); }
.btn.primary:hover { background: var(--maroon-hover); }
.btn.on-bar { background: #ffffff; border-color: #ffffff; color: var(--maroon); }
.btn.on-bar:hover { background: #f3e6e6; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--link); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; border-color: transparent; color: var(--link); }
.btn.danger:hover { background: var(--surface-2); }
.btn.small { height: 28px; padding: 0 10px; }
.btn:disabled { opacity: .6; cursor: progress; }

.icon-btn {
  width: 32px; height: 32px; flex: none;
  border: none; background: transparent; color: var(--muted);
  border-radius: var(--radius);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text-strong); }

input, select, textarea {
  font: inherit; color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 6px 10px; min-width: 0;
}
input, select { height: 34px; }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: #9a9a9a; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .th-btn:focus-visible,
tr:focus-visible, .side-row:focus-visible, .nav a:focus-visible, .side-tabs button:focus-visible {
  outline: 2px solid var(--red); outline-offset: 1px;
}

/* ---------- Dashboard ---------- */
.dash { display: grid; grid-template-columns: minmax(0, 1fr) 380px; min-height: calc(100vh - 56px); }
.dash-main { padding: 0 20px 40px; min-width: 0; }

.period-bar {
  display: flex; align-items: center; gap: 4px;
  height: 52px; margin: 0 -20px 16px; padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.period-label { font-weight: 500; color: var(--text-strong); margin-left: 8px; }
.period-bar select { height: 32px; margin-left: 6px; max-width: 190px; }
.period-bar select.active { border-color: var(--red); color: var(--text-strong); }
.period-bar .rates-btn { margin-left: 6px; height: 32px; }

/* ---------- Conversion rates ---------- */
.rate-note {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--surface-2); border-left: 3px solid var(--maroon);
  border-radius: var(--radius); padding: 8px 12px; margin-bottom: 14px; font-size: 13px;
}
.rate-note[hidden] { display: none; }
.rate-note span { flex: 1; min-width: 200px; }
.rate-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.rate-row { display: grid; grid-template-columns: 90px minmax(0, 1fr) 36px; align-items: center; gap: 10px; }
.rate-code { font-weight: 500; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.rate-add { display: flex; gap: 8px; }
.rate-add input { flex: 1; }
dialog.narrow { width: min(460px, calc(100vw - 32px)); }
.approx { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }

.kpi-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px 12px;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px;
}
.kpi-label { color: var(--text); font-size: 14px; }
.kpi-value { font-size: 24px; font-weight: 500; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.kpi-value.accent { color: var(--link); }
.kpi-sub { font-size: 11px; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card h2 { margin-bottom: 12px; }

.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head h2 { margin: 0; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 16px; height: 0; border-top: 2px solid; }

.chart { position: relative; height: 260px; }
.chart svg { display: block; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart .guide { stroke: var(--border-strong); stroke-width: 1; }
.chart-tip {
  position: absolute; top: 8px; pointer-events: none;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 8px 10px; font-size: 12px; min-width: 150px;
}
.chart-tip .tip-title { font-weight: 600; color: var(--text-strong); margin-bottom: 4px; }
.chart-tip .tip-row { display: flex; justify-content: space-between; gap: 12px; }
.chart-tip .tip-row b { font-weight: 500; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.note { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.split .card { margin-bottom: 0; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; font-size: 13px; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-val { color: var(--text-strong); font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; position: relative; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: #b5b5b5; border-radius: 3px; }
.bar-fill.inner { background: var(--red); }
.bars .none { color: var(--muted); font-size: 13px; }

.dash-side { background: var(--surface); border-left: 1px solid var(--border); min-width: 0; }
.side-tabs { display: flex; height: 52px; background: var(--maroon-deep); }
.side-tabs button {
  all: unset; cursor: pointer; padding: 0 16px;
  color: rgba(255, 255, 255, .78); font-weight: 500; font-size: 13px;
  display: flex; align-items: center;
  border-bottom: 2px solid transparent;
}
.side-tabs button:hover { color: var(--on-maroon); }
.side-tabs button[aria-selected=true] { color: var(--on-maroon); border-bottom-color: #ffffff; }
.side-header { padding: 10px 16px; font-size: 12px; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); }
.side-list { max-height: calc(100vh - 56px - 52px - 38px); overflow-y: auto; }
.side-row {
  all: unset; box-sizing: border-box; cursor: pointer; width: 100%;
  display: grid; grid-template-columns: minmax(0, 1fr) auto 86px; gap: 10px; align-items: center;
  padding: 11px 16px; border-bottom: 1px solid var(--border);
}
.side-row:hover { background: var(--surface-2); }
.sr-title { color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-amt { font-variant-numeric: tabular-nums; text-align: right; }
.side-row .pill { justify-self: stretch; text-align: center; }
.side-empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* ---------- Status pills ---------- */
.pill { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 3px; white-space: nowrap; }
.pill.paid { background: var(--light-gray); color: #141414; }
.pill.part { background: #888888; color: #ffffff; }
.pill.process { background: #ffffff; color: var(--maroon); box-shadow: inset 0 0 0 1px var(--maroon); }
.pill.unpaid { background: var(--maroon); color: var(--on-maroon); }

/* ---------- Progress ---------- */
.prog { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.prog::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.prog.new::before { background: var(--light-gray); box-shadow: inset 0 0 0 1px #aaaaaa; }
.prog.ongoing::before { background: var(--maroon); }
.prog.hold::before { background: #888888; }
.prog.completed::before { background: #333333; }

/* Pipeline: label only, no money. */
.pipe { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.pipe::before { content: ""; width: 8px; height: 8px; border-radius: 2px; flex: none; }
.pipe.committed::before { background: var(--maroon); }
.pipe.upside::before { background: #ffffff; box-shadow: inset 0 0 0 2px var(--maroon); }
.pipe.omitted::before { background: var(--light-gray); }
.pipe.omitted { color: var(--muted); }
.small-value { font-size: 13px !important; font-weight: 500 !important; }

.progress-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.prog-tile { all: unset; box-sizing: border-box; cursor: pointer; background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; }
.prog-tile:hover { background: var(--surface-3); }
.prog-tile:focus-visible { outline: 2px solid var(--red); outline-offset: 1px; }
.prog-tile .count { display: block; font-size: 22px; font-weight: 500; color: var(--text-strong); }

.split-summary { display: flex; flex-direction: column; gap: 12px; }
.split-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; }
.split-row .who { font-weight: 500; color: var(--text-strong); }
.split-row .amt { font-size: 18px; font-weight: 500; color: var(--text-strong); font-variant-numeric: tabular-nums; text-align: right; }
.split-row .sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.split-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-3); }
.split-bar .v { background: var(--maroon); }
.split-bar .a { background: #888888; }

/* ---------- Team tags ---------- */
.team-list { font-size: 13px; }
.tag-input {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-height: 34px; padding: 4px 6px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: #ffffff;
  cursor: text;
}
.tag-input:focus-within { outline: 2px solid var(--red); outline-offset: 1px; }
.tag-chips { display: contents; }
.tag-input input { border: none; outline: none !important; flex: 1; min-width: 140px; height: 24px; padding: 0 4px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-3); color: var(--text-strong);
  border-radius: 3px; padding: 1px 4px 1px 8px; font-size: 13px; font-weight: 400;
}
.tag button { all: unset; cursor: pointer; width: 18px; text-align: center; color: var(--muted); font-size: 15px; line-height: 1; }
.tag button:hover { color: var(--maroon); }

/* ---------- Payment split field ---------- */
.split-field { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px 12px; margin: 0; }
.split-field legend { padding: 0 4px; }
.split-field .check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 400; cursor: pointer; }
.split-field .check input { width: 18px; height: 18px; margin: 0; accent-color: var(--maroon); }
.split-inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 4px; }
.split-inputs[hidden] { display: none; }
.split-person { display: flex; flex-direction: column; gap: 4px; font-weight: 400; }

/* ---------- Projects / clients tables ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters select { flex: 0 1 170px; }
.filters select.active { border-color: var(--red); color: var(--text-strong); }

.selection-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--maroon-deep); color: var(--on-maroon);
  border-radius: var(--radius); padding: 6px 8px 6px 14px; margin-bottom: 12px; font-weight: 500;
}
.selection-bar[hidden] { display: none; }
.selection-bar .btn.ghost { color: var(--on-maroon); }
.selection-bar .btn.ghost:hover { background: rgba(255, 255, 255, .14); }
.btn.danger-solid { background: #ffffff; border-color: #ffffff; color: var(--maroon); }
.btn.danger-solid:hover { background: #f3e6e6; }
.grid th.sel, .grid td.sel { width: 40px; padding-right: 0; cursor: default; }
.grid .sel input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--maroon); cursor: pointer; }
.grid tbody tr.selected { background: #f6eded; }
.grid tbody tr.selected:hover { background: #f0e2e2; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.grid th { font-weight: 500; color: var(--muted); font-size: 12px; white-space: nowrap; background: var(--surface-2); }
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--surface-2); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.th-btn { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th.num .th-btn { justify-content: flex-end; }
.th-btn::after { content: ""; width: 10px; font-size: 9px; }
th[aria-sort=ascending] .th-btn, th[aria-sort=descending] .th-btn { color: var(--text-strong); }
th[aria-sort=ascending] .th-btn::after { content: "\25B2"; }
th[aria-sort=descending] .th-btn::after { content: "\25BC"; }

.cell-title { font-weight: 500; color: var(--text-strong); }
.cell-sub { font-size: 12px; color: var(--muted); }
.tour-badge {
  font-size: 11px; font-weight: 500; padding: 0 6px; margin-left: 6px;
  border-radius: 3px; border: 1px solid var(--border-strong); color: var(--muted); vertical-align: 1px;
}

.empty { background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 48px 24px; text-align: center; }
.empty h2 { margin-bottom: 6px; }
.empty p { margin: 0 0 16px; color: var(--muted); }
.empty .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- Dialogs ---------- */
dialog {
  border: 1px solid var(--border-strong); border-radius: 10px; padding: 0;
  width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  background: var(--surface); color: var(--text);
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog { box-shadow: 0 20px 60px rgba(0, 0, 0, .18); }
dialog > form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px 12px; border-bottom: 1px solid var(--border); }
.dlg-body { padding: 16px 20px; overflow-y: auto; flex: 1; min-height: 0; }
.dlg-foot { display: flex; gap: 8px; align-items: center; padding: 12px 20px; border-top: 1px solid var(--border); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--text-strong); }
.field input, .field textarea, .field select { font-weight: 400; font-size: 14px; }
.field.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; }
.field.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--maroon); }
.span-2 { grid-column: 1 / -1; }
.req { color: var(--link); }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.err { font-weight: 400; color: var(--link); font-size: 13px; }
.err:empty { display: none; }
.link-list { display: flex; flex-direction: column; gap: 6px; }
.link-row { display: flex; gap: 6px; }
.link-row input { flex: 1; }
.field .btn.small { align-self: flex-start; font-weight: 400; }

.money-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 12px; align-items: center; margin-bottom: 18px; }
.money { background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; }
.money .dvalue { font-size: 18px; font-weight: 600; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 20px; }
.dlabel { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.dvalue { overflow-wrap: anywhere; color: var(--text-strong); }
.prewrap { white-space: pre-wrap; }
.link-stack { display: flex; flex-direction: column; gap: 4px; }
.meta { margin-top: 18px; font-size: 12px; color: var(--muted); }

/* ---------- Import ---------- */
.import-section { margin-bottom: 16px; }
.import-section h3 { font-size: 13px; font-weight: 600; margin: 0 0 6px; color: var(--text-strong); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 3px; background: var(--surface-3); }
.chip.ok { background: var(--light-gray); color: #141414; }
.chip.missing { background: var(--maroon); color: var(--on-maroon); }
.preview { width: 100%; font-size: 13px; border: 1px solid var(--border); border-collapse: collapse; }
.preview th, .preview td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.preview th { color: var(--muted); font-weight: 500; }
.preview-wrap { overflow-x: auto; }
.error-box { background: var(--maroon-deep); color: var(--on-maroon); border-radius: var(--radius); padding: 10px 12px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #222222; color: #ffffff;
  padding: 10px 16px; border-radius: var(--radius);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px); z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--maroon); color: var(--on-maroon); }

/* ---------- Smaller screens ---------- */
@media (max-width: 1180px) {
  .dash { grid-template-columns: minmax(0, 1fr); }
  .dash-side { border-left: none; border-top: 1px solid var(--border); }
  .side-list { max-height: none; }
}
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
  .brand-row { border-bottom: none; }
  .nav { flex-direction: row; padding: 0; overflow-x: auto; }
  .nav a { padding: 16px 14px; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .topbar h1 { display: none; }
  .top-search { order: 3; flex-basis: 100%; max-width: none; }
  .dash-main, .page { padding-left: 16px; padding-right: 16px; }
  .period-bar { margin: 0 -16px 16px; padding: 0 16px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .form-grid, .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .filters select { flex: 1 1 45%; }
  .money-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .money-row .pill { grid-column: 1 / -1; justify-self: start; }
}
