:root {
  --primary: #4db6a5;
  --primary-dark: #379a89;
  --accent: #ff8f00;
  --bg: #f1f2f6;
  --card: #ffffff;
  --text: #23272e;
  --muted: #8a919c;
  --border: #e4e7ee;
  --danger: #e15b5b;
  --ok: #3ba776;
  --orange: #f0a63a;
  --blue: #4f7df0;
  --field: #f0f1f5;
  --nav-h: 74px;
}
body.dark {
  --bg: #12161c;
  --card: #1b222c;
  --text: #e8ecf1;
  --muted: #94a0ae;
  --border: #2c3642;
  --field: #232b36;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
code { background: var(--bg); padding: 2px 5px; border-radius: 4px; }

.pos { color: var(--ok); }
.neg { color: var(--danger); }
.warn { color: var(--orange); }
.info { color: var(--blue); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.08);
}
.login-card h1 { margin: 0; color: var(--primary); }
.login-card p { margin: 0; }

/* ---------- shell ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px;
  background: var(--card);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { height: 36px; border-radius: 6px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
#biz-name {
  font-size: 1.35rem; font-weight: 800; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.page-sub { color: var(--muted); font-size: .95rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  border: none; background: none; color: var(--muted);
  cursor: pointer; padding: 6px; border-radius: 50%;
  display: flex; align-items: center;
}
.icon-btn:hover, .icon-btn.active { color: var(--primary); background: var(--bg); }
.badge {
  background: var(--accent); color: #fff;
  font-size: .75rem; padding: 3px 8px; border-radius: 10px;
}
#business-switcher { max-width: 160px; }

/* ---------- bottom / top nav ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  height: var(--nav-h);
}
.tab {
  flex: 1; min-width: 0;
  border: none; background: none; color: var(--muted);
  cursor: pointer; font-size: .78rem; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 4px 0; border-radius: 14px;
}
.tab svg { flex: none; }
.tab span { white-space: nowrap; overflow: hidden; max-width: 100%; }
.tab.active { color: var(--primary); font-weight: 600; }
.tab.active svg { background: color-mix(in srgb, var(--primary) 15%, transparent); border-radius: 16px; padding: 3px 10px; box-sizing: content-box; }

main {
  padding: 12px 14px calc(var(--nav-h) + 20px);
  max-width: 640px; margin: 0 auto;
}

/* desktop: nav along the top, wider content */
@media (min-width: 900px) {
  .tabs {
    position: sticky; top: 0; bottom: auto;
    border-top: none; border-bottom: 1px solid var(--border);
    height: auto; padding: 4px 12px;
    justify-content: center; gap: 8px;
  }
  .tab { flex: none; flex-direction: row; gap: 8px; font-size: .95rem; padding: 10px 16px; }
  .tab.active { background: color-mix(in srgb, var(--primary) 12%, transparent); }
  .tab.active svg { background: none; padding: 0; }
  .topbar { position: static; }
  main { max-width: 1000px; padding-bottom: 40px; }
}

/* ---------- sub-tabs (within a page) ---------- */
.subtabs {
  display: flex;
  background: var(--card);
  border-radius: 14px;
  margin-bottom: 12px;
  overflow-x: auto;
}
.subtab {
  flex: 1; white-space: nowrap;
  border: none; background: none; color: var(--muted);
  font: inherit; font-size: .98rem; cursor: pointer;
  padding: 13px 14px;
  border-bottom: 3px solid transparent;
}
.subtab.active { color: var(--text); font-weight: 700; border-bottom-color: var(--primary); }

/* ---------- segmented control ---------- */
.seg {
  display: flex; width: 100%;
  border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; margin: 10px 0 4px;
}
.seg button {
  flex: 1; border: none; background: var(--field); color: var(--muted);
  font: inherit; font-size: 1.02rem; padding: 12px; cursor: pointer;
}
.seg button.active { background: var(--primary); color: #fff; font-weight: 600; }
.seg button:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- chip ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: #1e4e47; color: #fff;
  font-size: .95rem; font-weight: 600;
  padding: 8px 16px; border-radius: 20px;
  margin-bottom: 8px;
}
.chip::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary);
}

/* ---------- components ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--card); color: var(--text);
  border-radius: 12px; padding: 11px 18px;
  cursor: pointer; font: inherit; font-size: .98rem; font-weight: 600;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary-dark { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.orange { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.dark { background: #2b2f36; border-color: #2b2f36; color: #fff; }
.btn.navy { background: #2c3e63; border-color: #2c3e63; color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 12px; font-size: .88rem; }
.btn.block { width: 100%; padding: 14px; font-size: 1.05rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; color: var(--muted); font-weight: 600; }
label > .lbl, .lbl { text-transform: uppercase; letter-spacing: .04em; font-size: .78rem; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 14px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
input[type="color"] { padding: 3px; height: 46px; }
input[type="checkbox"] { width: 20px; height: 20px; }
.check { flex-direction: row; align-items: center; gap: 8px; }
input:read-only { color: var(--muted); }

.view-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 10px; flex-wrap: wrap;
}
.view-head h2 { margin: 0; }

.card {
  background: var(--card);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(20,30,40,.05);
}
.card h3 { margin: 0 0 12px; font-size: 1.25rem; font-weight: 700; color: var(--text); }

.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid > label { grid-column: 1 / -1; }
  .form-grid.three > label, .form-grid > label.half { grid-column: auto; }
  .form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
}

/* ---------- stat tiles ---------- */
.stat-grid {
  display: grid; gap: 12px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 14px;
}
@media (min-width: 900px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
.stat {
  background: var(--card);
  border-radius: 18px; padding: 16px 18px;
  box-shadow: 0 1px 3px rgba(20,30,40,.05);
}
.stat .label {
  font-size: .78rem; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
}
.stat .value { font-size: 1.65rem; font-weight: 800; margin-top: 6px; }

/* ---------- breakdown rows (tax card, gst position) ---------- */
.rows { width: 100%; }
.rows .row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; padding: 7px 0; font-size: 1.05rem;
}
.rows .row .r-label { color: var(--text); }
.rows .row.strong { font-weight: 800; font-size: 1.1rem; }
.rows .row.sub { font-size: .98rem; }
.rows hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

