:root {
  --ink: #10202f;
  --ink-2: #4a5a6a;
  --ink-3: #8a97a4;
  --bg: #f4f1ec;
  --card: #ffffff;
  --line: #e4dfd7;
  --go: #1f9d55;
  --go-dark: #167a41;
  --amber: #e08a00;
  --red: #d64545;
  --blue: #2f6fdb;
  --radius: 16px;
  --tabs-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; -webkit-tap-highlight-color: transparent; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; position: relative; }
main { padding: calc(16px + var(--safe-t)) 16px calc(var(--tabs-h) + 32px + var(--safe-b)); }
a { color: inherit; }
h1 { font-size: 28px; margin: 4px 0 2px; letter-spacing: -0.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 26px 0 10px; font-weight: 700; }
p.sub { margin: 0 0 8px; color: var(--ink-2); }
.loading { padding: 60px 0; text-align: center; color: var(--ink-3); }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

#demo-banner {
  background: #fff4d6; color: #7a5600; font-size: 12px; text-align: center;
  padding: calc(4px + var(--safe-t)) 8px 4px; font-weight: 600;
}
#demo-banner:not([hidden]) + main { padding-top: 16px; }

/* ---- Cards & lists ---- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: 0 1px 0 var(--line), 0 1px 3px rgba(16,32,47,.04); margin-bottom: 10px;
}
.job-card { display: grid; grid-template-columns: 54px 1fr auto; gap: 4px 12px; align-items: center; text-decoration: none; }
.job-card .time { font-weight: 800; font-size: 15px; align-self: start; padding-top: 2px; }
.job-card .title { font-weight: 700; font-size: 17px; }
.job-card .meta { color: var(--ink-2); font-size: 14px; line-height: 1.35; }
.job-card .price { font-weight: 800; font-size: 17px; text-align: right; align-self: start; }
.job-card .actions { grid-column: 2 / 4; margin-top: 8px; }
.job-card.done-state { opacity: .7; }

.row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--card);
  border-bottom: 1px solid var(--line); text-decoration: none; }
.list { border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(16,32,47,.05); }
.list .row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 650; }
.row .s { color: var(--ink-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r { font-weight: 700; text-align: right; white-space: nowrap; }
.chev::after { content: "›"; color: var(--ink-3); font-size: 22px; margin-left: 4px; }

.empty { text-align: center; color: var(--ink-3); padding: 24px 12px; background: var(--card); border-radius: var(--radius); }

/* ---- Buttons ---- */
button, .btn {
  font: inherit; border: 0; cursor: pointer; border-radius: 12px; padding: 12px 16px;
  font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: #e9e5de; color: var(--ink); min-height: 44px;
}
button:active, .btn:active { transform: scale(.98); }
button:disabled { opacity: .5; }
.btn-go { background: var(--go); color: #fff; }
.btn-go:active { background: var(--go-dark); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-ghost { background: transparent; color: var(--blue); padding-left: 4px; padding-right: 4px; }
.btn-danger { background: transparent; color: var(--red); }
.btn-big { width: 100%; font-size: 18px; padding: 18px; border-radius: 14px; letter-spacing: .02em; }
.btn-sm { padding: 8px 14px; min-height: 36px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > * { flex: 1; }

/* ---- Chips / pills ---- */
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: #ece8e1; color: var(--ink-2); }
.pill.go { background: #ddf3e6; color: var(--go-dark); }
.pill.amber { background: #fdefd2; color: #8a5300; }
.pill.red { background: #fbe0e0; color: #a12b2b; }
.pill.blue { background: #e0eafc; color: #234fa0; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 2px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 16px; font-weight: 700; min-height: 44px; }
.chip.on { border-color: var(--ink); background: var(--ink); color: #fff; }

/* ---- Forms ---- */
label.f { display: block; margin: 14px 0 0; }
label.f > span { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
input, textarea, select {
  font: inherit; font-size: 17px; width: 100%; padding: 13px 14px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--card); color: var(--ink); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); }
textarea { min-height: 96px; resize: vertical; }
.money-input { position: relative; }
.money-input::before { content: "£"; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-weight: 700; font-size: 17px; color: var(--ink-2); }
.money-input input { padding-left: 30px; }
.step { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.step h3 { margin: 0 0 10px; font-size: 18px; }
.inline-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.results { margin-top: 8px; }
.results .row { cursor: pointer; border-radius: 0; }
.selected-customer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; border-radius: 12px; background: #eef7f1; border: 2px solid #bfe6cd; }

/* ---- Header bar for inner pages ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin: -4px -4px 8px; }
.topbar a, .topbar button { text-decoration: none; }
.back { font-weight: 700; color: var(--blue); padding: 8px 4px; background: none; min-height: 0; }

/* ---- Job screen ---- */
.job-head { margin-bottom: 14px; }
.job-head .who { font-size: 17px; color: var(--ink-2); margin-top: 4px; }
.job-head .price { font-size: 26px; font-weight: 800; margin-top: 8px; }
.timeline { list-style: none; padding: 0; margin: 12px 0 0; font-size: 14px; color: var(--ink-2); }
.timeline li { padding: 3px 0; }
.timeline b { color: var(--ink); font-variant-numeric: tabular-nums; }
.section { margin-top: 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-head h2 { margin: 0; }
.note { background: var(--card); border-radius: 12px; padding: 12px 14px; margin-top: 8px; white-space: pre-wrap; line-height: 1.4; }
.note time { display: block; font-size: 12px; color: var(--ink-3); margin-bottom: 4px; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #ddd; border: 0; padding: 0; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .tag { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; text-transform: uppercase; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.contact-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 6px; }
.contact-btns a { flex-direction: column; gap: 2px; font-size: 14px; background: var(--card); padding: 12px 6px; }
.contact-btns a span { font-size: 22px; }

/* ---- Money ---- */
.big-number { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot.red { background: var(--red); } .dot.amber { background: var(--amber); } .dot.go { background: var(--go); } .dot.blue { background: var(--blue); }

/* ---- Bottom tabs ---- */
#tabs {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 560px;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(255,255,255,.96); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; z-index: 20;
}
#tabs[hidden] { display: none; }
#tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 700; color: var(--ink-3); text-decoration: none; }
#tabs a .ti { font-size: 20px; filter: grayscale(1); opacity: .6; }
#tabs a.on { color: var(--ink); }
#tabs a.on .ti { filter: none; opacity: 1; }
#tabs .tab-new span { width: 54px; height: 54px; border-radius: 50%; background: var(--go); color: #fff; font-size: 32px; font-weight: 400; display: grid; place-items: center; margin-top: -22px; box-shadow: 0 6px 16px rgba(31,157,85,.35); line-height: 1; }

/* ---- Bottom sheet ---- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(16,32,47,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 10px 16px calc(20px + var(--safe-b)); max-height: 92vh; overflow-y: auto; animation: up .2s ease; }
.sheet .grab { width: 40px; height: 5px; background: #cfc8bd; border-radius: 9px; margin: 0 auto 12px; }
.sheet h3 { font-size: 22px; margin: 4px 0 12px; }
.sheet .opt { width: 100%; justify-content: flex-start; background: var(--card); margin-bottom: 8px; padding: 16px; font-size: 17px; border-radius: 14px; }
.viewer { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; align-items: center; justify-content: center; flex-direction: column; }
.viewer img { max-width: 100%; max-height: 80vh; }
.viewer .btn-row { position: absolute; bottom: calc(20px + var(--safe-b)); left: 16px; right: 16px; }

@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---- Toast ---- */
#toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 20px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 60; max-width: 90%; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Login ---- */
.auth { padding-top: 8vh; }
.logo { font-size: 44px; font-weight: 900; letter-spacing: -0.04em; }
.logo i { font-style: normal; color: var(--go); }
.tagline { color: var(--ink-2); margin: 0 0 28px; }
.error { color: var(--red); font-weight: 600; margin-top: 10px; }

/* ===== v2 additions ===== */
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 11px; font-weight: 800;
  display: inline-grid; place-items: center; margin-top: 6px; flex: none; }
.code { font-family: ui-monospace, Menlo, monospace; letter-spacing: .12em; background: #ece8e1; padding: 2px 8px; border-radius: 6px; }
select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input:disabled, textarea:disabled, select:disabled { background-color: #f1eee9; color: var(--ink-2); }

/* Send sheet */
.send-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.send-grid .btn { flex-direction: column; gap: 2px; font-size: 13px; background: var(--card); padding: 12px 4px; }
.send-grid .btn span { font-size: 22px; }
.send-grid [aria-disabled="true"] { opacity: .35; }

/* Line-item editor */
.line { padding: 10px 0; border-bottom: 1px solid var(--line); }
.line .l-desc { font-weight: 600; }
.line-nums { display: grid; grid-template-columns: 64px auto 1fr auto auto; gap: 8px; align-items: center; margin-top: 6px; }
.line-nums input { padding: 10px; font-size: 16px; }
.line-nums .money-input input { padding-left: 26px; }
.line-nums .l-total { min-width: 70px; text-align: right; font-variant-numeric: tabular-nums; }
.totals { margin-top: 12px; font-variant-numeric: tabular-nums; }
.totals > div { display: flex; justify-content: space-between; padding: 4px 0; color: var(--ink-2); }
.totals .grand { color: var(--ink); font-size: 20px; font-weight: 800; border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 8px; }

/* Signature */
.sig-pad { width: 100%; height: 200px; background: #fff; border: 2px dashed var(--line); border-radius: 12px; touch-action: none; display: block; }
.photo.sig { background: #fff; } .photo.sig img { object-fit: contain; }

/* Customer-facing document */
body.public main { padding-bottom: 40px; }
.preview-bar { display: flex; align-items: center; gap: 10px; background: #fff4d6; color: #7a5600; border-radius: 12px; padding: 4px 12px; margin-bottom: 12px; }
.doc { background: #fff; border-radius: 18px; padding: 22px 20px; box-shadow: 0 2px 12px rgba(16,32,47,.08); }
.doc-head { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 16px; border-bottom: 3px solid var(--ink); }
.doc-biz { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.doc-kind { font-size: 22px; font-weight: 900; letter-spacing: .08em; color: var(--go-dark); }
.doc-to { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.doc-to .small.muted { font-weight: 700; font-size: 11px; letter-spacing: .08em; }
.doc-title { text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 18px; margin: 8px 0 6px; }
.doc-lines { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.doc-lines th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 8px 4px; border-bottom: 1px solid var(--line); }
.doc-lines td { padding: 10px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc-lines th:not(:first-child), .doc-lines td:not(:first-child) { text-align: right; white-space: nowrap; }
.doc-totals { max-width: 280px; margin-left: auto; }
.doc-notes { white-space: pre-wrap; background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.pay-box { background: #eef7f1; border: 2px solid #bfe6cd; border-radius: 14px; padding: 14px; margin-top: 16px; }
.stamp { margin-top: 16px; padding: 14px; border-radius: 14px; background: #ece8e1; font-weight: 700; text-align: center; }
.stamp.go { background: #ddf3e6; color: var(--go-dark); }

@media print {
  @page { margin: 14mm; }
  body, html { background: #fff; }
  #tabs, #demo-banner, #toast, #sheet-root, .no-print { display: none !important; }
  main { padding: 0 !important; }
  #app { max-width: none; }
  .doc { box-shadow: none; padding: 0; }
  .btn, button { display: none !important; }
}
