/* WP-Invoicer web — blue accent like the iOS app (#0A5BD3, dark #4A94FF). */
:root {
  --accent: #0a5bd3;
  --accent-strong: #0849ab;
  --accent-soft: #e8f0fc;
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e1e5eb;
  --text: #15181d;
  --text-2: #5b6472;
  --text-3: #8a93a1;
  --green: #1d8a4e;
  --green-soft: #e3f4ea;
  --orange: #c45a00;
  --orange-soft: #fdeedd;
  --red: #c62828;
  --red-soft: #fbe6e6;
  --gray-soft: #eceef2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --chart-1: #0a5bd3;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #4a94ff;
    --accent-strong: #79b0ff;
    --accent-soft: #15284a;
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #1d222b;
    --border: #2a303b;
    --text: #e9edf3;
    --text-2: #a4adbb;
    --text-3: #7c8594;
    --green: #4cc480;
    --green-soft: #133624;
    --orange: #ff9f45;
    --orange-soft: #3d2610;
    --red: #ff6b6b;
    --red-soft: #3f1a1a;
    --gray-soft: #262c36;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
    --chart-1: #3d86f5;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 8px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 13px; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.boot { height: 100vh; display: grid; place-items: center; }
.boot-logo { width: 220px; opacity: .85; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh;
  background: linear-gradient(to right, var(--surface) 235px, var(--border) 235px, var(--border) 236px, var(--bg) 236px); }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 4px 10px 18px; }
.sidebar .brand img { width: 150px; display: block; }
.org-switch { margin: 0 6px 12px; }
.org-switch select { width: 100%; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 19px; height: 19px; flex: none; }
.sidebar .footer { margin-top: auto; padding: 10px; font-size: 13px; color: var(--text-2); }
.sidebar .footer .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 6px; }

.main { padding: 28px 32px 60px; min-width: 0; }
.page { max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head .title { flex: 1; min-width: 200px; }
.page-head .title p { margin: 4px 0 0; color: var(--text-2); }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 14px; margin-bottom: 6px; }

.mobile-bar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; background: var(--bg); }
  .sidebar { display: none; }
  .mobile-bar {
    display: flex; position: sticky; top: 0; z-index: 5;
    align-items: center; gap: 10px; padding: 10px 14px;
    background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .mobile-bar img { height: 26px; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .mobile-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--text-2); padding: 4px 0; }
  .mobile-nav a.active { color: var(--accent); }
  .mobile-nav svg { width: 22px; height: 22px; }
  .main { padding: 18px 14px 90px; }
}
@media (min-width: 861px) { .mobile-nav { display: none; } }