/* ---------- record cards ---------- */
.rec {
  background: var(--card);
  border-radius: 20px; padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(20,30,40,.05);
  display: flex; justify-content: space-between; gap: 12px;
}
.rec .rec-main { min-width: 0; }
.rec .rec-title { font-weight: 800; font-size: 1.15rem; overflow-wrap: anywhere; }
.rec .rec-sub { color: var(--muted); margin-top: 2px; font-size: .95rem; }
.rec .rec-sub .link { color: var(--primary); font-weight: 600; cursor: pointer; }
.rec .rec-right { text-align: right; flex: none; }
.rec .rec-amt { font-size: 1.35rem; font-weight: 800; }
.rec .rec-excl { color: var(--muted); font-size: .92rem; margin-top: 2px; }
.rec .rec-actions { margin-top: 10px; display: flex; gap: 16px; justify-content: flex-end; }
.rec .rec-actions button {
  border: none; background: none; cursor: pointer; padding: 2px;
  color: var(--primary); display: flex;
}
.rec .rec-actions button.del { color: var(--danger); }
.pill {
  display: inline-block;
  font-size: .78rem; padding: 3px 10px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border);
}
.pill.Paid, .pill.Completed, .pill.Accepted { background: var(--ok); color: #fff; border-color: var(--ok); }
.pill.Sent, .pill.Scheduled { background: var(--primary); color: #fff; border-color: var(--primary); }
.pill.Declined { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---------- quote line items ---------- */
.line-card {
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 16px; padding: 14px;
  margin-bottom: 12px;
  display: flex; flex-direction: column; gap: 12px;
}
.line-card input, .line-card select, .line-card textarea { background: var(--card); }
.line-grid { display: grid; grid-template-columns: 1fr 1.2fr 1.2fr; gap: 10px; }
.line-total {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 14px; font-weight: 800;
}
.line-head { display: flex; justify-content: space-between; align-items: center; }
.totals-card {
  background: var(--field); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px 16px; margin: 12px 0;
}

/* ---------- calendar ---------- */
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.cal-head h3 { margin: 0; font-size: 1.35rem; }
.cal-nav {
  border: none; background: none; color: var(--text);
  font-size: 1.5rem; cursor: pointer; padding: 4px 14px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow {
  text-align: center; color: var(--muted); font-weight: 700;
  font-size: .85rem; padding: 6px 0;
}
.cal-day {
  border: none; background: none; color: var(--text); font: inherit;
  aspect-ratio: 1; border-radius: 14px; cursor: pointer;
  font-size: 1.05rem; position: relative;
}
.cal-day:hover { background: var(--bg); }
.cal-day.sel { background: var(--primary); color: #fff; font-weight: 700; }
.cal-day.today:not(.sel) { outline: 2px solid var(--primary); }
.cal-day .dot {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 6px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
}
.cal-day.sel .dot { background: #fff; }
.day-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 16px 2px 10px;
}
.day-head h3 { margin: 0; }

/* ---------- settings: colour rows + theme toggle ---------- */
.color-row { display: flex; gap: 10px; align-items: center; }
.color-row input { flex: 1; }
.swatch {
  width: 46px; height: 46px; flex: none;
  border-radius: 12px; border: 1px solid var(--border);
  cursor: pointer; padding: 0;
}
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.toggle-title { font-weight: 700; font-size: 1.05rem; }
.switch {
  width: 56px; height: 32px; flex: none;
  border: none; border-radius: 16px;
  background: #cfd4dc; cursor: pointer; position: relative;
  transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: left .15s;
}
.switch.on { background: var(--primary); }
.switch.on::after { left: 27px; }

/* ---------- report period presets ---------- */
.presets { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* ---------- tables (ledgers etc.) ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td.wrap { white-space: normal; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; }
td.num, th.num { text-align: right; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 30px 12px; overflow-y: auto; z-index: 50;
}
.modal {
  background: var(--card);
  border-radius: 20px;
  width: 100%; max-width: 640px;
  padding: 20px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-foot { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.spacer { flex: 1; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 14px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--card);
  padding: 10px 18px; border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  z-index: 100; max-width: 90vw;
}
@media (min-width: 900px) { .toast { bottom: 22px; } }
