:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --line: #e3e6ec;
  --brand: #1f5fbf;
  --brand-ink: #ffffff;
  --brand-soft: #e8f0fc;
  --danger: #c0392b;
  --ok-bg: #e7f6ec; --ok-ink: #1e6b3a;
  --err-bg: #fdecea; --err-ink: #9b2c1f;
  --top: #172033; --top-ink: #d9deea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --card: #1b2029; --text: #e5e8ef; --muted: #98a0b3; --line: #2c3340;
    --brand: #5b8fe6; --brand-soft: #1f2c44; --ok-bg: #173323; --ok-ink: #8fd6a7; --err-bg: #3a1c19; --err-ink: #f2a59b;
    --top: #0c0f15; --top-ink: #c6cbd8; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { font-size: 14px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .2rem; font-weight: 650; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; font-weight: 650; display: flex; align-items: baseline; gap: .5rem; }
h2 .small { margin-left: auto; font-weight: 400; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.prewrap { white-space: pre-wrap; }
.count { font-size: .8rem; font-weight: 500; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 0 .5rem; }
.overdue, h2.overdue { color: var(--danger); }

.topbar { background: var(--top); color: var(--top-ink); display: flex; align-items: center; gap: 1.25rem; padding: 0 1.25rem; min-height: 52px; flex-wrap: wrap; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; }
.mainnav { display: flex; gap: .15rem; flex-wrap: wrap; }
.mainnav a { color: var(--top-ink); padding: .45rem .7rem; border-radius: 6px; }
.mainnav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.mainnav a.on { background: rgba(255,255,255,.14); color: #fff; }
.topright { margin-left: auto; display: flex; gap: .9rem; align-items: center; }
.topright a { color: var(--top-ink); }
.topright .linkbtn { color: var(--top-ink); }
.groupswitch select { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.2); }
.groupswitch option { color: #000; }
.groupname { font-weight: 600; color: #fff; }

.page { max-width: 1320px; margin: 0 auto; padding: 1.25rem; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.crumb { font-size: .88rem; margin-bottom: .15rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow-x: auto; }
.card .pad { padding: 1rem 1.15rem 0; }
.card.narrow { max-width: 440px; margin: 3rem auto; }
.login h1 { justify-content: center; margin-bottom: 1rem; }
.twocol { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; }
.twocol > div > .card:last-child { margin-bottom: 1rem; }
@media (max-width: 900px) { .twocol { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: .45rem .85rem; border-radius: 6px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--danger); }
.btn.on { background: var(--brand-soft); border-color: var(--brand); }
.btn.small { padding: .2rem .55rem; font-size: .88rem; }
.btnrow { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.btnrow form { margin: 0; }
.linkbtn { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
.linkbtn.danger { color: var(--danger); }

input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .45rem .6rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[disabled] { background: var(--bg); }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.stack label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filters input[type=search] { flex: 1 1 240px; width: auto; }
.filters select, .filters .ref { width: auto; flex: 0 1 190px; }

.recordform fieldset { border: 0; padding: 0; margin: 0 0 1.25rem; }
.recordform legend { font-weight: 650; margin-bottom: .6rem; color: var(--muted); text-transform: uppercase; font-size: .78rem; letter-spacing: .04em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .8rem 1rem; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field > span { font-weight: 500; font-size: .92rem; }
.field.wide { grid-column: 1 / -1; }
.field.check, label.check { flex-direction: row; align-items: center; gap: .4rem; }
.field.check input, label.check input { width: auto; }
.actions { display: flex; gap: .5rem; border-top: 1px solid var(--line); padding-top: 1rem; }

.ref { position: relative; }
.ref-menu { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; min-width: 260px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.15); max-height: 320px; overflow-y: auto; }
.ref-item { padding: .45rem .65rem; cursor: pointer; }
.ref-item.on, .ref-item:hover { background: var(--brand-soft); }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
table.data th a { color: inherit; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
table.data .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data .empty { color: var(--muted); text-align: center; padding: 1.5rem; }
table.data.compact td { padding: .35rem .5rem; }
table.data tr.done td { color: var(--muted); }
table.data tr.done td a { color: var(--muted); text-decoration: line-through; }
table.data tfoot td { border-bottom: 0; }
table.data tr.strong td { font-weight: 700; }
td.check { width: 34px; }
td.check form { margin: 0; }
.tick { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--muted); background: transparent; color: transparent; cursor: pointer; font-size: 12px; line-height: 1; padding: 0; }
.tick:hover { border-color: var(--brand); color: var(--brand); }
.tick.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 520px; }
.lines.edit textarea { min-height: 2.3rem; resize: vertical; }
.lines.edit input { text-align: right; max-width: 120px; }
.lines.edit td:first-child { min-width: 280px; }

.pill { display: inline-block; font-size: .78rem; font-weight: 600; padding: .05rem .5rem; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill[data-v="Closed Won"], .pill[data-v="Paid"], .pill[data-v="Paid In Full"], .pill[data-v="Active"], .pill[data-v="Completed"] { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.pill[data-v="Closed Lost"], .pill[data-v="Void"], .pill[data-v="Deleted"], .pill[data-v="High"] { background: var(--err-bg); color: var(--err-ink); border-color: transparent; }
.pill[data-v="Sent"], .pill[data-v="Partial"], .pill[data-v="Invoiced Full"], .pill[data-v="Invoiced Partial"], .pill[data-v="Paid Partial"], .pill[data-v="In Negotiation"], .pill[data-v="Contract Sent"], .pill[data-v="Open"] { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

dl.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .8rem 1.25rem; margin: 0 0 1rem; }
dl.fields .wide { grid-column: 1 / -1; }
dl.fields dt { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
dl.fields dd { margin: .1rem 0 0; word-break: break-word; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; display: flex; flex-direction: column; }
.stat span { font-size: .8rem; color: var(--muted); }
.stat strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stagebar { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { border: 1px solid var(--line); border-radius: 6px; padding: .35rem .65rem; color: var(--text); display: flex; flex-direction: column; }
.chip small { color: var(--muted); }
.chip.on { border-color: var(--brand); background: var(--brand-soft); }

/* Horizontal bar chart: single series, 20px bars, 4px rounded data end, value at the tip */
.chartcard .charthead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.chartcard .charthead h2 { margin-bottom: .1rem; }
.chartcard .charthead p { margin: 0; }
.chartfilters { display: flex; gap: .5rem; flex-wrap: wrap; }
.chartfilters select { width: auto; }
.eventselect { max-width: 320px; }
.hbars { list-style: none; margin: 0; padding: 0; }
.hbar { display: grid; grid-template-columns: minmax(120px, 180px) 1fr; align-items: center; gap: .75rem; padding: 4px 6px; border-radius: 6px; color: var(--text); }
.hbar:hover, .hbar:focus-visible { background: var(--brand-soft); text-decoration: none; }
.hbar:hover .hbar-fill, .hbar:focus-visible .hbar-fill { filter: brightness(1.12); }
.hbar-label { font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { display: flex; align-items: center; gap: .5rem; min-height: 26px; border-left: 1px solid var(--line); }
.hbar-fill { display: block; height: 20px; width: 0; flex: none; background: var(--brand); border-radius: 0 4px 4px 0; }
.hbar-value { font-size: .88rem; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.defaultrow { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin: -.5rem 0 1rem; }
@media (max-width: 600px) { .hbar { grid-template-columns: 1fr; gap: .2rem; } .hbar-track { border-left: 0; } }

.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.error { background: var(--err-bg); color: var(--err-ink); }
.copyrow { display: flex; gap: .5rem; margin-top: .5rem; }

.pager { display: flex; gap: .75rem; align-items: center; justify-content: center; margin: 1rem 0; }
.subnav { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.subnav a { padding: .5rem .8rem; color: var(--muted); border-bottom: 2px solid transparent; }
.subnav a.on { color: var(--text); border-color: var(--brand); }
form.inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: 0; }
form.inline input { width: auto; flex: 1 1 160px; }
form.inline input.short, input.short { flex: 0 0 80px; width: 80px; }
form.inline select { width: auto; }
.addrow { margin-top: 1rem; }
.lookuplayout { display: grid; grid-template-columns: 240px 1fr; gap: 1rem; }
.listnav { display: flex; flex-direction: column; padding: .5rem; }
.listnav a { padding: .4rem .6rem; border-radius: 6px; color: var(--text); display: flex; justify-content: space-between; }
.listnav a.on { background: var(--brand-soft); }
@media (max-width: 760px) {
  .lookuplayout { grid-template-columns: 1fr; }
  .page { padding: 1rem; }
  .topright { margin-left: 0; }
}
