[hidden] { display: none !important; }
:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --ink: #1c2128;
  --muted: #6e747d;
  --line: #e3e5e1;
  --accent: #0f5e6e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0f1;
  --success: #1e8c50;
  --success-soft: #e3f4ea;
  --warn: #b86e00;
  --warn-soft: #fbf0dc;
  --danger: #c2372f;
  --danger-soft: #fbe7e5;
  --radius: 14px;
  --top: calc(52px + env(safe-area-inset-top));
  --bottom: calc(62px + env(safe-area-inset-bottom));
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111416; --card: #1b2023; --ink: #e9ecee; --muted: #98a0a8; --line: #2b3236;
    --accent: #3fb3c4; --accent-ink: #062126; --accent-soft: #163338;
    --success: #4cc584; --success-soft: #15301f; --warn: #f0ad42; --warn-soft: #33270f;
    --danger: #ff7a70; --danger-soft: #3a1a18;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
html { scroll-padding-top: calc(var(--top) + 10px); scroll-padding-bottom: calc(var(--bottom) + 90px); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding: var(--top) 0 var(--bottom);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 0; line-height: 1.2; }
code { font-size: 13px; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }

/* --- top bar & tab bar */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 10;
  height: var(--top); padding: env(safe-area-inset-top) 12px 0;
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.title { font-weight: 650; font-size: 17px; text-align: center; grid-column: 2; }
.back { grid-column: 1; grid-row: 1; background: none; border: 0; color: var(--accent); font-size: 34px; line-height: 1; padding: 0 0 4px; width: 40px; text-align: left; cursor: pointer; }
.sync { grid-column: 3; grid-row: 1; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.sync-synced { color: var(--success); background: var(--success-soft); }
.sync-syncing { color: var(--accent); background: var(--accent-soft); }
.sync-offline { color: var(--warn); background: var(--warn-soft); }
.sync-demo { color: var(--muted); background: var(--line); }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  height: var(--bottom); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 10.5px; color: var(--muted); font-weight: 500; }
.tabbar a span { font-size: 20px; line-height: 1.1; filter: grayscale(1); opacity: .7; }
.tabbar a.on { color: var(--accent); }
.tabbar a.on span { filter: none; opacity: 1; }
body.signed-out .tabbar, body.signed-out .sync { display: none; }

main { max-width: 640px; margin: 0 auto; padding: 16px 16px 90px; }
.loading { color: var(--muted); text-align: center; padding: 40px 0; }

/* --- building blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.section-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; }
.section-title.danger { color: var(--danger); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.danger { color: var(--danger) !important; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.view-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin: 4px 2px 14px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; min-height: 48px; padding: 10px 16px; margin: 0 0 10px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-big { min-height: 58px; font-size: 18px; border-radius: 16px; margin-bottom: 16px; }
.big-actions { gap: 10px; }
.big-actions .btn-big { margin-bottom: 16px; }
.actions .actions-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.actions .actions-row .btn { margin: 0; min-height: 40px; font-size: 15px; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 16px; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; flex: none; }

/* --- forms */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px;
  font: inherit; font-size: 16px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; min-height: 46px; -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea { resize: vertical; min-height: 46px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 500; font-size: 15px; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 0; -webkit-appearance: checkbox; appearance: auto; }
.subform { border-left: 3px solid var(--accent); padding-left: 12px; margin: 0 0 12px; }
.search { margin: 0 0 12px; }
.error { color: var(--danger); font-size: 14px; margin: 0 0 10px; }

/* --- lists */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; color: var(--ink); border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--bg); }
.row.dim { opacity: .5; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row-amount { font-weight: 650; font-variant-numeric: tabular-nums; }
.chevron { color: var(--muted); font-size: 22px; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 650; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.badge-draft { background: var(--line); color: var(--muted); }
.badge-open { background: var(--accent-soft); color: var(--accent); }
.badge-overdue { background: var(--danger-soft); color: var(--danger); }
.badge-paid { background: var(--success-soft); color: var(--success); }
.badge-invoiced { background: var(--ink); color: var(--bg); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chip { flex: none; font: inherit; font-size: 14px; font-weight: 600; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--muted); cursor: pointer; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--bottom) + 16px); z-index: 9;
  width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 32px; font-weight: 300; line-height: 1;
  box-shadow: 0 6px 18px rgba(15, 94, 110, .35);
}

.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty-icon { font-size: 40px; }
.empty .btn { margin-top: 12px; }
.notice { display: block; background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px; }

/* --- dashboard */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 22px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat-sub { font-size: 12.5px; color: var(--muted); }

/* --- invoice editor */
.savebar {
  position: sticky; bottom: calc(var(--bottom) + 8px); z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 10px 10px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.savebar .btn { width: auto; min-width: 120px; margin: 0; }
.savebar-total { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* --- invoice view */
.paper .label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 0 4px; }
.paper p { margin: 0; }
.paper-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; font-size: 15px; }
.paper-grid .label { margin-top: 0; }
.lines { margin-top: 16px; border-top: 1px solid var(--line); }
.line { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.line-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals { margin-top: 10px; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); }
.totals .grand { color: var(--ink); font-size: 20px; font-weight: 700; padding-top: 8px; }
.internal { background: var(--warn-soft); border-color: transparent; }
.internal .label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; color: var(--warn); margin-bottom: 4px; }
.internal p { margin: 0; }

