:root {
  --red: #C21F2E; --red-dark: #9E1824; --ink: #1D232B; --muted: #5E6773;
  --line: #DDE1E6; --bg: #F5F6F8; --card: #FFFFFF; --ok: #1E7B45; --warn: #9A6200;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Calibri, sans-serif;
  color: var(--ink); background: var(--bg); padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
small, .muted { color: var(--muted); }

/* top bar */
.top { background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 20; }
.top-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 18px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
.brand { color: #fff; font-weight: 700; letter-spacing: .08em; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.brand img { height: 26px; background: #fff; border-radius: 4px; padding: 2px 4px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #D7DCE2; padding: 6px 10px; border-radius: 6px; font-size: 14px; }
.nav a.on, .nav a:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.top form { margin: 0; }
.linkbtn { background: none; border: 0; color: #D7DCE2; font: inherit; cursor: pointer; padding: 6px; }

/* bottom tab bar on phones */
.tabs { display: none; }
@media (max-width: 760px) {
  .nav, .top .desk { display: none; }
  .tabs { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: #fff;
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabs a { flex: 1; text-align: center; padding: 9px 0 8px; font-size: 11px; color: var(--muted); }
  .tabs a.on { color: var(--red); font-weight: 600; }
  .tabs a span { display: block; font-size: 18px; line-height: 1.1; }
  body { padding-bottom: 70px; }
}

main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 40px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stat b { display: block; font-size: 22px; }

/* forms */
label { display: block; font-size: 13px; font-weight: 600; color: #39424D; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number],
input[type=search], input:not([type]), select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  padding: 9px 10px; border: 1px solid #C5CBD3; border-radius: 8px; background: #fff; color: var(--ink); }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(194,31,46,.25); border-color: var(--red); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: 18px; height: 18px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; font-weight: 400; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  padding: 9px 14px; border-radius: 8px; border: 1px solid #C5CBD3; background: #fff; color: var(--ink);
  cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover { text-decoration: none; background: #F0F2F5; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline { display: inline; margin: 0; }

/* tables / lists */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; border-bottom: 1px solid var(--line); padding: 8px 10px; }
table.list td { border-bottom: 1px solid var(--line); padding: 10px; vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.link { cursor: pointer; }
table.list tr.link:hover td { background: #FAFAFB; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) {
  table.list.stack thead { display: none; }
  table.list.stack tr { display: grid; grid-template-columns: 1fr auto; padding: 10px 2px; border-bottom: 1px solid var(--line); }
  table.list.stack td { border: 0; padding: 1px 8px; }
  table.list.stack td.hide-sm { display: none; }
  table.list.stack td.tot { grid-column: 2; grid-row: 1; }
}

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #EEF0F3; color: #4A525D; text-transform: capitalize; }
.badge.sent, .badge.partial { background: #FFF4DB; color: var(--warn); }
.badge.accepted, .badge.paid { background: #E3F4EA; color: var(--ok); }
.badge.declined, .badge.void, .badge.expired, .badge.overdue { background: #FBE4E6; color: var(--red-dark); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input[type=search] { flex: 1; min-width: 180px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chips a { padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 13px; }
.chips a.on { background: var(--ink); color: #fff; border-color: var(--ink); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-weight: 500; }
.flash.ok { background: #E3F4EA; color: #155C33; }
.flash.error { background: #FBE4E6; color: #7D121C; }

/* line items editor */
.item { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 10px; background: #FBFBFC; }
.item-grid { display: grid; gap: 8px; grid-template-columns: 1fr 90px 80px 120px 110px 36px; align-items: end; }
.item-grid .desc { grid-column: 1 / -1; }
.item .line-total { font-weight: 700; text-align: right; padding: 9px 0; font-variant-numeric: tabular-nums; }
.item .rm { border: 0; background: none; color: var(--muted); font-size: 22px; cursor: pointer; padding: 4px; }
@media (max-width: 760px) {
  .item-grid { grid-template-columns: 1fr 1fr; }
  .item-grid .pick { grid-column: 1 / -1; }
  .item .rm { justify-self: end; }
}
.totals { margin-left: auto; max-width: 360px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; font-size: 18px; font-weight: 700; }

details summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.sticky-save { position: sticky; bottom: 0; background: rgba(245,246,248,.95); padding: 12px 0; display: flex; gap: 8px;
  justify-content: flex-end; border-top: 1px solid var(--line); margin-top: 10px; z-index: 5; }
@media (max-width: 760px) { .sticky-save { bottom: 58px; } .sticky-save .btn { flex: 1; } }

.login { max-width: 380px; margin: 9vh auto; }
.login .logo { text-align: center; margin-bottom: 18px; }
.login .logo img { width: 190px; }
.pdf-frame { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
@media (max-width: 760px) { .pdf-frame { display: none; } }
.events { font-size: 13px; color: var(--muted); padding-left: 18px; margin: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; white-space: pre-line; }
