/* Self billing styles. Mobile first; wider screens are tweaked at the end of each section.
   1. Tokens and base   2. Top bar and tab bar   3. Layout   4. Buttons   5. Forms
   6. Lists and rows    7. Cards, stats, pills   8. Quick invoice wizard   9. Invoice page   10. Login */

/* ---------- 1. Tokens and base ---------- */
:root {
    --bg: #f4f6f5;
    --surface: #ffffff;
    --surface-2: #f0f4f3;
    --text: #17201d;
    --muted: #61706b;
    --faint: #8a9893;
    --border: #e3e8e6;
    --primary: #0f766e;
    --primary-hover: #115e59;
    --primary-soft: #e6f4f1;
    --primary-ink: #0b4f49;
    --ok: #047857;
    --ok-soft: #e7f6ef;
    --warn: #a15c07;
    --warn-soft: #fdf3e2;
    --danger: #c42b2b;
    --danger-soft: #fdeeee;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 22, .04), 0 4px 16px rgba(16, 24, 22, .04);
    --tabbar-h: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); }

a { color: var(--primary); text-underline-offset: 2px; }
h1 { font-size: 1.6rem; line-height: 1.2; letter-spacing: -.01em; margin: 0 0 .75rem; font-weight: 650; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
small { font-size: .85rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.text-ok { color: var(--ok); }
.icon { flex: none; }
:focus-visible { outline: 3px solid rgba(15, 118, 110, .35); outline-offset: 2px; }

/* Shown only when JavaScript runs (html.js is set in the page head) */
html:not(.js) .js-only { display: none !important; }

/* ---------- 2. Top bar and tab bar ---------- */
.topbar { background: var(--primary); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 960px; margin: 0 auto; padding: 0 12px 0 16px; height: 56px; display: flex; align-items: center; gap: 8px; }
.brand { color: #fff; font-weight: 650; text-decoration: none; display: inline-flex; align-items: center; gap: 10px; font-size: 1.05rem; margin-right: auto; }
.brand-badge { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 9px; background: #fff; }
.brand-badge img { display: block; }
.brand-badge-lg { width: 52px; height: 52px; border-radius: 15px; box-shadow: var(--shadow); }
.topbar-title { font-weight: 600; margin-right: auto; }
.topbar .topnav, .topbar .topbar-cta { display: none; }
.topbar-logout { margin: 0; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; border: 0; background: none; color: inherit; cursor: pointer; }
.icon-btn.on-dark { color: #e6fffb; }
.icon-btn.on-dark:hover { background: rgba(255, 255, 255, .14); color: #fff; }

.test-banner { background: #fef3c7; color: #78350f; font-size: .85rem; text-align: center; padding: 6px 16px; }
.test-banner strong { margin-right: 4px; }

.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; align-items: center;
    height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
    background: rgba(255, 255, 255, .96); border-top: 1px solid var(--border);
    backdrop-filter: saturate(1.4) blur(10px);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; font-weight: 500; color: var(--faint); text-decoration: none; padding: 6px 0; }
.tabbar a[aria-current] { color: var(--primary); }
.tabbar-new span { display: flex; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 18px; background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(15, 118, 110, .35); }
.tabbar-new .icon { width: 26px; height: 26px; }
/* Order: Invoices, +, Contractors, Settings - the + is second so it sits under the thumb */

@media (min-width: 760px) {
    body.has-tabbar { padding-bottom: 0; }
    .tabbar { display: none; }
    .topbar .topnav { display: flex; gap: 4px; margin-right: 8px; }
    .topnav a { color: #d7f5ef; text-decoration: none; padding: 8px 12px; border-radius: 10px; font-weight: 500; font-size: .95rem; }
    .topnav a:hover, .topnav a[aria-current] { background: rgba(255, 255, 255, .14); color: #fff; }
    .topbar .topbar-cta { display: inline-flex; }
}

/* ---------- 3. Layout ---------- */
.container { max-width: 760px; margin: 0 auto; padding: 20px 16px 40px; }
.container-focus { max-width: 520px; padding-top: 12px; }
.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.section-title { margin: 28px auto 10px; max-width: 560px; }
.stack > * + * { margin-top: 16px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 12px -6px; padding: 6px; border: 0; background: none; color: var(--muted); font: inherit; font-size: .95rem; text-decoration: none; cursor: pointer; border-radius: 8px; }
.back-link:hover { color: var(--text); }
.danger-zone { margin: 24px auto 0; text-align: center; }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: .95rem; border: 1px solid transparent; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-success { background: var(--ok-soft); color: #065f46; border-color: #c4e9d8; }
.alert-error { background: var(--danger-soft); color: #9b1c1c; border-color: #f6cfcf; }
.alert-info { background: var(--primary-soft); color: var(--primary-ink); border-color: #c9e7e1; }

.empty { text-align: center; background: var(--surface); border: 1px dashed #cfd8d5; border-radius: var(--radius); padding: 40px 24px; }
.empty h2 { font-size: 1.2rem; }
.empty p { color: var(--muted); max-width: 34ch; margin: 0 auto 20px; }

@media (min-width: 760px) {
    .container { padding-top: 32px; }
}

/* ---------- 4. Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 18px; border-radius: 12px;
    font: inherit; font-weight: 600; font-size: .95rem; text-decoration: none; white-space: nowrap;
    background: var(--surface); color: var(--text); border: 1px solid var(--border); cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: #cdd6d3; background: #fafbfb; }
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-light { background: #fff; border-color: #fff; color: var(--primary-ink); min-height: 38px; padding: 0 14px; }
.btn-light:hover { background: var(--primary-soft); border-color: var(--primary-soft); }
.btn-ghost { background: none; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(0, 0, 0, .04); border-color: transparent; color: var(--text); }
.btn-danger-text, .btn-danger-text:hover { color: var(--danger); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: .88rem; border-radius: 10px; }
.btn-lg { min-height: 54px; font-size: 1.05rem; border-radius: 14px; }
.btn-block { display: flex; width: 100%; }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn-row form { margin: 0; }
.btn-stack { display: grid; gap: 10px; margin-top: 24px; }

/* ---------- 5. Forms ---------- */
label { font-weight: 600; font-size: .92rem; }
.field label { display: block; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: .85rem; margin: -2px 0 8px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], input:not([type]), textarea, select {
    width: 100%; min-height: 48px; padding: 10px 14px;
    font: inherit; font-size: 16px; color: var(--text);   /* 16px stops phones zooming in */
    background: var(--surface); border: 1px solid #d5ddda; border-radius: 12px;
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 88px; }
::placeholder { color: #b3bdb9; opacity: 1; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(15, 118, 110, .12); }
.has-error input, .has-error textarea, input[aria-invalid] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .88rem; margin: 6px 0 0; }
.field-error:empty { display: none; }
.input-prefix { position: relative; }
.input-prefix span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-prefix input { padding-left: 30px; }
.field-inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-inline label { margin: 0; }
.field-inline input { width: auto; min-width: 170px; }

.check { display: flex; align-items: center; gap: 12px; padding: 12px 0; font-weight: 500; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; margin: 0; }
.check small { display: block; color: var(--muted); font-weight: 400; }
.check:has(input:disabled) { opacity: .55; cursor: default; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-weight: 600; font-size: .92rem; padding: 0; margin-bottom: 2px; }

.search { position: relative; margin-bottom: 12px; }
.search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input { padding-left: 42px; }

.disclosure { margin-top: 12px; }
.disclosure summary { display: inline-flex; align-items: center; gap: 6px; color: var(--primary); font-weight: 600; cursor: pointer; list-style: none; padding: 8px 0; }
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure[open] summary { margin-bottom: 8px; }

/* ---------- 6. Lists and rows ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list > li + li { border-top: 1px solid var(--border); }
.row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: inherit; text-decoration: none; min-height: 68px; }
a.row:hover { background: #fafbfb; }
.row.is-archived { opacity: .6; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row-end small { color: var(--muted); }
.amount { font-variant-numeric: tabular-nums; font-weight: 650; }
.avatar { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-ink); font-weight: 650; font-size: .85rem; letter-spacing: .02em; }
.avatar-lg { width: 52px; height: 52px; font-size: 1rem; }

.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.plain-list form { margin: 0; }

/* ---------- 7. Cards, stats, pills ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: .85rem; margin: 0 0 2px; }
.stat-value { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; margin: 0; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--faint); font-size: .8rem; margin: 0; }
.stat:first-child { background: var(--primary); border-color: var(--primary); color: #fff; }
.stat:first-child .stat-label, .stat:first-child .stat-sub { color: #c8efe8; }

.segmented { display: flex; gap: 4px; padding: 4px; background: #e8eeec; border-radius: 12px; margin-bottom: 14px; }
.segmented a { flex: 1; text-align: center; padding: 8px 0; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: .92rem; text-decoration: none; }
.segmented a[aria-current] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 650; white-space: nowrap; }
.pill-unpaid { background: var(--warn-soft); color: var(--warn); }
.pill-paid { background: var(--ok-soft); color: var(--ok); }
.pill-cancelled { background: #eef0ef; color: var(--muted); }

/* ---------- 8. Quick invoice wizard ---------- */
.progress { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 20px; }
.progress span { height: 4px; border-radius: 4px; background: #dbe3e0; transition: background .25s; }
html:not(.js) .progress { display: none; }
.wizard[data-current="1"] .progress span:nth-child(-n+1),
.wizard[data-current="2"] .progress span:nth-child(-n+2),
.wizard[data-current="3"] .progress span:nth-child(-n+3) { background: var(--primary); }

.step-q { font-size: 1.75rem; margin: 4px 0 20px; }
.step-q label { font: inherit; }
html:not(.js) .step + .step { margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--border); }
html.js .wizard .step { display: none; }
html.js .wizard .step.is-active { display: block; animation: step-in .22s ease-out; }
html.js .wizard .step.is-back { animation-name: step-back; }
@keyframes step-in { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
@keyframes step-back { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { html.js .wizard .step.is-active { animation: none; } }
html:not(.js) .back-link[data-back], html:not(.js) .step-next { display: none; }

.pick-list { display: grid; gap: 10px; }
.pick { display: flex; align-items: center; gap: 14px; padding: 14px 16px; min-height: 72px; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); cursor: pointer; font-weight: 400; transition: border-color .15s, background .15s, transform .05s; }
.pick:hover { border-color: #c9d4d0; }
.pick:active { transform: scale(.99); }
.pick:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick:has(input:focus-visible) { outline: 3px solid rgba(15, 118, 110, .35); outline-offset: 2px; }
.pick > .icon { color: var(--faint); }
.add-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 16px; font-weight: 600; text-decoration: none; }

/* Who the invoice is for: stays pinned under the top bar while the step scrolls */
.wizard .who {
    display: flex; align-items: center; gap: 12px; padding: 10px 14px; margin-bottom: 20px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    position: sticky; top: 64px; z-index: 10; box-shadow: 0 6px 16px rgba(16, 24, 22, .06);
}
.wizard .who .avatar { width: 42px; height: 42px; font-size: .85rem; }

/* Rate and invoice date side by side, identical boxes */
.rate-date { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-bottom: 24px; }
.rate-date input {
    display: block; width: 100%; min-width: 0; max-width: 100%; height: 56px; margin: 0; padding: 0 14px;
    font: inherit; font-size: 1.15rem; font-weight: 600; line-height: 54px; font-variant-numeric: tabular-nums;
    text-align: left; color: var(--text); background: var(--surface);
}
/* iPhones draw date boxes their own way (taller, centred, wider): switch that off */
.rate-date input[type=date] { -webkit-appearance: none; appearance: none; }
.rate-date input[type=date]::-webkit-date-and-time-value { text-align: left; margin: 0; }
.rate-date input[type=date]::-webkit-calendar-picker-indicator { margin: 0; opacity: .6; }
.rate-date .input-prefix span { font-size: 1.15rem; }
.rate-date .input-prefix input { padding-left: 32px; }

/* While the phone keyboard is open, leave room to scroll the hours up above it */
body.keyboard-room .wizard { padding-bottom: 60vh; }
.who strong { display: block; font-size: 1.05rem; }
.who small { color: var(--muted); font-size: .95rem; }

.hours { display: flex; align-items: center; gap: 12px; }
.hours input { flex: 1; min-width: 0; height: 88px; text-align: center; font-size: 2.75rem; font-weight: 700; letter-spacing: -.02em; border-radius: 18px; font-variant-numeric: tabular-nums; }
.hours-btn { flex: none; width: 60px; height: 60px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.hours-btn:hover { background: var(--surface-2); }
.hours-btn:active { transform: scale(.94); }
.hours-total { text-align: center; color: var(--muted); font-size: 1.05rem; margin: 14px 0 0; min-height: 1.5em; }
.hours-total strong { color: var(--text); }
.step-next { margin-top: 28px; }

.summary { margin: 0 0 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 16px; }
.summary > div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.summary > div:last-child { border-bottom: 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 600; text-align: right; }
.summary-total dt { color: var(--text); font-weight: 600; align-self: center; }
.summary-total dd { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.wizard .field-inline { padding: 4px 0 8px; }
.send-to { margin: 12px 0 24px; padding-top: 12px; border-top: 1px solid var(--border); }
/* Keep the send button in reach on short phone screens */
.wizard [data-submit] { position: sticky; bottom: calc(12px + var(--safe-bottom)); box-shadow: 0 8px 24px rgba(15, 118, 110, .28); }

/* ---------- 9. Invoice page ---------- */
.invoice-card .summary { border: 0; padding: 0; margin: 16px 0 0; background: none; }
.invoice-head { display: flex; align-items: center; gap: 14px; }
.invoice-head h1 { font-size: 1.3rem; margin: 0; }
.status-line { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; }
.status-line.ok { color: var(--ok); }
.status-line.muted { color: var(--muted); }
.paid-form { display: grid; gap: 4px; }
.paid-form .btn { margin-top: 8px; }
.email-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.email-row:last-child { border-bottom: 0; }
.email-row form { margin: 0; }

.done { text-align: center; padding: 28px 8px 36px; animation: step-in .3s ease-out; }
.done-tick { width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: flex; align-items: center; justify-content: center; animation: pop .4s cubic-bezier(.2, 1.4, .4, 1); }
.done-tick .icon { width: 44px; height: 44px; stroke-width: 2.2; }
.done h1 { margin-bottom: 6px; }
.done-actions { display: grid; gap: 8px; max-width: 320px; margin: 24px auto 0; }
.done + .back-link { display: none; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- 10. Login ---------- */
.auth { max-width: 400px; margin: 6vh auto 0; }
.auth-brand { margin-bottom: 20px; }
.auth h1 { margin-bottom: 4px; }
.auth .muted { margin-bottom: 24px; }