/* --- invoice line items: spreadsheet */
.sheet { padding: 0; overflow: hidden; }
.sheet-head, .sheet-row {
  display: grid; gap: 0;
  grid-template-columns: minmax(0, 1fr) 64px 66px 92px 100px 34px;
  grid-template-areas: "desc qty unit rate amt del";
  align-items: center;
}
.sheet .c-desc { grid-area: desc; } .sheet .c-qty { grid-area: qty; } .sheet .c-unit { grid-area: unit; }
.sheet .c-rate { grid-area: rate; } .sheet .c-amt { grid-area: amt; } .sheet .c-del { grid-area: del; }
.sheet-head { background: var(--bg); border-bottom: 1px solid var(--line); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.sheet-head span { padding: 9px 8px; }
.sheet-head .c-qty, .sheet-head .c-rate, .sheet-head .c-amt { text-align: right; }
.sheet-row { border-bottom: 1px solid var(--line); }
.sheet-row:nth-child(even) { background: color-mix(in srgb, var(--bg) 45%, transparent); }
.sheet-row input, .sheet-row select {
  margin: 0; min-height: 44px; border-radius: 0; background: transparent;
  border: 0; border-right: 1px solid var(--line); padding: 8px; font-variant-numeric: tabular-nums;
}
.sheet-row input:focus, .sheet-row select:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--card); }
.sheet-row .c-qty, .sheet-row .c-rate { text-align: right; }
.sheet-row select { padding-right: 20px; background-position: calc(100% - 12px) 50%, calc(100% - 7px) 50%; }
.sheet-row .c-amt { text-align: right; padding: 0 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sheet-row .c-del { width: 34px; height: 44px; border-radius: 0; }
.sheet-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.sheet-foot .btn, .sheet-foot select { margin: 0; border-radius: 0; min-height: 46px; border: 0; }
.sheet-foot select { background-color: transparent; color: var(--accent); font-weight: 600; border-left: 1px solid var(--line); }
.sheet-foot .btn:only-child { grid-column: 1 / -1; }

@media (max-width: 560px) {
  .sheet-head, .sheet-row {
    grid-template-columns: 56px 58px minmax(0, 1fr) minmax(0, 1fr) 30px;
    grid-template-areas: "desc desc desc desc del" "qty unit rate amt amt";
  }
  .sheet-head { grid-template-areas: "qty unit rate amt amt"; }
  .sheet-head .c-desc, .sheet-head .c-del { display: none; }
  .sheet-row .c-desc { border-right: 0; border-bottom: 1px dashed var(--line); font-weight: 600; }
  .sheet-row .c-del { height: 44px; width: 30px; border-bottom: 1px dashed var(--line); }
  .sheet-row .c-rate { border-right: 0; }
}

/* sales order lines: extra details row */
.sheet-so .sheet-row { grid-template-areas: "desc qty unit rate amt del" "det det det det det ."; }
.sheet-so .c-det { grid-area: det; }
.sheet-row textarea.c-desc { margin: 0; border: 0; border-radius: 0; border-right: 1px solid var(--line); background: transparent; padding: 10px 8px; min-height: 44px; resize: none; font-weight: 600; overflow: hidden; }
.sheet-row textarea.c-desc:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--card); }
.sheet-row textarea.grow { overflow: hidden; }
.sheet-row textarea.c-det {
  margin: 0; min-height: 40px; border: 0; border-radius: 0; border-top: 1px dashed var(--line); background: transparent;
  font-size: 14px; color: var(--muted); padding: 7px 8px; resize: vertical;
}
.sheet-row textarea.c-det:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--card); color: var(--ink); }
@media (max-width: 560px) {
  .sheet-so .sheet-row { grid-template-areas: "desc desc desc desc del" "det det det det det" "qty unit rate amt amt"; }
  .sheet-so .sheet-row textarea.c-det { border-bottom: 1px dashed var(--line); }
}
.line-desc .muted.small { margin-top: 2px; }

