/* Link-Up Billing. Mobile first: bottom tab bar on phones, top tabs on laptops. */
:root {
  --bg: #EDF0F4; --surface: #FFFFFF; --sunk: #F5F7FA; --ink: #141B26; --muted: #5A6577; --line: #D5DBE4;
  --accent: #1E3A5F; --accent-ink: #FFFFFF; --accent-soft: #E2E9F3;
  --ok: #1C7A4E; --ok-soft: #DFF2E8; --warn: #9A6B12; --warn-soft: #F8EED6; --bad: #B42318; --bad-soft: #FBE4E1;
  --shadow: 0 1px 2px rgba(20,27,38,.06), 0 8px 24px rgba(20,27,38,.08);
  --f-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-num: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F141B; --surface: #171E28; --sunk: #121821; --ink: #E5EAF1; --muted: #97A2B3; --line: #2A3443;
    --accent: #7FA6D6; --accent-ink: #0B1420; --accent-soft: #1E2E44;
    --ok: #5BC48F; --ok-soft: #173326; --warn: #E2B45C; --warn-soft: #3A2F17; --bad: #F07A6E; --bad-soft: #3B1D1A;
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-ui); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
.up { text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.lbl2 { margin: 0; font-size: 12.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 160px; }
.boot { padding: 40px max(16px, env(safe-area-inset-left)); text-align: center; color: var(--muted); }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 600; min-height: 44px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { width: 100%; padding: 13px; font-size: 16px; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 4px 0; min-height: 0; text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.x { border: 0; background: transparent; color: var(--muted); cursor: pointer; min-width: 36px; height: 36px; border-radius: 8px; font-size: 18px; }
.x:hover { color: var(--bad); background: var(--bad-soft); }
.x.arm { color: var(--bad); font-size: 13px; font-weight: 700; }

/* fields */
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld label { font-size: 11.5px; color: var(--muted); letter-spacing: .05em; text-transform: uppercase; font-weight: 600; }
.fld input, .fld select, .fld textarea, .row select, .row input {
  width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--sunk); min-height: 44px; }
.row select, .row input { width: auto; }
.row input.grow { width: auto; }
.fld input:focus, .fld select:focus, .fld textarea:focus { background: var(--surface); border-color: var(--accent); outline: none; }
.fld textarea { resize: vertical; min-height: 64px; }
.hint { font-size: 12px; font-weight: 600; min-height: 1em; }
.hint.ok { color: var(--ok); } .hint.bad { color: var(--bad); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; min-height: 36px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.err { color: var(--bad); background: var(--bad-soft); padding: 10px 12px; border-radius: 9px; margin: 0; }
.full { grid-column: 1 / -1; }
.grid2f { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
@media (max-width: 560px) { .grid2f { grid-template-columns: minmax(0, 1fr); } }
.search { margin: 10px 0; }

/* sign in / onboarding */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.authcard { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 28px 22px; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; }
.authcard.wide { max-width: 620px; }
.authcard h1 { font-size: 24px; }
.authcard p { margin: 0; }
.logo-mark { width: 48px; height: 48px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 26px; font-weight: 700; }
.codeinput { font-size: 24px !important; letter-spacing: .3em; text-align: center; }

/* app shell */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; padding-top: env(safe-area-inset-top); }
.topin { max-width: 1380px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); }
.biz select { border: 0; background: transparent; font-weight: 700; font-size: 16px; padding: 8px 4px; max-width: 46vw; min-height: 44px; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab { border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 9px; padding: 8px 12px; display: flex; align-items: center; gap: 7px; font-weight: 500; min-height: 44px; }
.tab svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab:hover { color: var(--ink); }
.tab.on { background: var(--accent-soft); color: var(--accent); }
.tab.new { color: var(--accent); }
.offline { background: var(--warn-soft); color: var(--warn); text-align: center; padding: 8px 16px; font-weight: 600; font-size: 13.5px; }
.main { max-width: 1380px; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-right)) 40px max(16px, env(safe-area-inset-left)); }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }

