:root {
  --accent: #e8692a;
  --accent-ink: #ffffff;
  --ink: #2b2420;
  --ink-2: #4d443e;
  --muted: #857a72;
  --line: #e8e2dc;
  --card: #ffffff;
  --bg: #f6f3f0;
  --soft: #efeae5;
  --good: #2f8f4e;
  --good-bg: #e5f3e9;
  --warn: #b5541c;
  --warn-bg: #fbe9df;
  --bad: #c0392b;
  --bad-bg: #fbe3e0;
  --info: #3d6f9e;
  --info-bg: #e3edf6;
  --radius: 14px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom);
  --safe-t: env(safe-area-inset-top);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh; overscroll-behavior-y: none;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.boot { min-height: 80vh; display: grid; place-items: center; color: var(--muted); }

/* layout */
.page { max-width: 720px; margin: 0 auto; padding: calc(var(--safe-t) + 14px) 16px calc(var(--tabs-h) + var(--safe-b) + 28px); }
.page.no-tabs { padding-bottom: calc(var(--safe-b) + 110px); }
.head { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 10px; }
.head h1 { font-size: 28px; line-height: 1.15; margin: 0; flex: 1; font-weight: 800; letter-spacing: -.01em; }
.head .back { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); text-decoration: none; font-weight: 600; font-size: 16px; padding: 8px 8px 8px 0; background: none; border: 0; cursor: pointer; }
.head .back svg { width: 22px; height: 22px; stroke-width: 2.4; }
.subhead { color: var(--muted); margin: -4px 0 16px; font-size: 15px; }
.top-actions { display: flex; gap: 8px; }

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(252,250,248,.94); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs[hidden] { display: none; }
.tabs 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; }
.tabs a svg { width: 25px; height: 25px; }
.tabs a.on { color: var(--accent); }

/* cards and lists */
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(60,40,20,.05); margin-bottom: 14px; }
.card.pad { padding: 16px; }
.section-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 22px 4px 8px; display: flex; justify-content: space-between; align-items: center; }
.section-label a, .section-label button { text-transform: none; letter-spacing: 0; color: var(--accent); text-decoration: none; font-size: 15px; font-weight: 600; background: none; border: 0; padding: 0; cursor: pointer; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(60,40,20,.05); margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; text-decoration: none; border-bottom: 1px solid var(--line); min-height: 58px; background: var(--card); width: 100%; border-left: 0; border-right: 0; border-top: 0; text-align: left; cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--soft); }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.row .end { text-align: right; flex-shrink: 0; }
.row .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.row .chev { color: #c9c0b8; width: 18px; height: 18px; flex-shrink: 0; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; font-size: 17px; }

.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--soft); color: var(--ink-2); display: grid; place-items: center; font-weight: 700; font-size: 15px; flex-shrink: 0; }

/* badges */
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 20px; background: var(--soft); color: var(--ink-2); white-space: nowrap; }
.badge.draft { background: var(--soft); color: var(--muted); }
.badge.sent { background: var(--info-bg); color: var(--info); }
.badge.paid, .badge.accepted { background: var(--good-bg); color: var(--good); }
.badge.overdue, .badge.declined, .badge.void { background: var(--bad-bg); color: var(--bad); }
.badge.invoiced { background: var(--good-bg); color: var(--good); }
.badge.partial { background: var(--warn-bg); color: var(--warn); }