/* --- items table */
.it-table { padding: 0; overflow: hidden; }
.it-head, .it-row { display: grid; grid-template-columns: minmax(0, 1fr) 78px 56px 28px; gap: 2px; align-items: start; padding: 0 4px 0 6px; }
.it-head { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding-top: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); background: var(--bg); }
.it-row { position: relative; padding-top: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.it-row input, .it-row select { margin: 0; min-height: 40px; padding: 8px 9px; background: transparent; border-color: transparent; }
.it-row input:hover, .it-row select:hover { border-color: var(--line); }
.it-row .i-name { font-weight: 600; }
.it-row .i-desc { font-size: 14px; min-height: 30px; padding-top: 2px; padding-bottom: 4px; color: var(--muted); }
.it-row select { padding-left: 6px; padding-right: 18px; background-position: calc(100% - 12px) 50%, calc(100% - 7px) 50%; }
.it-price { position: relative; }
.it-dollar { position: absolute; left: 7px; top: 10px; color: var(--muted); font-size: 15px; pointer-events: none; }
.it-price input { padding-left: 17px; padding-right: 4px; font-variant-numeric: tabular-nums; }
.it-row .icon-btn { margin-top: 2px; width: 28px; }
.it-saved { position: absolute; right: 44px; bottom: 6px; font-size: 11px; color: var(--success); opacity: 0; pointer-events: none; }
.it-row.flash .it-saved { animation: saved 1.4s ease; }
@keyframes saved { 0% { opacity: 0; } 15% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }
.it-add { margin: 4px 0; min-height: 46px; }

/* --- settings */
.logo-row { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.logo-row .btn { margin-bottom: 6px; }
.logo-box { width: 96px; height: 96px; flex: none; border: 1px dashed var(--line); border-radius: 12px; display: grid; place-items: center; overflow: hidden; background: #fff; }
.logo-box img { max-width: 100%; max-height: 100%; }

/* --- login */
.login { max-width: 380px; margin: 6vh auto 0; text-align: center; }
.login img { border-radius: 18px; }
.login h1 { margin: 10px 0 18px; }
.login form { text-align: left; }

/* --- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + 20px); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 12px;
  font-size: 15px; font-weight: 500; max-width: calc(100% - 32px); text-align: center;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: var(--warn); color: #fff; }
@media (max-width: 560px) { .sheet-row textarea.c-desc { border-right: 0; border-bottom: 1px dashed var(--line); } }

/* --- sign-up / sign-in / setup (full-screen, no top bar or tabs) */
body.bare { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
body.bare .topbar, body.bare .tabbar, body.bare .erp { display: none !important; }
.tabbar a b { font-weight: inherit; }
.auth { max-width: 400px; margin: 0 auto; padding: 28px 4px 40px; display: flex; flex-direction: column; gap: 10px; }
.auth .btn { margin: 0; }
.auth form { display: flex; flex-direction: column; gap: 2px; }
.auth form .btn-primary { margin-top: 8px; }
.auth-hero { text-align: center; margin: 4vh 0 18px; }
.auth-hero img { border-radius: 18px; }
.auth-hero h1 { margin: 12px 0 6px; font-size: 28px; }
.auth-tag { font-size: 19px; font-weight: 600; margin: 0 0 6px; }
.auth-title { text-align: center; font-size: 24px; margin: 6px 0 6px; }
.auth-icon { font-size: 44px; text-align: center; margin-top: 4vh; }
.auth-link { display: block; text-align: center; font-size: 15px; font-weight: 500; padding: 8px; color: var(--accent); }
.auth-link.left { text-align: right; padding: 0 2px 6px; }
.linkish { background: none; border: 0; font: inherit; font-size: 15px; cursor: pointer; }
.center { text-align: center; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 4px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.btn-google { background: var(--card); gap: 10px; }
.field-error { display: block; color: var(--danger); font-size: 13px; font-weight: 500; margin-top: 4px; }
input.invalid { border-color: var(--danger); }
.ok-msg { background: var(--success-soft); color: var(--success); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 6px 0; }
.pw { position: relative; display: block; }
.pw input { padding-right: 46px; }
.pw-eye { position: absolute; right: 4px; top: 5px; height: 38px; width: 40px; border: 0; background: none; font-size: 18px; cursor: pointer; opacity: .6; }
.terms { font-size: 14px; align-items: flex-start; margin: 8px 0 0; }
.terms input { margin-top: 1px; flex: none; }
.lang-switch { display: flex; justify-content: center; gap: 4px; margin-top: 14px; }
.lang-switch button { border: 0; background: none; font: inherit; font-size: 14px; color: var(--muted); padding: 6px 10px; border-radius: 99px; cursor: pointer; }
.lang-switch button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.choice { display: flex; align-items: center; gap: 14px; text-align: left; width: 100%; padding: 18px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink); font: inherit; cursor: pointer; }
.choice:active { transform: scale(.98); }
.choice:hover { border-color: var(--accent); }
.choice b { font-size: 17px; }
.choice-icon { font-size: 30px; }
.steps { display: flex; gap: 6px; justify-content: center; margin-bottom: 4px; }
.steps span { width: 34px; height: 5px; border-radius: 99px; background: var(--line); }
.steps span.on { background: var(--accent); }
.auth .logo-row { margin: 8px 0 4px; }

/* --- data tables (ERP style) */
.dt-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.dt-search { flex: 1; margin: 0; min-height: 44px; }
.dt-add { width: auto; margin: 0; min-height: 44px; white-space: nowrap; padding: 10px 14px; }
.dt .chips { margin-bottom: 10px; }
.dt-scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
.dt-table { width: 100%; border-collapse: collapse; font-size: 14.5px; font-variant-numeric: tabular-nums; }
.dt-table th { position: sticky; top: 0; background: var(--bg); text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 10px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; }
.dt-table th.sorted { color: var(--accent); }
.dt-arrow { font-style: normal; font-size: 9px; margin-left: 4px; }
.dt-table td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dt-table tbody tr:last-child td { border-bottom: 0; }
.dt-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg) 45%, transparent); }
.dt-table tbody tr[data-href] { cursor: pointer; }
.dt-table tbody tr[data-href]:hover td, .dt-table tbody tr[data-href]:focus td { background: var(--accent-soft); outline: none; }
.dt-table .right { text-align: right; }
.dt-table td b { font-weight: 600; }
.dt-empty td { text-align: center; color: var(--muted); padding: 28px 12px; cursor: default; }
.dt-foot { font-size: 12.5px; color: var(--muted); margin: 8px 4px 0; }
@media (max-width: 560px) {
  .hide-phone { display: none; }
  .dt-table { font-size: 14px; }
  .dt-table th, .dt-table td { padding-left: 8px; padding-right: 8px; }
}
.it-sort { background: none; border: 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; padding: 0; text-align: left; }
.it-sort.right { text-align: left; }
.it-sort i { font-style: normal; font-size: 9px; }
body.wide main { max-width: 1100px; }
.dt-table td:first-child, .dt-table td.nowrap { white-space: nowrap; }
.dt-table td:nth-child(3) { white-space: nowrap; }

/* --- crew */
.week-nav { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; gap: 6px; margin-bottom: 10px; }
.week-nav .btn { margin: 0; font-size: 26px; min-height: 44px; }
.week-nav b { font-size: 17px; }
.day-chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 4px 0 14px; }
.day-chips .chip { text-align: center; padding: 6px 0; font-size: 12px; line-height: 1.25; border-radius: 12px; }
.day-chips .chip b { font-size: 15px; }
.crew-table td, .crew-table th { white-space: nowrap; }
.crew-table tfoot td { border-top: 2px solid var(--line); background: var(--bg); padding: 11px 10px; }
.sticky-col { position: sticky; left: 0; background: var(--card); z-index: 1; }
.crew-table thead .sticky-col, .crew-table tfoot .sticky-col { background: var(--bg); z-index: 2; }
.crew-table tbody tr:nth-child(even) td.sticky-col { background: color-mix(in srgb, var(--bg) 45%, var(--card)); }
.crew-row { padding: 12px 14px; margin-bottom: 10px; }
.crew-row-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.crew-calc { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--accent); }
.times { display: grid; grid-template-columns: 1fr 1fr 0.8fr; gap: 8px; }
.times label { margin: 0; font-size: 12px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--card); color: var(--ink); font: inherit; font-size: 14.5px; font-weight: 600; padding: 11px 6px; cursor: pointer; border-left: 1px solid var(--line); }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.seg button:disabled { opacity: .6; cursor: default; }
.pay-seg { margin: 6px 0 12px; }
.label-like { font-size: 13px; font-weight: 600; color: var(--muted); }
.totals-card .totals { margin: 0; }
.more-icon { font-size: 20px; width: 28px; text-align: center; }
.times { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1.25fr) minmax(0, .8fr); }
.times input { min-width: 0; width: 100%; padding-left: 8px; padding-right: 6px; }
.times input[type=time]::-webkit-calendar-picker-indicator { display: none; }
.times input[type=time] { font-variant-numeric: tabular-nums; }

