:root {
  --ink: #1c2422; --muted: #66706c; --line: #e2ded4; --bg: #f6f4ef; --card: #fff;
  --brand: #1f3a34; --brand-2: #2d564c; --accent: #f2c14e; --accent-ink: #5a4300;
  --ok: #2f7d4f; --warn: #a05a00; --danger: #b3261e; --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 14px rgba(20, 30, 25, .05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
body.noscroll { overflow: hidden; }
a { color: var(--brand-2); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mb { margin-bottom: .8rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.loading, .empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.warn { color: var(--warn); background: #fff6e5; padding: .5rem .7rem; border-radius: 8px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top)); background: var(--brand); color: #fff; }
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.topnav { display: flex; gap: .25rem; align-items: center; flex-wrap: wrap; }
.topnav a, .topnav .linkish { color: #dfe9e5; text-decoration: none; padding: .4rem .65rem; border-radius: 8px; font-size: .95rem; background: none; border: 0; cursor: pointer; font: inherit; }
.topnav a.on, .topnav a:hover, .topnav .linkish:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.container { max-width: 1180px; margin: 0 auto; padding: 1.2rem 1rem 4rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .55rem 1rem; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 40px; }
.btn:hover { border-color: #c9c3b6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: #efc9c6; }
.btn.ghost-light { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .25); }
.btn.small { padding: .3rem .6rem; min-height: 32px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: wait; }
.icon-btn { background: none; border: 0; font-size: 1.2rem; cursor: pointer; padding: .3rem .5rem; color: var(--muted); }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.file-btn { position: relative; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: .3rem .75rem; font: inherit; font-size: .85rem; cursor: pointer; }
.chip:hover { border-color: var(--brand-2); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .6rem; }

/* page headings */
.page-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-h p { margin: 0; }
.crumbs { margin-bottom: .5rem; font-size: .9rem; }
.crumbs a { text-decoration: none; }
.sec-h { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin: .4rem 0 .9rem; flex-wrap: wrap; }
.sec-h h2 { margin: 0; }
.toolbar-row { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.search { flex: 1; min-width: 200px; }

/* status & tags */
.status { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .55rem; border-radius: 99px; background: #eceae4; color: #4a514e; text-transform: uppercase; letter-spacing: .03em; }
.s-active, .s-accepted { background: #dcf1e4; color: #1d5e37; }
.s-planning, .s-draft { background: #e8eef8; color: #2a4a7a; }
.s-quoted, .s-sent, .s-revised { background: #fdf0cf; color: var(--accent-ink); }
.s-onhold { background: #fbe6d6; color: #8a4310; }
.s-completed { background: #e4e9e7; color: #334; }
.s-cancelled, .s-declined { background: #f6dcda; color: #8c1d18; }
.tag { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 6px; background: #efece5; color: #555; }
.tag.share { background: #fdf0cf; color: var(--accent-ink); }
.tag.dir-received { background: #e8eef8; color: #2a4a7a; }
.tag.dir-note { background: #efece5; }
.pill { background: var(--brand); color: #fff; border-radius: 99px; padding: .15rem .6rem; font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* cards & panels */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: .9rem; }
.card, .panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card { padding: 1rem; text-decoration: none; color: inherit; display: block; transition: transform .1s, border-color .1s; }
.card:hover { border-color: #c9c3b6; transform: translateY(-1px); }
.proj-top { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.proj-top h3 { margin: 0 0 .2rem; font-size: 1.05rem; }
.labour { display: flex; justify-content: space-between; align-items: flex-end; gap: .5rem; margin-top: .7rem; padding: .55rem .7rem; background: #f3f6f4; border: 1px solid #d8e3dd; border-radius: 9px; }
.labour span { display: block; }
.labour b { font-size: 1.2rem; color: var(--brand); font-variant-numeric: tabular-nums; }
.labour .small { text-align: right; }
.proj-stats { display: flex; gap: .9rem; margin-top: .7rem; font-size: .85rem; color: var(--muted); flex-wrap: wrap; align-items: center; }
.proj-stats b { color: var(--ink); }
.panel { padding: 1.1rem; margin-bottom: 1rem; }
.panel h2 { margin-bottom: .7rem; }
.panel-foot { margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: .45rem .8rem; margin: 0; }
.kv dt { color: var(--muted); font-size: .9rem; }
.kv dd { margin: 0; word-break: break-word; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.stat span { display: block; font-size: .8rem; color: var(--muted); }
.stat b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.tax-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.tax-row > div { padding: .3rem .2rem; }
.tax-row span { display: block; font-size: .8rem; color: var(--muted); }
.tax-row b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.tax-row > div:last-child b { color: var(--brand); }

/* tabs */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-bottom: 1.1rem; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: .6rem .85rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 600; font-size: .95rem; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--accent); }
.tabs a:hover { color: var(--ink); }

/* segmented control */
.seg { display: inline-flex; background: #ebe8e0; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: .35rem .8rem; border-radius: 8px; font: inherit; font-size: .9rem; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

/* forms */
input, select, textarea { font: inherit; font-size: 16px; padding: .55rem .7rem; border: 1px solid #d2cdc1; border-radius: 9px; background: #fff; color: var(--ink); width: 100%; min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--brand-2); }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span { font-size: .85rem; font-weight: 600; color: #444c49; }
.check { display: flex; gap: .5rem; align-items: center; cursor: pointer; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.form-grid .wide { grid-column: 1 / -1; }
.form-sec { margin: .3rem 0 -.2rem; color: var(--brand); font-size: .9rem; text-transform: uppercase; letter-spacing: .05em; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; }
.form-err { color: var(--danger); background: #fbeceb; padding: .5rem .7rem; border-radius: 8px; font-size: .9rem; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .6rem; margin: .5rem 0 .8rem; }
.range { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .7rem; }

/* materials calc */
.form-grid .calc-manual { display: none; }
.form-grid.manual .calc-manual { display: flex; }
.form-grid.manual .calc-auto { display: none; }
.calc-preview { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; background: #f3f6f4; border: 1px solid #d8e3dd; border-radius: 10px; padding: .7rem; }
.calc-preview span { display: block; font-size: .75rem; color: var(--muted); }
.calc-preview b { font-variant-numeric: tabular-nums; }
.calc-preview .gross b { color: var(--brand); font-size: 1.1rem; }

/* lists */
.list { display: flex; flex-direction: column; gap: .7rem; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; display: flex; gap: 1rem; justify-content: space-between; align-items: flex-start; box-shadow: var(--shadow); }
.item-main { flex: 1; min-width: 0; }
.item-h { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .2rem; }
.note { margin-top: .5rem; white-space: normal; word-break: break-word; }
details.note summary { cursor: pointer; color: #444; }
details.note[open] summary { display: none; }
.row-actions { display: flex; gap: .35rem; flex-shrink: 0; }
.files { list-style: none; padding: 0; margin: .5rem 0 0; display: flex; flex-direction: column; gap: .2rem; }
.files a { text-decoration: none; word-break: break-all; }
.files .x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 .3rem; }
.files .x:hover { color: var(--danger); }

/* tables */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .65rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #faf9f6; }
.table tfoot td { font-weight: 700; background: #faf9f6; border-bottom: 0; }
.table th.num, .table td.num { text-align: right; }
.panel .table th { background: transparent; }

/* timesheet */
.ts-form .ts-grid { display: grid; grid-template-columns: 180px auto 140px; gap: .8rem; align-items: end; }
.ts-form .ts-grid .wide { grid-column: 1 / -1; }
.quick-dates { display: flex; gap: .4rem; padding-bottom: .5rem; }
.ts-form .form-actions { margin-top: .8rem; }
.ts-day { margin-bottom: 1rem; }
.ts-day-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; }
.ts-day-h h3 { margin: 0; }
.ts-item { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; display: grid; grid-template-columns: 70px 1fr auto; gap: .8rem; align-items: start; margin-bottom: .4rem; }
.ts-hours { font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; }

/* photos */
.lib-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: .8rem; gap: .8rem; flex-wrap: wrap; }
.day-group { margin-bottom: 1.4rem; }
.day-h { font-size: .95rem; margin: 0 0 .5rem; padding-bottom: .3rem; border-bottom: 1px solid var(--line); }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.ptile { position: relative; padding: 0; border: 0; background: #ddd; border-radius: 8px; overflow: hidden; aspect-ratio: 1; cursor: zoom-in; }
.ptile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ptime { position: absolute; left: 6px; bottom: 6px; background: rgba(0, 0, 0, .55); color: #fff; font-size: .72rem; padding: .1rem .4rem; border-radius: 5px; }
.plist { display: flex; flex-direction: column; gap: 6px; }
.prow { display: flex; gap: .9rem; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.pthumb { padding: 0; border: 0; width: 96px; height: 96px; border-radius: 7px; overflow: hidden; flex-shrink: 0; cursor: zoom-in; background: #ddd; }
.pthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pmeta { min-width: 0; }
.pdate { font-size: 1rem; }
.pdate span { color: var(--brand-2); font-weight: 600; margin-left: .3rem; }
.pcap { margin-top: .2rem; }
.progress { position: relative; height: 30px; background: #e9e6de; border-radius: 8px; overflow: hidden; margin-bottom: 1rem; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); transition: width .2s; }
.progress span { position: relative; display: block; line-height: 30px; padding: 0 .8rem; font-size: .85rem; font-weight: 600; }

.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(10, 14, 12, .94); color: #fff; display: flex; flex-direction: column; }
.lb-top { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .7rem 1rem; padding-top: max(.7rem, env(safe-area-inset-top)); flex-wrap: wrap; }
.lb-top .muted { color: #aab5b0; }
.lb-actions { display: flex; gap: .4rem; }
.lb-img { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; min-height: 0; padding: 0 3rem; }
.lb-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, .1); color: #fff; border: 0; font-size: 2.2rem; width: 44px; height: 64px; border-radius: 8px; cursor: pointer; }
.lb-nav:disabled { opacity: .2; }
.lb-nav.prev { left: .5rem; } .lb-nav.next { right: .5rem; }
.lb-cap { text-align: center; padding: .7rem 1rem; padding-bottom: max(.7rem, env(safe-area-inset-bottom)); }
.lb-cap .muted { color: #aab5b0; margin-left: .5rem; }

/* sharing */
.switch { display: flex; gap: .8rem; align-items: center; cursor: pointer; margin-bottom: 1rem; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .slider { width: 50px; height: 28px; border-radius: 99px; background: #cfcac0; position: relative; flex-shrink: 0; transition: background .15s; }
.switch .slider::after { content: ''; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: left .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::after { left: 25px; }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); }
.share-link { display: flex; gap: .5rem; margin: .5rem 0 1rem; }
.share-link input { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
.pin-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.pin-row input { max-width: 160px; letter-spacing: .2em; }
.pin-box { background: #fff8e1; border: 1px solid #f0d58a; border-radius: 10px; padding: .9rem 1rem; margin-bottom: 1rem; }
.pin-box .pin { font-size: 1.6rem; letter-spacing: .25em; font-family: ui-monospace, Menlo, monospace; }
.share-h { margin-bottom: 1rem; }
.share-h h1 { margin: .1rem 0 .3rem; }
.share-foot { margin-top: 2rem; text-align: center; }
.pin-input { font-size: 1.6rem; letter-spacing: .4em; text-align: center; }

/* reports */
.report-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.rcard { display: flex; flex-direction: column; gap: .6rem; margin: 0; }
.rcard p { margin: 0; }
.rcard .btn { align-self: flex-start; }
.rcard.feature { border-color: var(--accent); background: linear-gradient(180deg, #fffaf0, #fff); }

/* modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(20, 28, 25, .45); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; overflow-y: auto; }
.modal-card { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; padding: 1.2rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal-card.wide { max-width: 760px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: .8rem; }
.modal-h h2 { margin: 0; }

/* auth */
.auth-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 1.6rem; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.auth-brand { display: flex; gap: .8rem; align-items: center; margin-bottom: 1.2rem; }
.auth-brand h1 { margin: 0; font-size: 1.4rem; }
.auth-brand p { margin: 0; }

.toast { position: fixed; left: 50%; bottom: max(1.2rem, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--brand); color: #fff; padding: .6rem 1.1rem; border-radius: 10px; z-index: 80; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); font-weight: 600; }
.toast.err { background: var(--danger); }

@media (max-width: 700px) {
  .container { padding: .9rem .75rem 4rem; }
  h1 { font-size: 1.35rem; }
  .topnav a, .topnav .linkish { padding: .35rem .45rem; font-size: .88rem; }
  .brand span { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .tax-row, .calc-preview { grid-template-columns: 1fr 1fr; }
  .item { flex-direction: column; }
  .ts-form .ts-grid { grid-template-columns: 1fr 1fr; }
  .ts-form .quick-dates { grid-column: 1 / -1; order: 3; padding: 0; }
  .ts-item { grid-template-columns: 60px 1fr; }
  .ts-item .row-actions { grid-column: 1 / -1; }
  .pgrid { grid-template-columns: repeat(3, 1fr); gap: 3px; }
  .pthumb { width: 76px; height: 76px; }
  .kv { grid-template-columns: 90px 1fr; }
  .table.mat .row-actions { flex-direction: column; }
  .lb-img { padding: 0; }
}