@media (max-width: 760px) {
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; background: var(--surface); border-top: 1px solid var(--line);
    justify-content: space-around; padding: 4px max(6px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); z-index: 20; }
  .tab { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; }
  .tab.new svg { background: var(--accent); color: var(--accent-ink); border-radius: 50%; padding: 3px; width: 26px; height: 26px; }
  .main { padding-bottom: calc(var(--nav-h) + 30px + env(safe-area-inset-bottom)); }
  .biz select { max-width: 90vw; }
  h1 { font-size: 20px; }
}

/* cards & tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card.flat { padding: 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat small { display: block; color: var(--muted); font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; font-weight: 600; }
.stat b { font-family: var(--f-num); font-size: 18px; font-weight: 500; overflow-wrap: anywhere; }
.stat.warn b { color: var(--warn); }
.cards { display: flex; flex-direction: column; gap: 8px; }
.invcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; display: flex; align-items: center; gap: 10px; padding-right: 12px; }
.invmain { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; cursor: pointer; padding: 12px 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; border-radius: 12px; }
.invmain:hover { background: var(--sunk); }
.invno { font-size: 13px; color: var(--muted); }
.invdate { font-size: 13px; color: var(--muted); text-align: right; }
.invcust { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; grid-row: 2; }
.invamt { font-weight: 600; text-align: right; grid-row: 2; grid-column: 2; }
.invcard.cancelled .invcust, .invcard.cancelled .invamt { text-decoration: line-through; color: var(--muted); }
.pill { border: 1px solid var(--line); background: var(--sunk); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
button.pill { cursor: pointer; min-height: 32px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.arm { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
#edStatus { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 26px 10px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); margin-bottom: 3px; }
.tablewrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; min-width: 720px; }
table.list th { font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 600; text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list .r { text-align: right; }
table.list .c { text-align: center; }
table.list input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
table.list input, table.list select { padding: 7px 8px; border: 1px solid transparent; border-radius: 7px; background: transparent; width: 100%; min-height: 38px; }
table.list input.r { text-align: right; }
table.list input:hover, table.list select:hover { border-color: var(--line); }
table.list input:focus, table.list select:focus { border-color: var(--accent); background: var(--surface); outline: none; }
td.low input { color: var(--bad); font-weight: 700; }
.partform { display: grid; grid-template-columns: minmax(0, 2.2fr) repeat(5, minmax(0, 1fr)) auto auto; gap: 8px; align-items: end; flex-direction: unset; }
@media (max-width: 900px) { .partform { grid-template-columns: repeat(2, minmax(0, 1fr)); } .partform .wide { grid-column: 1 / -1; } .partform .btn { grid-column: 1 / -1; } }

/* editor */
.desk { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 18px; align-items: start; }
.form { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
details.sec { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
details.sec > summary { list-style: none; cursor: pointer; padding: 13px 16px; display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 48px; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary h2 { white-space: nowrap; margin: 0; font-size: 12.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
details.sec > summary .sumr { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; margin-left: auto; }
details.sec > summary::after { content: "▾"; color: var(--muted); }
details.sec:not([open]) > summary::after { transform: rotate(-90deg); }
.secb { padding: 2px 16px 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
@media (max-width: 560px) { .secb { grid-template-columns: minmax(0, 1fr); } }
.items { display: flex; flex-direction: column; gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--sunk);
  display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, .9fr) minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, .9fr) minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.item .desc { grid-column: 1 / -1; }
.item .fld input, .item .fld select { background: var(--surface); }
.item .amt { grid-column: 1 / -1; font-family: var(--f-num); font-size: 12.5px; color: var(--muted); text-align: right; }
@media (max-width: 700px) {
  .item { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .item .x { grid-column: 3; justify-self: end; }
}
.taxmode { padding: 9px 12px; border-radius: 9px; background: var(--accent-soft); font-size: 13.5px; }
.totals { display: grid; gap: 4px; font-size: 14px; }
.totals div { display: flex; justify-content: space-between; color: var(--muted); }
.totals .grand { color: var(--ink); font-weight: 700; font-size: 20px; border-top: 1px dashed var(--line); padding-top: 8px; }
.prevcol { position: sticky; top: calc(env(safe-area-inset-top) + 74px); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.scroller { overflow: auto; max-height: calc(100vh - 170px); border-radius: 6px; box-shadow: var(--shadow); }
#previewToggle { display: none; }
@media (max-width: 1000px) {
  .desk { grid-template-columns: minmax(0, 1fr); }
  #previewToggle { display: inline-block; }
  .prevcol { display: none; position: static; }
  .desk.show-preview .prevcol { display: flex; }
  .desk.show-preview .form { display: none; }
  .scroller { max-height: none; }
}

/* invoice sheet (paper: always light) */
.sheet { background: #FFFFFF; color: #111111; min-width: 640px; padding: 24px 24px 28px; font-size: 10.5px; line-height: 1.38; font-family: var(--f-ui); }
.sheet .title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; gap: 8px; }
.sheet .title b { font-size: 16px; letter-spacing: .14em; flex: 1; text-align: center; }
.sheet .title i { width: 130px; font-style: normal; }
.sheet .title span { width: 130px; text-align: right; font-size: 9px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.sheet .cx { color: #B42318; font-weight: 700; font-style: normal; }
.sheet .box { border: 1px solid #9AA3AF; }
.sheet .g2 { display: grid; grid-template-columns: 1.45fr 1fr; }
.sheet .g2 > div { padding: 8px 10px; }
.sheet .g2 > div + div { border-left: 1px solid #9AA3AF; }
.sheet .mt { margin-top: -1px; }
.sheet .seller { display: flex; gap: 10px; }
.sheet .seller img { max-height: 46px; max-width: 90px; object-fit: contain; }
.sheet .nm { font-size: 13.5px; font-weight: 700; }
.sheet .missing { color: #B42318; font-weight: 700; }
.sheet .kv { display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; margin: 0; }
.sheet .kv dt { color: #4B5563; }
.sheet .kv dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.sheet .lbl { font-size: 8.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #1E3A5F; margin-bottom: 2px; }
.sheet table { width: 100%; border-collapse: collapse; }
.sheet table.it th { background: #1E3A5F; color: #FFFFFF; font-weight: 600; font-size: 9px; padding: 5px 4px; border: 1px solid #1E3A5F; text-align: left; }
.sheet table.it td { border: 1px solid #9AA3AF; padding: 4px; vertical-align: top; font-variant-numeric: tabular-nums; }
.sheet .r { text-align: right; } .sheet .c { text-align: center; }
.sheet tr.tot td { background: #F1F4F8; font-weight: 700; }
.sheet .totg > div.tt { padding: 0; }
.sheet .totg table td { padding: 3px 10px; }
.sheet .totg .grand td { background: #1E3A5F; color: #FFFFFF; font-weight: 700; font-size: 12px; padding: 6px 10px; }
.sheet .words { font-weight: 600; }
.sheet .small { font-size: 9px; color: #4B5563; }
.sheet .bank { display: flex; gap: 12px; justify-content: space-between; }
.sheet .qrp { line-height: 1.1; text-align: center; }
.sheet .terms { white-space: pre-line; }
.sheet .sign { display: flex; flex-direction: column; justify-content: space-between; min-height: 110px; text-align: right; }
.sheet .foot { text-align: center; font-size: 8.5px; color: #6B7280; margin-top: 8px; }

/* settings */
.setgrid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 900px) { .setgrid { grid-template-columns: minmax(0, 1fr); } }
#logoPrev { max-height: 44px; max-width: 120px; border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 3px; }
.team { display: flex; flex-direction: column; gap: 6px; }
.mrow { display: grid; grid-template-columns: minmax(0, 1fr) auto 36px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.mrow em { color: var(--muted); font-style: normal; font-size: 12.5px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 11px 16px; border-radius: 10px; font-weight: 500; z-index: 50; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
@media (max-width: 760px) { .toast { bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.activity { display: grid; gap: 6px; max-height: 420px; overflow-y: auto; font-size: 13px; }
.arow { display: grid; grid-template-columns: 92px 1fr; gap: 2px 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.arow > :last-child { grid-column: 2; font-size: 12px; }
#mfaQr { background: #fff; border-radius: 8px; padding: 6px; }
#mfaSecret { word-break: break-all; }