/* --- crew (simple time tracker) */
.week-nav .center { text-align: center; }
.crew-list .row-end b { font-variant-numeric: tabular-nums; }
.crew-total { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; font-size: 17px; }
.crew-total b { font-size: 20px; }
.person-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.person-head select { width: auto; max-width: 65%; font-size: 20px; font-weight: 700; margin: 0; padding: 8px 32px 8px 10px; }
.tt { padding: 0; overflow: hidden; }
.tt-row { display: grid; grid-template-columns: 52px minmax(0,1fr) minmax(0,1fr) 78px; align-items: center; gap: 4px; width: 100%; padding: 13px 12px; border: 0; border-top: 1px solid var(--line); background: none; color: var(--ink); font: inherit; font-size: 15px; text-align: left; font-variant-numeric: tabular-nums; }
.tt-row.tt-daily { grid-template-columns: 52px minmax(0,1fr) 70px; }
.tt-row > span:last-child { text-align: right; }
button.tt-row { cursor: pointer; }
button.tt-row:active { background: var(--accent-soft); }
.tt-head { border-top: 0; background: var(--bg); font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tt-set { color: var(--accent); font-weight: 700; }
.tt-foot { border-top: 2px solid var(--line); padding: 10px 12px 12px; }
.tt-foot > div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.tt-foot .grand { font-size: 18px; }
.tt-foot .grand b { color: var(--accent); }
@media (max-width: 380px) { .tt-row { font-size: 13.5px; padding: 12px 8px; } }

.popup-back { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.popup { width: 100%; max-width: 520px; background: var(--card); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0,0,0,.25); }
.popup-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 17px; }
.popup-x { border: 0; background: none; color: var(--muted); font-size: 20px; padding: 4px 8px; cursor: pointer; }
.popup-calc { text-align: center; font-size: 22px; font-weight: 700; color: var(--accent); min-height: 34px; margin: 12px 0 4px; font-variant-numeric: tabular-nums; }
@media (min-width: 700px) { .popup-back { align-items: center; } .popup { border-radius: 18px; } }

