:root {
  --brand: #18853f;
  --brand-soft: color-mix(in srgb, var(--brand) 10%, white);
  --sidebar: #12261b;
  --bg: #f4f5f8;
  --panel: #ffffff;
  --text: #1c2233;
  --muted: #667085;
  --line: #e4e7ec;
  --good: #12805c;
  --warn: #b54708;
  --bad: #c01f2f;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }

/* layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 228px; flex-shrink: 0; background: var(--sidebar); color: #c9cfdb; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 18px 18px 14px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand img { max-height: 36px; max-width: 60px; border-radius: 4px; background: #fff; }
.brand .mark { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: #fff; flex-shrink: 0; }
.brand .name { color: #fff; font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand .tag { font-size: 11px; color: #8d96a8; text-transform: uppercase; letter-spacing: .08em; }
.nav { padding: 10px 8px; flex: 1; }
.nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6f7a8f; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #c9cfdb; padding: 8px 10px; border-radius: 6px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar .foot { padding: 12px 18px; font-size: 11px; color: #6f7a8f; border-top: 1px solid rgba(255,255,255,.08); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 24px 28px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.panel.flush { padding: 0; overflow: hidden; }
.panel.flush > h2 { padding: 16px 18px 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat.accent { border-top: 3px solid var(--brand); }

/* tables */
.table-wrap, .panel.flush.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: #fafbfc; }
tr.click { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 700; border-top: 2px solid var(--text); background: #fafbfc; }
th.selcell, td.selcell { width: 34px; padding-right: 0; }
td.selcell input, th.selcell input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--brand); }
tr.picked td { background: var(--brand-soft); }
tr.sel-foot td { background: var(--brand-soft); color: var(--brand); border-top: 1px solid var(--line); }
.selbar { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 140%); opacity: 0; transition: .18s; z-index: 50;
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap; max-width: calc(100vw - 32px);
  background: var(--sidebar); color: #fff; padding: 10px 14px 10px 18px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 14px; }