/* ---------- Cards, tables ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { flex: 1; }

table.list { width: 100%; border-collapse: collapse; }
.list th {
  text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.list td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.list tr:last-child td { border-bottom: none; }
.list tbody tr.click { cursor: pointer; }
.list tbody tr.click:hover td { background: var(--surface-2); }
.list tfoot td { font-weight: 650; border-top: 2px solid var(--border); border-bottom: none; }
.list .sub { color: var(--text-2); font-size: 13px; }
.table-wrap { overflow-x: auto; }
.empty { padding: 40px 20px; text-align: center; color: var(--text-2); }
.empty h3 { color: var(--text); margin-bottom: 6px; }

/* ---------- Buttons & forms ---------- */
button, .btn {
  font: inherit; font-weight: 550; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: 9px; padding: 8px 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button svg, .btn svg { width: 17px; height: 17px; }
.btn-primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover, button.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button.danger { color: var(--red); }
button.danger:hover { background: var(--red-soft); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.icon { padding: 7px; }
button.small { padding: 5px 10px; font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 550; color: var(--text-2); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: auto; }
input.num { text-align: right; }
.grid { display: grid; gap: 14px; }
.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)); }
.span2 { grid-column: span 2; }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }
.hint { font-size: 12.5px; color: var(--text-2); font-weight: 400; }
.hint.ok { color: var(--green); }
.hint.bad { color: var(--orange); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 280px; }
.segmented { display: inline-flex; background: var(--gray-soft); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button { border: none; background: transparent; padding: 5px 12px; font-size: 13.5px; border-radius: 7px; color: var(--text-2); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); font-weight: 500; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge.open { background: var(--accent-soft); color: var(--accent); }
.badge.overdue { background: var(--orange-soft); color: var(--orange); }
.badge.paid { background: var(--green-soft); color: var(--green); }
.badge.cancelled { background: var(--gray-soft); color: var(--text-2); }
.badge.sent { background: #efe7fd; color: #6a3fc7; }
@media (prefers-color-scheme: dark) { .badge.sent { background: #2d2346; color: #b79cf5; } }

/* ---------- Tiles & charts ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 900px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { padding: 16px 18px; }
.tile .label { font-size: 13px; color: var(--text-2); font-weight: 550; }
.tile .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile .sub { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--chart-1); }
.chart rect[tabindex]:focus { outline: none; }
.chart rect[tabindex]:focus-visible { stroke: var(--text-2); stroke-width: 1; }
.chart .bar-paid { fill: var(--green); }
.chart .axis { stroke: var(--border); }
.chart text { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .tip { pointer-events: none; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- Invoice detail & editor ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .detail { grid-template-columns: 1fr; } }
.pdf-frame { width: 100%; height: 78vh; min-height: 560px; border: none; border-radius: var(--radius); background: var(--surface-2); display: block; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.actions button { justify-content: flex-start; }
.accounting { border-radius: 10px; padding: 10px 12px; font-size: 13.5px; background: var(--surface-2); }
.accounting.ok { background: var(--green-soft); }
.accounting.fail { background: var(--orange-soft); }

.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); text-align: left; padding: 6px 6px; }
.lines td { padding: 5px 6px; vertical-align: top; }
.lines td.amount { padding-top: 13px; }
.lines textarea { min-height: 38px; height: 38px; }
.lines .c-qty { width: 86px; } .lines .c-unit { width: 120px; } .lines .c-price { width: 120px; }
.lines .c-vat { width: 96px; } .lines .c-total { width: 110px; } .lines .c-del { width: 40px; }
@media (max-width: 760px) {
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .lines td { padding: 0; width: auto !important; }
  .lines td.c-text { grid-column: 1 / -1; }
}
.totals { margin-left: auto; width: min(360px, 100%); display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; font-size: 14px; }
.totals .grand { font-size: 17px; font-weight: 700; border-top: 2px solid var(--border); padding-top: 8px; }

/* ---------- Modal & toast ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 20; background: rgba(10, 14, 22, .45);
  display: grid; place-items: center; padding: 16px;
}
.modal { width: min(560px, 100%); max-height: 92vh; overflow: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); }
.modal .card-head { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal .foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); }
#toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1c2230; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 14px; max-width: 90vw; }
.toast.error { background: #a32020; }
.banner { padding: 10px 14px; border-radius: 10px; background: var(--orange-soft); color: var(--orange); font-size: 14px; }
.banner.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- Sign-in ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(420px, 100%); padding: 32px 30px; margin: 0 auto; }
.auth-card .logo { width: 190px; display: block; margin: 0 auto 22px; }
.auth-card h1 { font-size: 22px; text-align: center; margin-bottom: 6px; }
.auth-card .lead { text-align: center; color: var(--text-2); margin-bottom: 22px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card button.primary { padding: 11px; font-size: 16px; }
.qr-box { background: #fff; border-radius: 14px; padding: 10px; width: 236px; margin: 0 auto 16px; border: 1px solid var(--border); }
.qr-box svg { width: 100%; height: auto; display: block; }
.steps { margin: 0 0 16px; padding-left: 20px; color: var(--text-2); font-size: 14px; }
.steps li { margin-bottom: 4px; }
.countdown { text-align: center; font-size: 13px; color: var(--text-3); margin-bottom: 12px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-3); }
.error-text { color: var(--red); font-size: 14px; text-align: center; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Print (reports) ---------- */
/* ---------------------------------------------------------------- spreadsheet import */
.modal.wide { width: min(1000px, 100%); }
.modal .foot { position: sticky; bottom: 0; background: var(--surface); }
.empty-actions { margin-top: 14px; display: flex; justify-content: center; }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 30px 20px; text-align: center;
  border: 2px dashed var(--border); border-radius: 14px; cursor: pointer; background: var(--surface-2); transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.dropzone .dz-icon svg { width: 34px; height: 34px; color: var(--accent); }
.map-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.preview-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.list.compact th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.list.compact td { padding: 7px 10px; font-size: 13.5px; vertical-align: top; }
.list.compact td.note { color: var(--text-2); font-size: 12.5px; min-width: 180px; }
.list.compact td.note.bad, .modal .hint.bad { color: var(--red); }
.list.compact tr.bad td { background: var(--red-soft); }
.progress { flex: 1; height: 8px; border-radius: 99px; background: var(--gray-soft); overflow: hidden; min-width: 120px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.row.grow { flex: 1; }
@media (max-width: 720px) { .map-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 460px) { .map-grid { grid-template-columns: minmax(0, 1fr); } }

@media print {
  body { background: #fff; color: #000; font-size: 11px; }
  .sidebar, .mobile-bar, .mobile-nav, .no-print, #toast { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .card { border: none; box-shadow: none; }
  .list th, .list td { padding: 4px 6px; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
button.danger-fill { background: var(--red); border-color: var(--red); color: #fff; }
button.danger-fill:hover { background: var(--red); filter: brightness(.92); }
.list th.num { text-align: right; }
.list td.mono { white-space: nowrap; }
.segmented { max-width: 100%; }
@media (max-width: 700px) {
  .list .hide-sm { display: none; }
  .list th, .list td { padding: 10px 10px; }
  .toolbar input[type=search] { max-width: none; }
}
.shell > div { min-width: 0; }
@media (max-width: 700px) {
  .page-head .title { min-width: 0; flex-basis: 100%; }
  .mobile-bar img { height: 30px; }
}
.show-sm { display: none; }
@media (max-width: 700px) { .show-sm { display: block; margin-top: 4px; font-family: var(--font); } }
@media (prefers-color-scheme: dark) {
  .sidebar .brand img, .mobile-bar img, .auth-card .logo, .boot-logo { background: #fff; border-radius: 10px; padding: 6px 10px; }
}

/* ---------------------------------------------------------------- discounts */
.disc { display: flex; gap: 4px; align-items: center; }
.disc input { width: 76px; }
.disc select { width: 72px; }
.lines .c-disc { width: 156px; }

/* ---------------------------------------------------------------- countries */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 12px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 550; }
.chip button.icon { width: 26px; height: 26px; padding: 0; color: inherit; }
.chip button.icon svg { width: 14px; height: 14px; }

/* ---------------------------------------------------------------- item suggestions in invoice lines */
.lines td.c-text { position: relative; }
.suggest { position: absolute; left: 6px; right: 6px; top: calc(100% - 2px); z-index: 20; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 4px; max-height: 280px; overflow: auto; }
.suggest-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); padding: 6px 10px 4px; }
.suggest-item { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.suggest-item .meta { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.suggest-item:hover, .suggest-item.on { background: var(--accent-soft); }
.suggest-item.on .name, .suggest-item:hover .name { color: var(--accent); }

/* Unit of measure picker (drop-down, plus a text field for "Other …") */
.unit-pick { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.unit-pick select, .unit-pick input { width: 100%; min-width: 0; }
.units-table td { vertical-align: middle; }
.units-table input[type=text], .units-table input:not([type]) { width: 100%; }
.units-table .code { color: var(--text); opacity: .6; font-family: var(--mono, ui-monospace, monospace); font-size: 12px; }
.units-wrap { max-height: 520px; overflow: auto; }
.units-table td { padding-top: 6px; padding-bottom: 6px; }
.units-table thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
