:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #16181d;
  --muted: #646a78;
  --line: #dfe2ea;
  --accent: #1f3bb3;
  --accent-text: #ffffff;
  --pink: #d61f72;
  --good: #1b8a4b;
  --warn: #b86b00;
  --bad: #c62828;
  --chip: #e8ebf5;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d24;
    --text: #eef0f4;
    --muted: #9aa1b0;
    --line: #2c303a;
    --accent: #5b7cff;
    --accent-text: #0b0d12;
    --pink: #ff5aa5;
    --good: #43c47b;
    --warn: #f0a640;
    --bad: #ff6b6b;
    --chip: #262a35;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-wrap: anywhere;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 19px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .brand { color: var(--accent); }
.top .brand span { color: var(--pink); }
.iconbtn {
  border: 0; background: none; color: var(--accent); font: inherit; font-size: 16px;
  padding: 8px 4px; cursor: pointer; white-space: nowrap;
}

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 96px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.big { width: 100%; min-height: 56px; font-size: 18px; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

.field { display: block; margin-bottom: 10px; }
.field label { display: block; }
.field span:first-child { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, textarea, select {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px; min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px; scrollbar-width: none; }
.tabs button {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 15px; cursor: pointer;
}
.tabs button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tabs .count { opacity: .7; margin-left: 4px; }

.job {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px;
}
.job .t { font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.job .t .title { flex: 1; }
.job .time { color: var(--accent); font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.attach { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; margin-top: 10px; }
.att { position: relative; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; border: 1px solid rgba(127,127,127,.35); }
.att img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.att .pdf { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 26px; padding: 4px; text-align: center; }
.att .pdf span { font-size: 10px; word-break: break-all; margin-top: 4px; }
.att button { position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 12px; border: 0;
  background: rgba(0,0,0,.65); color: #fff; font-size: 16px; line-height: 24px; padding: 0; }
.dayhead { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; opacity: .65; margin: 18px 4px 6px; }
.dayhead:first-of-type { margin-top: 4px; }
.job .s { color: var(--muted); font-size: 14px; margin-top: 2px; }

.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.chip.enquiry { color: var(--pink); }
.chip.onway, .chip.in_progress, .chip.paused { color: var(--warn); }
.chip.done { color: var(--accent); }
.chip.paid { color: var(--good); }
.chip.overdue { color: #fff; background: var(--bad); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--bad); }
.ok { color: var(--good); }
.notice { background: var(--chip); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }

.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo { position: relative; border-radius: 8px; overflow: hidden; background: var(--chip); aspect-ratio: 1; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .badge { position: absolute; left: 4px; bottom: 4px; font-size: 11px; padding: 2px 6px; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; }
.photo button { position: absolute; top: 4px; right: 4px; border: 0; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; padding: 4px 7px; font-size: 13px; }

.items .item { border-bottom: 1px solid var(--line); padding: 10px 0; }
.items .item:last-child { border-bottom: 0; }
.items .line { display: grid; grid-template-columns: 1fr 1fr 92px; gap: 6px; margin-top: 6px; }
.items .amt { text-align: right; font-weight: 600; padding-top: 4px; }
.total { display: flex; justify-content: space-between; font-size: 20px; font-weight: 700; padding-top: 10px; border-top: 2px solid var(--text); margin-top: 6px; }

.checklist { list-style: none; padding: 0; margin: 0; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 44px; }
.check input { width: 24px; height: 24px; min-height: 0; margin: 0; flex: none; accent-color: var(--accent); }
.checklist li { padding: 4px 0; }
.checklist li.miss::before { content: "✗ "; color: var(--bad); font-weight: 700; }
.checklist li.have::before { content: "✓ "; color: var(--good); font-weight: 700; }

.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 6;
  display: flex; gap: 8px;
}
.fab .btn { box-shadow: 0 4px 14px rgba(0,0,0,.18); }

.suggest { border: 1px solid var(--line); border-radius: 8px; margin: -6px 0 10px; overflow: hidden; }
.suggest button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: var(--card); color: var(--text); padding: 10px; font: inherit; font-size: 14px; }
.suggest button:last-child { border-bottom: 0; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 10;
  max-width: 480px; margin: 0 auto; background: var(--text); color: var(--bg);
  padding: 12px 14px; border-radius: 10px; font-size: 15px; text-align: center;
}
details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
pre.raw { white-space: pre-wrap; font: inherit; font-size: 14px; margin: 8px 0 0; color: var(--muted); }
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.login img { width: 72px; height: 72px; border-radius: 16px; margin-bottom: 4px; }

/* on-screen PDF preview (invoice and sample invoice) */
.pdf-preview { margin-top: 12px; }
.pdf-preview canvas { display: block; width: 100%; height: auto; margin-bottom: 10px; background: #fff; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.18); }

/* ---------------------------------------------------------------- office view (PC, 1000px and wider) */
.office { display: flex; min-height: 100vh; align-items: stretch; }
.onav { flex: none; width: 236px; position: sticky; top: 0; height: 100vh; box-sizing: border-box; display: flex; flex-direction: column; gap: 4px;
  padding: 20px 14px; background: #16245e; color: #fff; }
.onav a { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-radius: 8px; color: #dfe4fb; text-decoration: none; font-size: 15px; }
.onav a:hover { background: #22337a; }
.onav a.on { background: #2e3f97; color: #fff; font-weight: 600; }
.onav .badge { font-size: 12px; background: #fff; color: #16245e; border-radius: 10px; padding: 1px 8px; font-weight: 600; }
.onav .badge.warn { background: #f2a516; color: #1b1300; }
.obrand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.obrand .logo { width: 34px; height: 34px; border-radius: 9px; background: #fff; color: #1f3bb3; display: grid; place-items: center; font-weight: 700; flex: none; }
.obrand b { display: block; font-size: 16px; }
.obrand small { display: block; font-size: 12px; color: #c3cbef; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.onav .onew { justify-content: center; background: #fff; color: #1f3bb3; font-weight: 600; }
.onav .onew:hover { background: #e9edff; }
.oemail { color: #9aa6d8; font-size: 12px; padding: 8px 8px 0; overflow: hidden; text-overflow: ellipsis; }
.ocontent { flex: 1; min-width: 0; }
.ocontent.narrow main { max-width: 760px; }
.ohead { position: sticky; top: 0; z-index: 4; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 16px 28px; background: var(--bg); border-bottom: 1px solid var(--line); }
.ohead h1 { margin: 0; font-size: 24px; flex: 1; }
.ohead .btn { flex: none; text-decoration: none; }
.osearch { width: 320px; max-width: 100%; }
.opage { padding: 20px 28px 48px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 12px 0 16px; }
.tile { display: flex; flex-direction: column; gap: 3px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: inherit; text-decoration: none; }
.tile b { font-size: 26px; }
.tile .lbl, .cfacts .lbl { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.tile.bad { border-color: var(--bad); }
.tile.bad b { color: var(--bad); }
.ocols { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.ocols > .otable-card, .ocols > .cdetail { flex: 999 1 620px; min-width: 0; }
.ocols > .oside, .ocols > .clist { flex: 1 1 300px; min-width: 0; }
.ocard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.ocard h2 { margin: 0 0 10px; font-size: 16px; }
.otable-card { padding: 0; overflow: hidden; }
.ofilters { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.pill { height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.pill span { color: var(--muted); margin-left: 4px; }
.pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.pill.on span { color: inherit; opacity: .8; }
.oscroll { overflow-x: auto; }
.otable { width: 100%; border-collapse: collapse; font-size: 15px; table-layout: fixed; min-width: 760px; }
.otable th { text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 10px 12px; }
.otable td { padding: 11px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.otable tbody tr { cursor: pointer; }
.otable tbody tr:hover td { background: var(--chip); }
.otable a { text-decoration: none; }
.otable .sub { font-size: 13px; color: var(--muted); }
.otable .r, .r { text-align: right; }
.otable .nowrap { white-space: nowrap; }
.oside { display: flex; flex-direction: column; gap: 16px; }
.odrop { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 24px 18px; border: 2px dashed var(--accent); border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 8%, var(--card)); color: var(--accent); text-decoration: none; cursor: pointer; }
.odrop span { color: var(--muted); font-size: 14px; }
.odrop.big { padding: 44px 18px; font-size: 17px; }
.odrop.over { border-style: solid; background: color-mix(in srgb, var(--accent) 16%, var(--card)); }
.att-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.att-row:first-of-type { border-top: 0; }
.att-row i { flex: none; width: 9px; height: 9px; border-radius: 5px; margin-top: 6px; background: var(--warn); }
.att-row i.bad { background: var(--bad); }
.att-row small, .owing small, .crow small { display: block; font-size: 13px; color: var(--muted); }
.aging { display: grid; grid-template-columns: 120px minmax(0, 1fr) 90px; gap: 10px; align-items: center; padding: 5px 0; font-size: 14px; }
.aging b { text-align: right; }
.aging .bar { height: 10px; border-radius: 5px; background: var(--chip); overflow: hidden; }
.aging .bar i { display: block; height: 10px; background: var(--accent); }
.owing { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.clist { padding: 6px 0; }
.crow { display: flex; width: 100%; gap: 12px; align-items: center; padding: 10px 16px; border: 0; border-top: 1px solid var(--line); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.crow:first-child { border-top: 0; }
.crow.on { background: var(--chip); }
.cav { flex: none; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--chip); color: var(--muted); }
.cav.agency { background: color-mix(in srgb, var(--accent) 15%, var(--card)); color: var(--accent); }
.cname { flex: 1; min-width: 0; }
.cfacts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 18px; margin-bottom: 14px; font-size: 15px; }
.cfacts .lbl { display: block; }
.warn { color: var(--warn); }
/* job and invoice side by side */
.office-split { display: flex; align-items: stretch; min-height: 100vh; }
.office-split .pane { flex: 1 1 0; min-width: 0; border-left: 1px solid var(--line); }
.office-split .pane:first-child { border-left: 0; }
.office-split .pane main { max-width: none; padding-bottom: 40px; }
.office-split .top { position: sticky; }
.otable .chip { white-space: normal; }