.tt-row { padding: 8px 10px; }
.tt-head { padding: 10px; }
.tt-day { display: flex; flex-direction: column; line-height: 1.15; text-transform: capitalize; }
.tt-day small { color: var(--muted); font-size: 12.5px; }
.tt-calc { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; color: var(--muted); line-height: 1.25; }
.tt-calc b { color: var(--ink); font-size: 14.5px; }
.tfield { position: relative; display: block; margin: 0; font-size: 15px; font-weight: 600; color: var(--ink); }
.tfield span { display: flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 6px; border: 1px solid var(--field-line); background: var(--field); border-radius: 10px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tfield.blank span { color: var(--muted); font-weight: 500; border-style: dashed; }
.tfield input { position: absolute; inset: 0; opacity: 0; margin: 0; min-height: 0; width: 100%; height: 100%; cursor: pointer; }
.tfield:focus-within span { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.repeat { padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); background: color-mix(in srgb, var(--accent-soft) 60%, var(--card)); }
.repeat-title { font-weight: 700; color: var(--accent); margin-bottom: 8px; }
.repeat-times { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.repeat .two { margin-bottom: 6px; }
.repeat .two .btn { margin: 0; }
.seg-sm button { padding: 8px 4px; font-size: 13px; }
.tt-foot small { display: block; margin-top: 4px; }
@media (max-width: 380px) { .tt-row { grid-template-columns: 44px minmax(0,1fr) minmax(0,1fr) 66px; padding: 8px 6px; } .tfield { font-size: 13.5px; } }

/* --- fields stand out from the background (most visible in dark mode) */
:root { --field: var(--bg); --field-line: #cfd3cd; }
@media (prefers-color-scheme: dark) { :root { --field: #262d31; --field-line: #4a545a; } }
input, select, textarea { background-color: var(--field); border-color: var(--field-line); }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
.sheet-row input, .sheet-row select, .sheet-row textarea.c-desc, .sheet-row textarea.c-det { background-color: var(--field); }
.sheet-row input:focus, .sheet-row select:focus, .sheet-row textarea.c-desc:focus, .sheet-row textarea.c-det:focus { outline: 2px solid var(--accent); outline-offset: -2px; box-shadow: none; background-color: var(--card); }
.seg-sm button { line-height: 1.15; }
.session-card { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px; margin: 6px 0 14px; font-size: 17px; }

/* --- save at the end of the form + small save in the top bar */
.save-end { padding: 14px 16px; }
.save-total { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; font-size: 16px; }
.save-total b { font-size: 24px; font-variant-numeric: tabular-nums; }
.save-end .btn { margin: 0; }
.head-save { grid-column: 3; grid-row: 1; border: 0; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font: inherit; font-size: 14px; font-weight: 700; padding: 7px 14px; cursor: pointer; }

/* --- crew: clear a day */
.tt-row:not(.tt-daily) { grid-template-columns: 50px minmax(0,1fr) minmax(0,1fr) 66px 26px; }
.tt-clear { border: 0; background: none; color: var(--danger); font-size: 17px; font-weight: 700; padding: 6px 0; cursor: pointer; }
.tt-clear[hidden] { display: block !important; visibility: hidden; }
@media (max-width: 380px) { .tt-row:not(.tt-daily) { grid-template-columns: 42px minmax(0,1fr) minmax(0,1fr) 58px 22px; } }

/* --- OK bar above the number keyboard */
.kbbar { position: fixed; left: 0; right: 0; top: 0; z-index: 60; display: flex; justify-content: flex-end; padding: 6px 10px; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(0,0,0,.12); }
.kbbar button { border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 700; font-size: 16px; padding: 8px 22px; }
.tt-head:not(.tt-daily) > span:nth-child(4) { text-align: right; }

/* ===================== dashboard */
.stats-4 { grid-template-columns: 1fr 1fr; margin-bottom: 14px; }
a.stat { color: inherit; text-decoration: none; display: block; }
a.stat:hover { border-color: var(--accent); }
.chart-card { padding: 14px 16px 10px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.legend { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 6px; }
.lg-billed, .bar.billed { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.lg-paid, .bar.paid { background: var(--accent); }
.bars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; height: 140px; align-items: end; }
.bar-col { display: flex; flex-direction: column; height: 100%; }
.bar-pair { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 3px; border-bottom: 1px solid var(--line); }
.bar { width: 40%; max-width: 22px; min-height: 2px; border-radius: 4px 4px 0 0; }
.bar-label { text-align: center; font-size: 12px; color: var(--muted); padding-top: 4px; text-transform: capitalize; }

/* ===================== tables: footer, filters, export */
.dt-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.dt-count { flex: 1; }
.dt-total { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.dt-export { border: 1px solid var(--line); background: var(--card); color: var(--accent); font: inherit; font-size: 12.5px; font-weight: 700; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.dt-filters select { margin: 0; min-height: 44px; width: auto; }

/* ===================== admin */
.admin-tabs { margin-bottom: 14px; max-width: 520px; }
.admin-tabs a { flex: 1; text-align: center; padding: 10px 6px; font-size: 14.5px; font-weight: 600; color: var(--ink); text-decoration: none; border-left: 1px solid var(--line); background: var(--card); }
.admin-tabs a:first-child { border-left: 0; }
.admin-tabs a.on { background: var(--accent); color: var(--accent-ink); }
.chip-admin { display: inline-block; font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 1px 7px; vertical-align: 1px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv code { font-size: 12px; word-break: break-all; }
.uid-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.uid-row code { font-size: 12px; word-break: break-all; }
.btn-sm { width: auto; min-height: 0; padding: 4px 10px; font-size: 13px; margin: 0; }

/* ===================== computer layout (ERP style: name + menu on top) */
.erp[hidden] { display: none !important; }
@media (max-width: 999px) { .erp, .page-h, .view-head > .page-back { display: none !important; } }
@media (min-width: 1000px) {
  :root { --erp: 56px; --top: var(--erp); --bottom: 0px; }
  body.editor, body.doc-view { --top: calc(var(--erp) + 48px); }
  .tabbar { display: none; }
  .erp { position: fixed; inset: 0 0 auto 0; z-index: 11; height: var(--erp); display: flex; align-items: stretch; gap: 8px; padding: 0 16px 0 20px; background: var(--card); border-bottom: 1px solid var(--line); }
  .erp-co { display: flex; align-items: center; gap: 10px; padding-right: 14px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 15px; max-width: 260px; min-width: 0; }
  .erp-co #erpCompany { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .erp-co-logo { flex: none; width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 13px; font-weight: 800; letter-spacing: .5px; overflow: hidden; }
  .erp-co-logo.has-img { background: #fff; border: 1px solid var(--line); }
  .erp-co-logo img { width: 100%; height: 100%; object-fit: contain; }
  .topnav { flex: 1; min-width: 0; height: var(--erp); display: flex; align-items: stretch; gap: 2px; overflow-x: auto; border-left: 1px solid var(--line); padding-left: 8px; }
  .topnav a { display: flex; align-items: center; padding: 0 14px; font-size: 15px; font-weight: 600; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; }
  .topnav a:hover { color: var(--ink); }
  .topnav a.on { color: var(--accent); border-bottom-color: var(--accent); }
  .erp-sync { align-self: center; }
  .erp-me { position: relative; display: flex; align-items: center; }
  .erp-me-btn { display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 10px; border: 1px solid transparent; border-radius: 10px; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; }
  .erp-me-btn:hover, .erp-me-btn.on, .erp-me-btn[aria-expanded="true"] { background: var(--bg); border-color: var(--line); }
  .erp-menu { position: absolute; right: 0; top: calc(100% + 4px); min-width: 200px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 6px; display: flex; flex-direction: column; }
  .erp-menu[hidden] { display: none; }
  .erp-menu-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; color: var(--muted); font-size: 13px; }
  .erp-menu a, .erp-menu button { display: block; text-align: left; padding: 10px; border-radius: 8px; border: 0; background: none; color: var(--ink); font: inherit; font-size: 15px; text-decoration: none; cursor: pointer; }
  .erp-menu a:hover, .erp-menu button:hover { background: var(--bg); }
  .erp-menu #erpOut { color: var(--danger, #b42318); }
  /* page title inside the page; the grey title bar only stays in editors and documents (back + Save live there) */
  .topbar { display: none; }
  body.editor .topbar, body.doc-view .topbar { display: grid; top: var(--erp); height: 48px; padding-top: 0; background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; grid-template-columns: 44px 1fr auto; }
  .topbar .title { text-align: left; font-size: 18px; }
  .page-h { max-width: 1200px; margin: 0 auto; padding: 22px 24px 0; display: flex; align-items: center; gap: 8px; }
  .page-h h1 { margin: 0; font-size: 26px; }
  .page-back { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font-size: 24px; line-height: 1; cursor: pointer; }
  body.editor .page-h, body.doc-view .page-h, body.bare .page-h { display: none; }
  main { max-width: 1200px; padding: 20px 24px 40px; }
  body.wide main { max-width: 1200px; }

  /* dashboard */
  .stats-4 { grid-template-columns: repeat(4, 1fr); }
  .big-actions { max-width: 520px; }
  .dash-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; align-items: start; }
  .bars { height: 180px; }

  /* editors: form on the left, total + save on the right (stays visible) */
  body.editor #f { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 0 22px; align-items: start; }
  body.editor #f > * { grid-column: 1; }
  body.editor #f > .save-end { grid-column: 2; grid-row: 1 / span 30; position: sticky; top: calc(var(--top) + 16px); }
  body.editor #headSave { display: none; }

  /* document view: paper on the left, actions on the right */
  body.doc-view main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 0 22px; align-items: start; }
  body.doc-view main > * { grid-column: 1; }
  body.doc-view main > .view-head { grid-column: 1 / -1; }
  body.doc-view main > .actions { grid-column: 2; grid-row: 2 / span 10; position: sticky; top: calc(var(--top) + 16px); }

  /* admin account: details + actions side by side */
  .admin-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 0 22px; align-items: start; }

  /* forms in general: two fields per row where it fits */
  .card > .two { gap: 14px; }
  .dt-table { font-size: 15px; }
  .toast { bottom: 24px; }
}
@media (min-width: 1000px) and (max-width: 1150px) { .topnav a { padding: 0 10px; font-size: 14px; } }
.dt-toolbar { flex-wrap: wrap; }
.dt-toolbar .dt-search { min-width: 200px; }
@media (max-width: 560px) { .dt-toolbar > div { flex-basis: 100%; order: 3; } }

/* ===================== items: spreadsheet rows + quick add window */
.dt-table.compact td { padding: 6px 10px; font-size: 14px; }
.dt-table.compact th { padding: 7px 10px; }
.dt-table tbody tr[data-i] { cursor: pointer; }
.dt-table tbody tr[data-i]:hover td, .dt-table tbody tr[data-i]:focus td { background: var(--accent-soft); outline: none; }
.dt-table .mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: var(--muted); }
.dt-table .low { color: var(--danger); font-weight: 700; }
.item-det { white-space: nowrap; }
.dt-actions { display: flex; gap: 8px; }
.dt-btn { width: auto; margin: 0; min-height: 44px; padding: 10px 14px; white-space: nowrap; }
.item-pop label, .import-pop label { margin-bottom: 10px; }
.ip-grid { display: grid; gap: 10px; }
.ip-top { grid-template-columns: 110px minmax(0, 1fr); }
.ip-nums { grid-template-columns: 1fr 1fr 1fr; }
.ip-btns .btn { margin: 0; }
.item-pop .btn-ghost.danger { margin-top: 8px; }
.import-pop textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.import-pop .dt-scroll { margin: 10px 0 6px; max-height: 240px; }
.popup { max-height: 92vh; overflow: auto; }
@media (min-width: 700px) { .item-pop, .import-pop { max-width: 560px; } }

/* ===================== PDF design picker */
.two.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 560px) { .two.three { grid-template-columns: 1fr; } }
.pdf-pick { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.pdf-pick img { width: 64px; height: auto; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.pdf-pick-main { flex: 1; min-width: 0; }
.pdf-pick .btn-sm { padding: 8px 14px; }
#pdfCard .check { margin: 12px 0; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--card); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; margin: 0; }
.swatch.on { box-shadow: 0 0 0 3px var(--accent); }
.swatch-custom { display: grid; place-items: center; background: var(--bg); color: var(--muted); font-weight: 700; position: relative; overflow: hidden; }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; margin: 0; }
.gallery-pop { max-width: 980px !important; }
.tpl-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 10px; }
@media (min-width: 700px) { .tpl-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.tpl { border: 2px solid var(--line); background: var(--card); border-radius: 10px; padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; font: inherit; color: var(--ink); font-size: 13px; font-weight: 600; }
.tpl img { width: 100%; height: auto; border-radius: 4px; background: #fff; border: 1px solid var(--line); }
.tpl.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.gallery-pop .two .btn { margin: 0; }

/* ===================== line items: entry row + table */
.le-card { padding: 0; overflow: hidden; }
.le-entry { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 10px; padding: 14px 14px 6px; background: color-mix(in srgb, var(--accent-soft) 45%, var(--card)); border-bottom: 1px solid var(--line); }
.le-entry label { margin-bottom: 8px; }
.le-item, .le-det { grid-column: 1 / -1; }
.le-amt { display: flex; flex-direction: column; justify-content: center; font-variant-numeric: tabular-nums; margin-bottom: 8px; }
.le-amt b { font-size: 17px; }
.le-add { margin: 0 0 8px; align-self: end; min-height: 46px; }
.le-cancel { grid-column: 1 / -1; margin: 0 0 8px; }
.le-entry textarea { min-height: 42px; resize: none; overflow: hidden; }
.le-card.le-editing .le-entry { background: color-mix(in srgb, var(--warn-soft) 70%, var(--card)); }
.le-scroll { overflow-x: auto; }
.le-table { border: 0; }
.le-table th, .le-table td { padding: 8px 10px; }
.le-table tbody tr[data-i] { cursor: pointer; }
.le-table tbody tr[data-i]:hover td { background: var(--accent-soft); }
.le-table tr.le-on td { background: color-mix(in srgb, var(--warn-soft) 70%, var(--card)) !important; }
.le-table tfoot td { border-top: 2px solid var(--line); padding: 10px; background: var(--bg); }
.le-n { width: 28px; color: var(--muted); }
.le-act { width: 66px; white-space: nowrap; text-align: right; }
.le-act .icon-btn { width: 28px; height: 28px; font-size: 15px; }
.le-act .le-del { color: var(--danger); }
.le-dt { white-space: pre-line; margin-top: 2px; }
@media (max-width: 560px) {
  .le-table th:nth-child(4), .le-table td:nth-child(4) { display: none; }
  .le-table tfoot td:first-child { }
}
@media (min-width: 1000px) {
  .le-entry { grid-template-columns: minmax(0, 3fr) minmax(0, .6fr) minmax(0, .8fr) minmax(0, 1fr) minmax(0, 1fr) auto; gap: 0 10px; align-items: end; }
  .le-item { grid-column: auto; }
  .le-det { grid-column: 1 / 6; }
  .le-cancel { grid-column: 6; }
}

/* PDF preview (full screen, pages drawn with pdf.js) */
body.pv-open { overflow: hidden; }
.pv-back { position: fixed; inset: 0; z-index: 80; background: rgba(10, 18, 20, .72); display: flex; justify-content: center; align-items: stretch; }
.pv { display: flex; flex-direction: column; width: 100%; max-width: 980px; background: #3a4244; }
.pv-head { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--card); color: var(--ink); }
.pv-x { border: 0; background: none; color: inherit; font: inherit; font-weight: 600; padding: 10px 8px; min-height: 44px; cursor: pointer; }
.pv-name { flex: 1; text-align: center; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.pv-sp { width: 70px; }
.pv-pages { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px; touch-action: pan-x pan-y pinch-zoom; }
.pv-pages canvas { background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.35); max-width: 100%; height: auto; }
.pv-count { color: #d6dde0; }
.pv-banner { background: #fff4dc; color: #7a4b00; font-size: 14px; font-weight: 600; padding: 10px 14px; text-align: center; }
.pv-foot .btn-success { background: var(--success, #1c7a43); color: #fff; border: 0; }
.pv-frame { width: 100%; flex: 1; min-height: 70vh; border: 0; background: #fff; }
.pv-foot { display: flex; gap: 10px; justify-content: center; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--card); }
.pv-foot .btn { flex: 1; max-width: 260px; min-height: 48px; }
.pv-printframe { position: fixed; width: 0; height: 0; border: 0; visibility: hidden; }
@media (min-width: 1000px) { .pv-back { padding: 24px; } .pv { border-radius: 14px; overflow: hidden; } .pv-x span { display: inline; } }

@media (min-width: 1000px) { .page-h:empty { display: none; } .view-head > .page-back { flex: none; margin-right: 4px; align-self: center; } .view-head > .page-back + * { margin-right: auto; } }

/* ===================== row buttons in tables (Sales Orders) */
.tacts { display: flex; gap: 6px; justify-content: flex-end; }
.tbn { height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 13px; font-weight: 700; white-space: nowrap; cursor: pointer; }
.tbn:hover { border-color: var(--muted); }
.tbn.g { background: var(--accent); border-color: var(--accent); color: #fff; }
.tbn.r { color: var(--danger, #b42318); }
.tbn.l { border-color: transparent; background: none; color: var(--accent); }
.tbn.icon { width: 34px; padding: 0; font-size: 16px; }
.ph-only { display: none; }
.dt-table tr.dt-new td { background: var(--success-soft); }
.dt-extra { color: var(--muted); }
.dt-table th.nosort { cursor: default; }
@media (max-width: 999px) {
  .dt-table.cards, .dt-table.cards tbody { display: block; width: 100%; }
  .dt-table.cards thead { display: none; }
  .dt-table.cards tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "num amt" "sub st" "act act"; gap: 4px 10px; padding: 12px; border-bottom: 1px solid var(--line); }
  .dt-table.cards td { display: none; padding: 0; border: 0; background: none !important; }
  .dt-table.cards td.c-num { display: block; grid-area: num; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
  .dt-table.cards td.c-amt { display: block; grid-area: amt; }
  .dt-table.cards td.c-sub { display: block; grid-area: sub; color: var(--muted); font-size: 13px; white-space: normal; overflow: hidden; text-overflow: ellipsis; }
  .dt-table.cards td.c-st { display: block; grid-area: st; text-align: right; }
  .dt-table.cards td.c-act { display: block; grid-area: act; margin-top: 6px; }
  .dt-table.cards .ph-only { display: inline; }
  .dt-table.cards .tacts .tbn { flex: 1; height: 40px; }
  .dt-table.cards .tacts .tbn.icon { flex: 0 0 44px; }
  .dt-table.cards tr.dt-new { box-shadow: inset 4px 0 0 var(--success); }
  .dt-table.cards tr.dt-new td { background: none; }
  .dt-table.cards tr.dt-new { background: var(--success-soft); }
  .dt-table.cards tr.dt-empty { display: block; }
  .dt-table.cards tr.dt-empty td { display: block; }
  .dt:has(.dt-table.cards) .dt-foot { position: sticky; bottom: var(--bottom); background: var(--card); border-top: 1px solid var(--line); margin: 0 -16px; padding: 10px 16px; z-index: 2; }
}

/* ===================== v3: section colors, filters, editor buttons, payments */
/* Estimates keep the brand blue; Invoices turn green (money) */
body[data-sec="inv"] { --accent: #1c7a43; --accent-soft: #e2f3e8; --accent-ink: #ffffff; }
@media (prefers-color-scheme: dark) { body[data-sec="inv"] { --accent: #4cc27f; --accent-soft: #15301f; --accent-ink: #06210f; } }
.sec-tag { font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 4px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); margin-left: 4px; }
body[data-sec] .page-h h1 { color: var(--ink); }
.badge-unpaid, .badge-partial { background: #fff4dc; color: #8a5a00; }
.badge-invoiced { background: #ece8f8; color: #5b3fa8; }
@media (prefers-color-scheme: dark) { .badge-unpaid, .badge-partial { background: #3a2c0c; color: #f3c46a; } .badge-invoiced { background: #2a2342; color: #c4b5fd; } }

/* period + status filters */
.fbar { display: flex; gap: 8px; flex-wrap: wrap; }
.fsel { display: flex; align-items: center; gap: 8px; height: 44px; margin: 0; padding: 0 4px 0 12px; border: 1px solid var(--field-line, var(--line)); border-radius: 10px; background: var(--card); font-size: 12px; font-weight: 600; color: var(--muted); }
.fsel select, .fsel input { border: 0; background: none; margin: 0; padding: 0 6px; min-height: 40px; width: auto; font-size: 14px; font-weight: 700; color: var(--ink); box-shadow: none; }
.fsel select:focus, .fsel input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (max-width: 999px) { .dt-toolbar .fbar { width: 100%; } .fbar .fsel { flex: 1; min-width: 0; } .fsel select { flex: 1; min-width: 0; } }

/* editor: [Save draft] [Preview] side by side */
.save-btns { display: flex; gap: 10px; }
.save-btns .btn { flex: 1; min-height: 52px; font-size: 16px; }
.btn-outline { background: var(--card); border: 1.5px solid var(--field-line, var(--line)); color: var(--ink); }
body.editor #headSave { display: none !important; }

/* PDF preview: a big, clear Close on the right */
.pv-head { justify-content: space-between; padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px; }
.pv-name { text-align: left; }
.pv-x { height: 44px; padding: 0 18px; border-radius: 999px; background: var(--ink); color: var(--card); font-weight: 800; font-size: 15px; }
.pv-x:hover { opacity: .9; }

/* "+ New" chooser and "Got paid" sheet */
.big-actions #newDoc { width: 100%; }
@media (min-width: 1000px) { .big-actions #newDoc { width: auto; min-width: 260px; } }
.newdoc-opt { display: flex; flex-direction: column; gap: 2px; padding: 16px; border-radius: 14px; margin-top: 10px; text-decoration: none; color: #fff; }
.newdoc-opt b { font-size: 18px; } .newdoc-opt span { font-size: 14px; opacity: .9; }
.newdoc-opt.est { background: #0f5e6e; } .newdoc-opt.inv { background: #1c7a43; }
.receive { display: flex; flex-direction: column; gap: 10px; }
.receive label { margin: 0; }
.lbl-sm { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pay-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.pay-chips .chip.on { background: #1c7a43; color: #fff; border-color: #1c7a43; }
.center { text-align: center; }
.stats-4.stats-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 999px) { .stats-4.stats-3 { grid-template-columns: 1fr 1fr; } }
.ask-est { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; margin: 4px 0 12px; }
.ask-est legend { font-weight: 700; font-size: 14px; padding: 0 4px; }
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; display: flex; align-items: center; gap: 8px; margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-weight: 600; }
.seg input { width: auto; margin: 0; }
.erp-co-logo { background: #0f5e6e; }
.save-btns .btn { white-space: nowrap; font-size: 15px; padding-left: 8px; padding-right: 8px; }
