:root {
  /* Fresha-style: black, white, one blue accent; same font as the booking website */
  --bg: #f6f6f6;
  --surface: #ffffff;
  --surface-2: #f5f5f5;
  --border: #e5e5e5;
  --text: #0d0d0d;
  --muted: #767676;
  --ink: #0d0d0d;            /* primary buttons */
  --ink-hover: #262626;
  --accent: #2563eb;          /* blue: active, focus, highlights, links */
  --accent-hover: #1d4ed8;
  --accent-soft: #eff4ff;
  --accent-line: #c7d7fe;
  --danger: #d1352b;
  --danger-soft: #fde8e6;
  --good: #1f8900;
  --good-soft: #ecf8e3;
  --warn: #a35a00;
  --warn-soft: #fdf0dc;
  --nav-bg: #ffffff;
  --nav-text: #4d4d4d;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .06);
  --shadow-lg: 0 2px 6px rgb(0 0 0 / .05), 0 16px 40px rgb(0 0 0 / .12);
  font: 400 14.5px/1.5 "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.test-banner { background: #fde68a; color: #713f12; text-align: center; padding: 6px 12px; font-size: 13px; position: sticky; top: 0; z-index: 45; }
.boot { padding: 40px; color: var(--muted); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.flush { margin: 0; }
.subtitle { margin: -10px 0 16px; }
.nowrap { white-space: nowrap; }
select.auto { width: auto; }
.filter-bar { padding: 12px 16px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.neg { color: var(--danger); }
.pos { color: var(--good); }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav { background: var(--nav-bg); color: var(--nav-text); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; color: var(--text); padding: 0 8px 18px; }
.brand img { width: 28px; height: 28px; }
.nav a { display: block; color: var(--nav-text); padding: 9px 12px; border-radius: var(--radius-sm); margin: 2px 0; font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav .section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #9a9a9a; padding: 14px 10px 4px; }
.nav .me { margin-top: auto; border-top: 1px solid var(--border); padding: 12px 8px 0; font-size: 13px; color: var(--muted); }
.nav .me b { color: var(--text); display: block; }
.nav .me button { background: none; border: 0; color: var(--muted); padding: 4px 0; cursor: pointer; font: inherit; margin-right: 12px; border-radius: 0; }
.nav .me button:hover { color: var(--text); text-decoration: underline; background: none; }
.main { padding: 24px 28px 60px; min-width: 0; }
.page-head { margin-bottom: 16px; }
.head-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.head-nav:not(:has(.back-btn, .lang-btn)) { margin-bottom: 0; }
.head-main { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.head-main h1 { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; }
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.back-btn { padding: 6px 12px; font-size: 13.5px; color: var(--text); flex: none; }
.menu-btn { display: none; }
.nav-backdrop[hidden] { display: none; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-note { padding: 10px 16px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.empty { padding: 22px 16px; color: var(--muted); text-align: center; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.highlight { border-color: var(--accent-line); background: var(--accent-soft); }
.kpi.highlight .value:not(.neg) { color: var(--accent); }
.value.neg, .neg { color: var(--danger); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border); }
td.actions { white-space: nowrap; text-align: right; width: 1%; }
td .clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }

/* badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f0f0f0; color: #4d4d4d; white-space: nowrap; }
.badge.new { background: var(--accent-soft); color: var(--accent); }
/* one colour per service, same order as SERVICES in db.js */
.svc { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.svc::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.svc-0 { background: #f3e8dc; color: #7c4a1e; }   /* Building Repair */
.svc-1 { background: #fef3c7; color: #92400e; }   /* Electrical */
.svc-2 { background: #dbeafe; color: #1e40af; }   /* Plumbing */
.svc-3 { background: #cffafe; color: #155e75; }   /* AC Repair */
.svc-4 { background: #ccfbf1; color: #115e59; }   /* Tiles & Waterproofing */
.svc-5 { background: #ffedd5; color: #9a3412; }   /* Carpentry */
.svc-6 { background: #fce7f3; color: #9d174d; }   /* Painting */
.svc-7 { background: #e0e7ff; color: #3730a3; }   /* Doors & Windows */
.svc-8 { background: #e5e7eb; color: #374151; }   /* General Work */
.svc-9 { background: #dcfce7; color: #166534; }   /* Garden Work */
.svc-10 { background: #f3e8ff; color: #6b21a8; }  /* Bathroom Repair */
.badge.in_progress { background: #fff6e5; color: var(--warn); }
.badge.completed { background: #ecfdf3; color: var(--good); }
.badge.upd { background: #fff6e5; color: var(--warn); }
.badge.paid { background: var(--good-soft); color: var(--good); }
.badge.cash { background: var(--good); color: #fff; }
.badge.settled { background: var(--ink); color: #fff; }
.badge.cancelled { background: var(--danger-soft); color: var(--danger); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.flow-in { background: #ecfdf3; color: var(--good); }
.badge.flow-out { background: #fff1f0; color: var(--danger); }
.badge.flow-move { background: #eff4ff; color: #3538cd; }
tr.reversed td { color: var(--muted); }
tr.reversed td .badge.flow-in, tr.reversed td .badge.flow-out { opacity: .7; }
.badge.lock { background: #fff6e5; color: var(--warn); }

/* buttons & forms */
button, .btn { font: inherit; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 16px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-weight: 500; transition: background .15s, border-color .15s; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
button.primary:hover, .btn.primary:hover { background: var(--ink-hover); border-color: var(--ink-hover); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.small, .btn.small { padding: 4px 9px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); border: 1px solid #d3d3d3; border-radius: var(--radius-sm); padding: 9px 12px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: auto; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.req { color: var(--danger); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.filter-grid .wide { grid-column: 1 / -1; }
.filter-actions { display: flex; gap: 12px; align-items: center; }
.filter-presets { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.section-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.section-row .btn { margin-left: auto; }
.section-title { font-size: 15px; margin: 20px 0 10px; }
.scope-switch { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0 12px; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
table.grid-input td { padding: 6px; vertical-align: middle; }
table.grid-input input { padding: 6px 8px; min-width: 80px; }
table.grid-input td:first-child input { min-width: 160px; }
/* ledger entries */
.entries { padding: 0 0 4px; }
.day-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 10px 16px 6px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 13px; }
.entry { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.entry:last-child { border-bottom: 0; }
.entry-title { font-weight: 600; font-size: 15px; }
.entry-title .badge { margin-left: 4px; }
.entry-sub { color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.entry-amt { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.entry-amt.move { color: #3538cd; }
.entry-acts { margin-top: 6px; display: flex; gap: 6px; justify-content: flex-end; }
.entry-acts button { font-weight: 400; }
.entry-void .entry-title, .entry-void .amt { opacity: .55; }
.entry-void .amt { text-decoration: line-through; }
.flow-icon { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; font-weight: 700; font-size: 16px; flex: none; }
.flow-icon.flow-in { background: #ecfdf3; color: var(--good); }
.flow-icon.flow-out { background: #fff1f0; color: var(--danger); }
.flow-icon.flow-move { background: #eff4ff; color: #3538cd; }
.flow-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.flow-btn { justify-content: center; padding: 10px 8px; font-weight: 600; }
.flow-btn .flow-icon { width: 22px; height: 22px; font-size: 13px; }
.ledger-filter { display: grid; grid-template-columns: 1fr 1fr 1.4fr auto; gap: 10px; align-items: end; margin-bottom: 10px; }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 9px 12px; margin-bottom: 12px; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }

/* detail list */
.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 24px; }
.details .k { font-size: 12px; color: var(--muted); }
.details .v { white-space: pre-line; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal.wide { max-width: 820px; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 640px; box-shadow: var(--shadow-lg); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h2 { flex: 1; font-size: 16px; }
.modal-head button { border: 0; font-size: 20px; padding: 0 6px; line-height: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.notice { background: #fff6e5; color: var(--warn); border-radius: 8px; padding: 9px 12px; margin-bottom: 14px; font-size: 13px; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; }
.login .card-body { padding: 32px; display: flex; flex-direction: column; gap: 16px; }
.login .brand { color: var(--text); padding: 0; font-size: 17px; }

/* toast */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 60; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--danger); }

/* audit */
.diff { font-size: 13px; margin-top: 4px; }
.diff summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.diff div { margin: 1px 0; }
.diff s { color: var(--danger); }
.diff ins { color: var(--good); text-decoration: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .nav.open { transform: none; }
  .nav-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 39; }
  .menu-btn { display: inline-flex; }
  .main { padding: 12px 14px 48px; }
  .head-nav { margin-bottom: 8px; }
  .head-main h1 { font-size: 22px; }
  .page-head .btn, .page-head button { padding: 6px 12px; font-size: 13.5px; }
  .menu-btn { padding: 6px 11px; }
  .form-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .flow-btns { grid-template-columns: 1fr 1fr; }
  .ledger-filter { grid-template-columns: 1fr 1fr; }
  .ledger-filter .field:nth-child(3) { grid-column: 1 / -1; }
  .entry { gap: 10px; padding: 12px; }
  .entry-amt { font-size: 16px; }
  .kpi { padding: 10px 12px; }
  .kpi .value { font-size: 16px; }
  .toolbar input, .toolbar select { min-width: 0; flex: 1; }
}
tbody td:first-child { white-space: nowrap; }

/* website-booking label in the admin app */
.badge.online { background: #fef3c7; color: #92400e; }

/* work orders as cards on phones */
.wo-cards { display: none; }
.wo-card { padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.wo-card:last-child { border-bottom: 0; }
.wo-card:active { background: var(--surface-2); }
.wo-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.wo-name { font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.wo-line { font-size: 13px; margin-top: 4px; overflow-wrap: anywhere; }
@media (max-width: 860px) {
  .wo-cards { display: block; }
  .wo-cards + .table-wrap { display: none; }
}

/* "what is it?" picker (Add to the ledger) */
.pick-group + .pick-group { margin-top: 16px; }
.pick-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pick { flex-direction: column; align-items: flex-start; gap: 2px; border-radius: var(--radius-sm); padding: 10px 12px; text-align: left; border: 1px solid var(--border); }
.pick b { font-size: 15px; }
.pick span { font-size: 12px; color: var(--muted); font-weight: 400; }
.pick-in { border-left: 3px solid var(--good); }
.pick-out { border-left: 3px solid var(--danger); }
.pick-move { border-left: 3px solid var(--accent); }
.pick:hover { border-color: var(--text); }
@media (max-width: 360px) { .pick-grid { grid-template-columns: 1fr; } }

/* language switch (中文 / English) */
.nav .me .lang-btn { color: var(--accent); font-weight: 600; }
.login .lang-btn { display: block; margin: 14px auto 0; background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.login .lang-btn:hover { text-decoration: underline; background: none; }
.head-nav .head-lang { margin-left: auto; font-weight: 600; color: var(--accent); }