/* home stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px; text-decoration: none; box-shadow: 0 1px 2px rgba(60,40,20,.05); display: block; }
.stat .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 23px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .n { font-size: 13px; color: var(--muted); margin-top: 1px; }
.stat.alert .v { color: var(--bad); }
.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 4px; }
.biz-mark { display: flex; align-items: center; gap: 12px; margin: 4px 0 18px; }
.biz-mark img { max-height: 46px; max-width: 170px; }
.biz-mark .hello { color: var(--muted); font-size: 15px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 700; font-size: 16px;
  text-decoration: none; cursor: pointer; color: var(--ink); white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 20px; height: 20px; stroke-width: 2; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 15px; border-radius: 10px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: 0; background: var(--card); display: grid; place-items: center; color: var(--accent); cursor: pointer; box-shadow: 0 1px 2px rgba(60,40,20,.06); text-decoration: none; }
.icon-btn.accent { background: var(--accent); color: #fff; }
.icon-btn svg { stroke-width: 2.2; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-grid .wide { grid-column: 1 / -1; }

.contact-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 4px 0 14px; }
.contact-actions a, .contact-actions button { display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--card); border-radius: 12px; padding: 10px 4px; text-decoration: none; font-size: 12px; font-weight: 600; color: var(--accent); border: 0; cursor: pointer; box-shadow: 0 1px 2px rgba(60,40,20,.05); }
.contact-actions .off { color: #cfc6be; pointer-events: none; }

/* forms */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 13px; margin-top: 5px; }
.input, textarea.input, select.input {
  width: 100%; min-height: 48px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px; background: #fff;
  font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
textarea.input { min-height: 84px; resize: vertical; line-height: 1.4; }
select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23857a72' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; padding-right: 38px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.two { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; }
.two > * { min-width: 0; }
input[type=date].input { min-width: 0; display: block; line-height: 24px; }
.search { position: relative; margin-bottom: 12px; }
.search svg { position: absolute; left: 12px; top: 13px; width: 20px; height: 20px; color: var(--muted); }
.search .input { padding-left: 40px; background: var(--card); border-color: transparent; box-shadow: 0 1px 2px rgba(60,40,20,.05); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; border: 1px solid var(--line); background: var(--card); padding: 7px 14px; border-radius: 20px; font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.seg { display: flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 4px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.err { background: var(--bad-bg); color: var(--bad); padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 15px; }
.note { background: var(--soft); color: var(--ink-2); padding: 12px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 14px; }

/* editor */
.picker { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; background: var(--card); border: 0; border-radius: var(--radius); text-align: left; cursor: pointer; box-shadow: 0 1px 2px rgba(60,40,20,.05); margin-bottom: 12px; }
.picker .main { flex: 1; min-width: 0; }
.picker .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.picker .v { font-weight: 600; font-size: 17px; }
.picker .v.placeholder { color: var(--accent); }
.line { background: var(--card); border-radius: var(--radius); padding: 12px 12px 10px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(60,40,20,.05); }
.line textarea.input { min-height: 48px; height: 48px; margin-bottom: 8px; }
.line .nums { display: grid; grid-template-columns: 76px 1fr 1fr; gap: 8px; align-items: end; }
.line .nums label span { font-size: 12px; color: var(--muted); font-weight: 600; display: block; margin-bottom: 3px; }
.line .nums .input { min-height: 44px; padding: 9px 10px; }
.line .amount { text-align: right; font-weight: 800; font-size: 17px; padding-bottom: 10px; font-variant-numeric: tabular-nums; }
.line .foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.line .foot .seg { flex: 1; }
.line .del { border: 0; background: none; color: var(--muted); padding: 6px; cursor: pointer; }
.line .del svg { width: 20px; height: 20px; }
.line .taxrow { margin-top: 8px; }
.add-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: rgba(252,250,248,.96); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 12px 16px calc(12px + var(--safe-b));
}
.savebar .in { max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 14px; }
.savebar .tot { flex: 1; }
.savebar .tot .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.savebar .tot .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.savebar .btn { min-width: 130px; }

/* doc view */
.doc-hero { background: var(--card); border-radius: var(--radius); padding: 18px 16px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(60,40,20,.05); }
.doc-hero .who { font-size: 20px; font-weight: 800; }
.doc-hero .job { color: var(--muted); margin-top: 2px; }
.doc-hero .money { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 16px; }
.doc-hero .money .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.doc-hero .money .v { font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.doc-hero .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; color: var(--muted); font-size: 14px; }
.viewed { display: flex; align-items: center; gap: 6px; color: var(--good); font-size: 14px; font-weight: 600; margin-top: 10px; }
.viewed svg { width: 18px; height: 18px; }
.send-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.send-actions button, .send-actions a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; min-height: 72px; border-radius: 14px; border: 0; background: var(--card); color: var(--ink); font-weight: 700; font-size: 14px; cursor: pointer; text-decoration: none; box-shadow: 0 1px 2px rgba(60,40,20,.05); }
.send-actions .primary { background: var(--accent); color: #fff; }
.send-actions svg { width: 24px; height: 24px; }
.lines-view .lv { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.lines-view .lv:last-child { border-bottom: 0; }
.lines-view .lv .d { flex: 1; min-width: 0; }
.lines-view .lv .dt { white-space: pre-wrap; }
.lines-view .lv .q { color: var(--muted); font-size: 14px; margin-top: 2px; }
.lines-view .lv .a { font-weight: 700; font-variant-numeric: tabular-nums; }
.totline { display: flex; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.totline.b { font-weight: 800; font-size: 17px; }
.totline.m { color: var(--muted); font-size: 15px; }

/* sheets */
.sheet-back { position: fixed; inset: 0; background: rgba(30,20,10,.35); z-index: 40; animation: fade .18s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--bg); border-radius: 18px 18px 0 0;
  max-height: 92vh; display: flex; flex-direction: column; animation: up .22s cubic-bezier(.2,.8,.2,1);
  max-width: 720px; margin: 0 auto; padding-bottom: var(--safe-b);
}
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: #d6cdc5; margin: 8px auto 2px; flex-shrink: 0; }
.sheet .sh { display: flex; align-items: center; padding: 6px 16px 10px; gap: 10px; flex-shrink: 0; }
.sheet .sh h2 { flex: 1; margin: 0; font-size: 19px; font-weight: 800; }
.sheet .sh button { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 16px; cursor: pointer; padding: 6px 0; }
.sheet .sb { overflow-y: auto; padding: 4px 16px 20px; -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } }

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

/* login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; max-width: 400px; margin: 0 auto; padding: 24px 20px calc(24px + var(--safe-b)); }
.login .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.login .logo img { width: 48px; height: 48px; border-radius: 12px; }
.login .logo b { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.login h1 { font-size: 22px; margin: 0 0 6px; }
.login p { color: var(--muted); margin: 0 0 22px; }

/* import */
.map-grid { display: grid; grid-template-columns: 110px 1fr; gap: 8px 10px; align-items: center; margin-bottom: 14px; }
.map-grid label { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.map-grid .input { min-height: 42px; padding: 8px 34px 8px 10px; font-size: 15px; }
.preview { overflow-x: auto; background: var(--card); border-radius: 12px; margin-bottom: 14px; }
.preview table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.preview th, .preview td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.preview th { background: var(--soft); font-weight: 700; }

.logo-box { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.logo-box .pv { width: 150px; height: 70px; border-radius: 10px; background: #fff; border: 1px dashed var(--line); display: grid; place-items: center; overflow: hidden; }
.logo-box .pv img { max-width: 140px; max-height: 60px; }
.color-dot { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); padding: 0; cursor: pointer; }

@media (min-width: 700px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .head h1 { font-size: 32px; }
}
