:root {
  --orange: #F77600;
  --orange-dark: #d86400;
  --orange-soft: #fff1e5;
  --ink: #141414;
  --ink-2: #2a2a2a;
  --muted: #6b6b6b;
  --line: #e4e1dc;
  --bg: #f5f4f2;
  --card: #ffffff;
  --red: #c62828;
  --red-soft: #fdecea;
  --amber: #b26a00;
  --amber-soft: #fff4dc;
  --green: #2e7d32;
  --green-soft: #e8f5e9;
  --blue: #1f5fa8;
  --blue-soft: #e8f0fb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 Roboto, system-ui, -apple-system, "Segoe UI", Arial, sans-serif; }
a { color: var(--orange-dark); }
h1, h2, h3, .brand, .tile .n, .btn, th { font-family: Oswald, "Arial Narrow", Arial, sans-serif; }
h1 { font-size: 26px; font-weight: 600; margin: 0; letter-spacing: .02em; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 10px; letter-spacing: .04em; text-transform: uppercase; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #fff; padding: 18px 0; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { font-size: 24px; font-weight: 600; letter-spacing: .06em; padding: 0 20px 4px; }
.brand b { color: var(--orange); font-weight: 600; }
.brand-sub { font: 500 10px Oswald, sans-serif; letter-spacing: .3em; color: var(--orange); padding: 0 20px 18px; text-transform: uppercase; }
.nav a { display: flex; align-items: center; gap: 10px; color: #ddd; text-decoration: none; padding: 10px 20px; border-left: 3px solid transparent; font-weight: 500; }
.nav a:hover { background: var(--ink-2); color: #fff; }
.nav a.on { border-left-color: var(--orange); color: #fff; background: #1e1e1e; }
.nav .count { margin-left: auto; background: var(--orange); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; min-width: 20px; text-align: center; }
.side .me { border-top: 1px solid #2c2c2c; margin-top: 16px; padding: 14px 20px; font-size: 13px; color: #aaa; }
.side .me button { margin-top: 8px; }
.main { min-width: 0; padding: 24px 28px 60px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.menu-btn { display: none; margin-bottom: 10px; }
.nw { white-space: nowrap; }

/* ---------- cards, tiles, grid ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 18px; }
.grid > *, .tiles > * { min-width: 0; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; text-decoration: none; color: inherit; border-top: 3px solid var(--ink); display: block; }
.tile.alert { border-top-color: var(--orange); }
.tile.bad { border-top-color: var(--red); }
.tile .n { font-size: 28px; font-weight: 600; line-height: 1.1; }
.tile .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border-bottom: 2px solid var(--ink); padding: 8px 8px; white-space: nowrap; }
table.t td { border-bottom: 1px solid var(--line); padding: 9px 8px; vertical-align: top; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #faf8f5; }
table.t .num, .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.t tfoot td { font-weight: 700; border-bottom: 0; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }
.sub { color: var(--muted); font-size: 12px; }

/* ---------- badges ---------- */
.b { display: inline-block; border-radius: 10px; padding: 1px 9px; font-size: 12px; font-weight: 500; background: #eee; color: #333; white-space: nowrap; }
.b.new, .b.draft, .b.provisional, .b.ready_to_review, .b.requested, .b.upcoming { background: var(--blue-soft); color: var(--blue); }
.b.contacted, .b.sent, .b.approved, .b.on_request, .b.due_soon, .b.due_today, .b.held { background: var(--amber-soft); color: var(--amber); }
.b.quoted { background: var(--orange-soft); color: var(--orange-dark); }
.b.won, .b.accepted, .b.confirmed, .b.paid, .b.completed, .b.part_paid { background: var(--green-soft); color: var(--green); }
.b.lost, .b.declined, .b.expired, .b.cancelled, .b.void, .b.failed, .b.overdue { background: var(--red-soft); color: var(--red); }
.b.ski, .b.sail, .b.beach { background: var(--ink); color: #fff; }
.b.ski::before { content: "▲ "; color: var(--orange); }
.b.sail::before { content: "⛵ "; }
.b.beach::before { content: "☀ "; color: var(--orange); }

/* ---------- forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--ink); background: #fff; color: var(--ink); border-radius: 6px; padding: 7px 14px; font-size: 14px; font-weight: 500; letter-spacing: .04em; cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 36px; }
.btn:hover { background: #f1efec; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.primary:hover { background: var(--orange-dark); }
.btn.dark { background: var(--ink); color: #fff; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.small { padding: 3px 9px; min-height: 28px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--orange-dark); padding: 0; min-height: 0; font-family: inherit; letter-spacing: 0; }
.btn:disabled { opacity: .5; cursor: default; }
.side .btn { background: transparent; color: #ddd; border-color: #555; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; letter-spacing: .03em; }
input, select, textarea { font: inherit; width: 100%; border: 1px solid #cfcac3; border-radius: 6px; padding: 7px 9px; background: #fff; color: var(--ink); min-height: 36px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--orange); outline-offset: 1px; border-color: var(--orange); }
input[type=checkbox] { width: auto; min-height: 0; }
.row { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.search { max-width: 320px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 16px; cursor: pointer; font: 500 14px Roboto, sans-serif; color: var(--muted); }
.tabs button.on { background: var(--ink); color: #fff; }

/* line editor */
table.lines input, table.lines select { min-height: 32px; padding: 4px 6px; }
table.lines td { padding: 5px 4px; }
table.lines .w-type { width: 130px; } table.lines .w-date { width: 135px; } table.lines .w-qty { width: 64px; } table.lines .w-money { width: 110px; }

/* ---------- details ---------- */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--line); padding: 0 0 12px 12px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 6px; width: 8px; height: 8px; background: var(--orange); border-radius: 50%; }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal .dow { font: 500 12px Oswald, sans-serif; letter-spacing: .1em; text-transform: uppercase; text-align: center; padding: 6px; background: var(--ink); color: #fff; }
.cal .day { min-height: 104px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px; background: #fff; }
.cal .day.out { background: #faf9f7; color: #aaa; }
.cal .day.today { box-shadow: inset 0 0 0 2px var(--orange); }
.cal .d { font-size: 12px; font-weight: 700; }
.chip { display: block; font-size: 11px; line-height: 1.3; border-radius: 4px; padding: 2px 4px; margin-top: 3px; text-decoration: none; color: var(--ink); background: #eee; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.travel { background: var(--ink); color: #fff; }
.chip.overdue { background: var(--red-soft); color: var(--red); }
.chip.due_soon, .chip.due_today { background: var(--amber-soft); color: var(--amber); }
.chip.upcoming { background: var(--blue-soft); color: var(--blue); }
.chip.paid { background: var(--green-soft); color: var(--green); }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; margin-top: 10px; }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 20; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 640px; padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 980px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toast { position: fixed; right: 16px; bottom: 16px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; border-left: 4px solid var(--orange); z-index: 30; max-width: calc(100vw - 32px); box-shadow: 0 4px 18px rgba(0,0,0,.3); }
.toast.err { border-left-color: #ff5a4f; }
.err-box { background: var(--red-soft); color: var(--red); padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; }
.note { background: var(--orange-soft); border-left: 4px solid var(--orange); padding: 10px 14px; border-radius: 4px; margin-bottom: 14px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--ink); padding: 16px; }
.login form { background: #fff; border-radius: 10px; padding: 28px; width: 100%; max-width: 380px; border-top: 4px solid var(--orange); }
.login .brand { color: var(--ink); padding: 0; text-align: center; font-size: 30px; }
.login .brand-sub { padding: 0 0 20px; text-align: center; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 15; transform: translateX(-100%); transition: transform .2s, visibility .2s; visibility: hidden; }
  .shell.menu-open .side { transform: none; visibility: visible; }
  .btn.menu-btn { display: inline-flex; }
  .main { padding: 14px 16px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .cal .day { min-height: 70px; }
  .cal .chip { font-size: 10px; }
  h1 { font-size: 22px; }
}
@media (max-width: 560px) {
  .cal { grid-template-columns: 1fr; }
  .cal .dow, .cal .day.out, .cal .day.blank { display: none; }
  .cal .day { min-height: 0; }
  .cal .day:not(.has) { display: none; }
}
