:root {
  --bg: #f4f4f5; --card: #ffffff; --ink: #1f2126; --muted: #6b7280; --line: #e4e4e7;
  --accent: #c7541a; --accent-ink: #ffffff; --accent-soft: #fbe9df;
  --good: #1f8a4c; --good-soft: #e3f4ea; --warn: #b45309; --warn-soft: #fdf0dc; --bad: #c0262d; --bad-soft: #fbe4e5;
  --radius: 14px; --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1012; --card: #1a1b1f; --ink: #eceef1; --muted: #9ca3af; --line: #2b2d33;
    --accent: #e8743a; --accent-ink: #160a04; --accent-soft: #3a2218; --good: #4cc27f; --good-ink: #07160d; --good-soft: #14281d; --warn: #f0a24b; --warn-soft: #33250f; --bad: #f06a70; --bad-soft: #3a1a1c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1012; --card: #1a1b1f; --ink: #eceef1; --muted: #9ca3af; --line: #2b2d33;
  --accent: #e8743a; --accent-ink: #160a04; --accent-soft: #3a2218; --good: #4cc27f; --good-ink: #07160d; --good-soft: #14281d; --warn: #f0a24b; --warn-soft: #33250f; --bad: #f06a70; --bad-soft: #3a1a1c;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; padding-bottom: calc(var(--tab-h) + var(--safe-b) + 16px); }
a { color: var(--accent); }
h1 { font-size: 24px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 22px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.wrap { max-width: 720px; margin: 0 auto; padding: calc(var(--safe-t) + 16px) 16px 0; }
.topbar { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 14px; min-height: 44px; }
.topbar .back { font-size: 15px; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; padding: 8px 0; }
.card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 16px; margin-bottom: 12px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap-row { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 19px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.v.pos { color: var(--good); } .v.neg { color: var(--bad); }
.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.big-actions .btn { height: 64px; font-size: 16px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--good); border-color: var(--good); color: var(--good-ink, #fff); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn svg { width: 20px; height: 20px; }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }

label.f { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 44px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: end; }
.field, .grid2 { margin-top: 12px; }
.field:first-child, .grid2:first-child, .grid2 > .field, .stack > .field, .stack > .grid2 { margin-top: 0; }
input[type="date"] { min-width: 0; appearance: none; -webkit-appearance: none; }
.row.wrap-row > .btn { flex: 1 1 40%; white-space: nowrap; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; min-height: 0; }

.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-top: 1px solid var(--line); color: inherit; text-decoration: none; min-height: 60px; }
.item:first-child { border-top: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--bg); flex: none; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; font-weight: 700; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.pill.draft { background: var(--bg); color: var(--muted); }
.pill.sent, .pill.review, .pill.reading { background: var(--warn-soft); color: var(--warn); }
.pill.partial { background: var(--accent-soft); color: var(--accent); }
.pill.paid, .pill.ok { background: var(--good-soft); color: var(--good); }
.pill.void, .pill.error, .pill.overdue { background: var(--bad-soft); color: var(--bad); }

.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: transparent; font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); padding: 9px 10px; border-radius: 9px; cursor: pointer; white-space: nowrap; min-height: 38px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--card); border-top: 1px solid var(--line); display: flex; z-index: 20; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--accent); }
.tabbar .dot { position: absolute; margin: -16px 0 0 22px; background: var(--bad); color: #fff; border-radius: 999px; font-size: 10px; padding: 1px 5px; }

.lines .li { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.lines .li .grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.totals { margin-top: 12px; }
.totals .row { justify-content: space-between; padding: 4px 0; }
.totals .grand { font-weight: 800; font-size: 19px; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 6px; }
.preview { width: 100%; max-height: 52vh; object-fit: contain; border-radius: 10px; background: var(--bg); display: block; }
.pdf-frame { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

.pnl-line { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.pnl-line:first-child { border-top: 0; }
.pnl-detail { font-size: 13px; padding: 0 0 8px 8px; }
.pnl-detail .row { justify-content: space-between; padding: 3px 0; }
.pnl-total { display: flex; justify-content: space-between; font-weight: 800; padding: 12px 0 2px; border-top: 2px solid var(--ink); }

.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); }
.sheet h3 { margin: 0 0 12px; font-size: 19px; }
@media (min-width: 760px) { .sheet-bg { align-items: center; } .sheet { border-radius: 18px; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--safe-b) + 14px); background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 60; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); color: #fff; }
.banner { border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 12px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.err { background: var(--bad-soft); color: var(--bad); }
.banner a { color: inherit; font-weight: 700; }
.spin { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: s .8s linear infinite; display: inline-block; }
@keyframes s { to { transform: rotate(360deg); } }

/* --- bottom bar with the center + button --- */
.tabbar .fab { flex: none; width: 58px; height: 58px; margin: -18px 6px 0; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 18px rgba(199, 84, 26, .45); cursor: pointer; align-self: flex-start; }
.tabbar .fab svg { width: 28px; height: 28px; }
.tabbar a { position: relative; }
.tabbar .dot { position: absolute; top: 6px; left: 50%; margin: 0 0 0 6px; }

/* --- tiles: big square buttons --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); grid-auto-flow: column; gap: 10px; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 78px; padding: 10px 6px;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 13px; font-weight: 700; text-decoration: none; cursor: pointer; }
.tile svg { width: 26px; height: 26px; color: var(--accent); }
.tile:active, .item.tap:active, .chip:active { transform: scale(.98); }

/* --- chips --- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; padding: 8px 13px; border-radius: 999px; min-height: 38px; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* --- schedule + today --- */
.item.tap { cursor: pointer; }
.item.done .t { text-decoration: line-through; color: var(--muted); }
.item .when { width: 62px; flex: none; font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; }
.item .when .s { font-weight: 500; }
.item .s.late { color: var(--bad); font-weight: 600; }
.icon-btn.sm { width: 38px; height: 38px; border-radius: 10px; flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.dotmark { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.dotmark.bad { background: var(--bad); } .dotmark.warn { background: var(--warn); }
.card.next { border-left: 4px solid var(--accent); cursor: pointer; }
.next-title { font-size: 20px; font-weight: 800; margin-top: 2px; letter-spacing: -0.01em; }
a.banner { display: block; text-decoration: none; font-weight: 600; }
.quick input { flex: 1; }
.quick .btn { flex: none; }

/* --- job stage stepper --- */
.stepper { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.stepper button { border: 1px solid var(--line); background: var(--card); color: var(--muted); font: inherit; font-size: 12px; font-weight: 700;
  padding: 9px 8px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.stepper button.past { color: var(--ink); background: var(--accent-soft); border-color: transparent; }
.stepper button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill.st-lead { background: var(--bg); color: var(--ink); }
.pill.st-quoting, .pill.st-quote_sent { background: var(--warn-soft); color: var(--warn); }
.pill.st-won, .pill.st-in_progress { background: var(--accent-soft); color: var(--accent); }
.pill.st-done { background: var(--good-soft); color: var(--good); }
.pill.st-lost { background: var(--bad-soft); color: var(--bad); }

.auth { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.auth .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 16px; }
@media (max-width: 400px) { .stats { gap: 6px; } .stat { padding: 10px; } .stat .v { font-size: 15px; } }
