:root {
  --ink: #1d1b2c;
  --muted: #6b6880;
  --line: #e4e2ee;
  --bg: #f6f5fb;
  --card: #fff;
  --brand: #3b2f8f;
  --brand-2: #5b4bd1;
  --accent: #f2a33a;
  --ok: #1f8a5b;
  --warn: #b7791f;
  --bad: #c2413b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 16, 60, .06), 0 2px 8px rgba(20, 16, 60, .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #fff; padding: 1.25rem .75rem; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.logo { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.2rem; padding: 0 .5rem 1.25rem; letter-spacing: -.01em; }
.logo-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: var(--brand); font-weight: 900; }
.nav a { display: flex; align-items: center; gap: .6rem; color: #dcd8ff; padding: .6rem .75rem; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.on { background: rgba(255,255,255,.16); color: #fff; }
.nav .ico { width: 20px; text-align: center; }
.nav .pill { margin-left: auto; background: var(--accent); color: var(--brand); border-radius: 99px; font-size: .75rem; padding: 0 .45rem; font-weight: 700; }
.side .who { margin-top: auto; font-size: .85rem; color: #cfc9ff; padding: .5rem; }
.side .who button { margin-top: .4rem; }
main { padding: 1.5rem 2rem 6rem; max-width: 1200px; width: 100%; }
.top { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.top .grow { flex: 1; }

/* Components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { font-size: 1.7rem; font-weight: 800; }
.stat-label { color: var(--muted); font-size: .85rem; }
.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: .55rem .9rem; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand-2); text-decoration: none; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:hover { background: var(--brand); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: .3rem .6rem; font-size: .85rem; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.3); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.empty { color: var(--muted); padding: 1rem 0; text-align: center; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); padding: .7rem 0; display: flex; gap: .75rem; align-items: center; }
.list li:first-child { border-top: 0; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list a.rowlink { color: inherit; display: flex; gap: .75rem; align-items: center; width: 100%; }
.list a.rowlink:hover { text-decoration: none; }
.list a.rowlink:hover .title { color: var(--brand-2); }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .1rem .5rem; border-radius: 99px; background: #eceaf6; color: var(--muted); text-transform: capitalize; white-space: nowrap; }
.badge.sent, .badge.scheduled, .badge.new { background: #e6e3ff; color: var(--brand-2); }
.badge.approved, .badge.completed { background: #dff3e9; color: var(--ok); }
.badge.declined, .badge.cancelled { background: #fbe5e3; color: var(--bad); }
.badge.in_progress { background: #fff1dc; color: var(--warn); }
.badge.recurring { background: #e3f1fb; color: #2b6a95; }
.badge.paid { background: #dff3e9; color: var(--ok); }
.badge.overdue, .badge.void { background: #fbe5e3; color: var(--bad); }
.badge.partial, .badge.changes_requested, .badge.assessment { background: #fff1dc; color: var(--warn); }
.badge.quoted, .badge.received { background: #e3f1fb; color: #2b6a95; }

/* Money, notes, timer */
.content { min-width: 0; }
.timerbar { display: flex; align-items: center; gap: .6rem; background: #1f8a5b; color: #fff; padding: .55rem 2rem; position: sticky; top: 0; z-index: 15; }
.timerbar a { color: #fff; text-decoration: underline; }
.timerbar .grow { flex: 1; }
.timerbar .dot { width: 9px; height: 9px; border-radius: 50%; background: #b9f5d6; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.note { background: #fffaf0; border-color: #f3dfb5; }
.ok-note { background: #f1faf5; border-color: #cbead9; }
.kv { display: flex; justify-content: space-between; padding: .2rem 0; }
.statlink { color: inherit; display: block; }
.statlink:hover { text-decoration: none; border-color: var(--brand-2); }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { padding: .45rem 0; border-top: 1px solid var(--line); }
.checklist li:first-child { border-top: 0; }
.checklist label { display: flex; gap: .6rem; align-items: center; color: var(--ink); font-size: 1rem; font-weight: 500; margin: 0; cursor: pointer; }
.checklist input { width: 22px; height: 22px; flex: none; }
.checklist input:checked + span { text-decoration: line-through; color: var(--muted); }
.list li.wrap { flex-wrap: wrap; }
details summary { cursor: pointer; }
.invoice-doc .doc-head { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.invoice-doc .doc-co { font-weight: 800; font-size: 1.2rem; }
.invoice-doc .doc-title { font-weight: 800; letter-spacing: .04em; color: var(--brand); }
.invoice-doc .doc-to { margin-bottom: 1rem; }
table.bars .barcell { width: 40%; }
.bar { height: 7px; border-radius: 4px; margin: 2px 0; }
.bar.inv, .key.inv { background: var(--brand-2); }
.bar.col, .key.col { background: var(--ok); }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 .2rem 0 .5rem; vertical-align: middle; }
.ev.assessment { border-left-style: dashed; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: .5rem; border-bottom: 1px solid var(--line); }
td { padding: .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }

/* Forms */
form .fields { display: grid; gap: .9rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
form .full { grid-column: 1 / -1; }
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea { width: 100%; font: inherit; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }
.items input { padding: .4rem .5rem; }
.totals { margin-left: auto; width: min(320px, 100%); }
.totals div { display: flex; justify-content: space-between; padding: .2rem 0; }
.totals .grand { font-weight: 800; font-size: 1.1rem; border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .5rem; }
.error { color: var(--bad); font-weight: 600; min-height: 1.2em; }
.search { max-width: 320px; }

/* Schedule */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .5rem; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); min-height: 220px; padding: .5rem; }
.day.today { border-color: var(--brand-2); box-shadow: 0 0 0 1px var(--brand-2); }
.day-head { font-weight: 700; font-size: .85rem; display: flex; justify-content: space-between; margin-bottom: .4rem; }
.day-head .muted { font-weight: 500; }
.ev { display: block; border-radius: 8px; padding: .4rem .5rem; margin-bottom: .35rem; background: #efedff; color: var(--ink); border-left: 4px solid var(--brand-2); font-size: .82rem; }
.ev:hover { text-decoration: none; filter: brightness(.97); }
.ev.completed { background: #e6f5ee; border-left-color: var(--ok); }
.ev.cancelled { background: #f4f3f6; border-left-color: #bbb; text-decoration: line-through; color: var(--muted); }
.ev.in_progress { background: #fff3e0; border-left-color: var(--accent); }
.ev .t { font-weight: 700; }
.ev .c { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, var(--brand) 0%, var(--brand-2) 100%); }
.auth .card { width: min(420px, 100%); padding: 2rem; }
.auth .logo { color: var(--brand); padding: 0 0 1rem; }
.auth form .fields { grid-template-columns: 1fr; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; }
#toast.show { opacity: 1; }

.tabbar { display: none; }

/* Phone */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 1.3rem; }
  .top > .grow { flex-basis: 100%; }
  .card { padding: 1rem; overflow-x: auto; }
  th, td { padding: .4rem .3rem; font-size: .9rem; }
  .card a, .card p { overflow-wrap: anywhere; }
  .side { display: none; }
  main { padding: 1rem 1rem 6rem; padding-top: calc(1rem + env(safe-area-inset-top)); }
  .g4 { grid-template-columns: 1fr 1fr; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .stat { font-size: 1.35rem; }
  form .fields { grid-template-columns: 1fr; }
  .week { grid-template-columns: 1fr; }
  .day { min-height: 0; }
  .day:not(.has) .empty-day { display: none; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
  .tabbar a { display: flex; flex-direction: column; align-items: center; font-size: .7rem; padding: .45rem 0; color: var(--muted); position: relative; }
  .tabbar a .ico { font-size: 1.25rem; line-height: 1.2; }
  .tabbar a.on { color: var(--brand-2); font-weight: 700; }
  .tabbar .pill { position: absolute; top: 2px; right: 22%; background: var(--accent); color: var(--brand); font-size: .65rem; border-radius: 99px; padding: 0 .35rem; font-weight: 800; }
  .hide-phone { display: none; }
  .search { max-width: none; }
  table.items thead { display: none; }
  table.items tr { display: grid; grid-template-columns: 1fr 1fr auto; gap: .35rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
  table.items td { border: 0; padding: 0; }
  table.items td:first-child { grid-column: 1 / -1; }
  .timerbar { padding: .55rem 1rem; padding-top: calc(.55rem + env(safe-area-inset-top)); }
  .invoice-doc .doc-head { flex-direction: column; }
  .invoice-doc .doc-head .right { text-align: left; }
  table.bars .barcell { display: none; }
}

/* Printing an invoice: just the document. */
@media print {
  body { background: #fff; }
  .side, .tabbar, .timerbar, .no-print, #toast { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; }
}