.selbar.show { transform: translate(-50%, 0); opacity: 1; }
.selbar em { font-style: normal; opacity: .7; margin-right: 4px; }
.selbar .btn { margin-left: 4px; }
tr.subtotal td { font-weight: 700; background: var(--brand-soft); }
tr.section td { font-weight: 700; padding-top: 16px; border-bottom: none; }
.neg { color: var(--bad); }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* forms */
label { display: block; font-size: 12px; font-weight: 600; color: #344054; margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid #d0d5dd; border-radius: 6px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; font-size: 13px; }
.lines td { padding: 4px; }
.lines input, .lines select { padding: 6px 8px; }
.lines .del { color: var(--muted); cursor: pointer; border: none; background: none; font-size: 18px; }
.totals { margin-left: auto; width: 300px; margin-top: 12px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 16px; border-top: 2px solid var(--text); padding-top: 8px; }
.search { max-width: 260px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 6px; border: 1px solid #d0d5dd; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(.94); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef0f4; color: #475467; }
.badge.good { background: #e7f6ef; color: var(--good); }
.badge.warn { background: #fef3e7; color: var(--warn); }
.badge.bad { background: #fdecee; color: var(--bad); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--brand); border-color: var(--brand); text-decoration: none; }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(16, 24, 40, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: min(640px, 100%); max-height: 92vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(980px, 100%); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; }
.modal .body { padding: 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
#toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 60; }
.toast { background: #1c2233; color: #fff; padding: 12px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 380px; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--good); }
.alert { padding: 12px 14px; border-radius: 6px; background: #fef3e7; color: #7a2e0e; margin-bottom: 14px; }
.alert.info { background: #eef4ff; color: #1d3a8a; }

/* chart */
.bars { display: flex; gap: 14px; align-items: flex-end; height: 170px; padding-top: 10px; }
.bars .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bars .b { width: 40%; max-width: 26px; border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .s { background: var(--brand); }
.bars .c { background: #98a2b3; }
.bars .lbl { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; background: var(--c); }

/* printable documents */
.doc { background: #fff; max-width: 820px; margin: 0 auto; padding: 44px; border: 1px solid var(--line); border-radius: var(--radius); }
.doc .top { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.doc .logo img { max-height: 70px; max-width: 220px; }
.doc .logo .co { font-size: 22px; font-weight: 800; color: var(--brand); }
.doc .title { font-size: 26px; font-weight: 800; text-align: right; color: var(--brand); text-transform: uppercase; letter-spacing: .04em; }
.doc .meta { text-align: right; font-size: 13px; line-height: 1.6; }
.doc .addr { white-space: pre-line; line-height: 1.5; }
.doc table { margin-top: 24px; }
.doc th { background: var(--brand-soft); color: var(--text); }
.doc .foot { margin-top: 36px; font-size: 12px; color: var(--muted); white-space: pre-line; border-top: 1px solid var(--line); padding-top: 14px; }
.pre { white-space: pre-line; }
.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 16px; }
.login { min-height: 100vh; display: grid; place-items: center; background: var(--sidebar); }
.login .panel { width: 340px; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--sidebar); color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: none; color: #fff; font-size: 22px; }
  .content { padding: 16px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .doc { padding: 20px; }
  .doc .top { flex-direction: column; }
}

/* phones (screen only, so emailed / printed PDFs are not affected) */
@media screen and (max-width: 900px) {
  /* iPhone: 16px text stops Safari zooming into fields; room for the notch / home bar */
  input, select, textarea { font-size: 16px; }
  .topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
  .content { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .sidebar { padding-top: env(safe-area-inset-top); }
  .page-head h1 { font-size: 20px; }
  .actions .btn { padding: 9px 12px; }
  .selbar { bottom: calc(12px + env(safe-area-inset-bottom)); gap: 10px; font-size: 13px; }
  /* invoices / quotes / statements on screen: smaller type, swipe sideways if a line is still too wide */
  .doc { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .doc table { font-size: 13px; }
  .doc th, .doc td { padding: 7px 6px; }
  /* lists: swipe sideways for more columns; keep each cell on one line so rows stay short */
  .table-wrap > table:not(.editor) td, .table-wrap > table:not(.editor) th { white-space: nowrap; }
  /* order / invoice lines as stacked cards */
  table.editor, table.editor tbody { display: block; }
  table.editor thead { display: none; }
  table.editor tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; padding: 12px 34px 12px 0; border-bottom: 1px solid var(--line); position: relative; }
  table.editor td { display: block; border: none; padding: 0; text-align: left; }
  table.editor td::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
  table.editor td:nth-child(1), table.editor td:nth-child(2) { grid-column: 1 / -1; }
  table.editor td[data-net] { align-self: end; font-weight: 700; font-size: 16px; }
  table.editor td:last-child { position: absolute; top: 8px; right: 0; }
  table.editor td:last-child::before { content: none; }
  table.editor input, table.editor select { width: 100%; }
  table.editor .del { font-size: 26px; padding: 4px 8px; }
}

@media print {
  .sidebar, .topbar, .no-print, #toasts { display: none !important; }
  body, .content { background: #fff; padding: 0; }
  .panel, .doc { border: none; padding: 0; }
  th { position: static; }
}

td > strong, .nowrap { white-space: nowrap; }

/* "How to pay" box on invoices */
.paybox { margin-top: 24px; border: 2px solid var(--brand); border-radius: 10px; padding: 14px 18px; break-inside: avoid; }
.paybox-title { font-weight: 800; color: var(--brand); font-size: 15px; margin-bottom: 8px; }
.paybox-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.paybox-tbl { margin-top: 6px !important; }
.paybox-tbl td { padding: 3px 8px 3px 0; border: none; font-size: 13px; }
.paybox-tbl td:first-child { color: var(--muted); width: 110px; }
.paybtn { display: inline-block; background: var(--brand); color: #fff !important; font-weight: 700; padding: 10px 22px; border-radius: 8px; text-decoration: none !important; }
@media print { .paybox { border-color: var(--brand); } .paybtn { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
