:root {
  --bg: #f7f6f4; --panel: #ffffff; --ink: #1d1915; --muted: #6b625a; --line: #e7e2dc;
  --brand: #b4540a; --brand-ink: #ffffff; --brand-soft: #fdf1e4;
  --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --ok: #15803d; --ok-soft: #dcfce7;
  --side: #1f1710; --side-ink: #d9cfc6; --side-active: #3a2b1d;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12100e; --panel: #1b1815; --ink: #efe9e4; --muted: #a89c91; --line: #2f2a25;
    --brand: #f5a04a; --brand-ink: #2a1504; --brand-soft: #3a2614;
    --warn: #fbbf24; --warn-soft: #3a2e0f; --bad: #f87171; --bad-soft: #3b1414; --ok: #4ade80; --ok-soft: #12321e;
    --side: #0d0a07; --side-ink: #c4b8ad; --side-active: #33251a; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
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: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }

.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 700; font-size: 16px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: #b4540a; overflow: hidden; display: grid; place-items: center; font-size: 12px; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .55; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--side-ink); padding: 8px 10px; border-radius: 8px; }
.nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; font-weight: 600; }
.nav a .lock { font-size: 10px; background: #334; color: #ccd; padding: 1px 6px; border-radius: 99px; }
.main { min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.top .who { display: flex; align-items: center; gap: 10px; }
.btn.menu-btn { display: none; }
.content { padding: 24px; max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.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 .label { color: var(--muted); font-size: 12px; } .stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; }
.btn:hover { border-color: var(--brand); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); } .btn.sm { padding: 3px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: color-mix(in srgb, var(--brand-soft) 35%, transparent); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.table-wrap table { min-width: 640px; }
.card .table-wrap table { min-width: 0; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.grey { background: var(--line); color: var(--muted); }

form .row { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
label.f.full { grid-column: 1 / -1; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
input[type=checkbox] { width: auto; }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--ink) !important; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 14px; }
legend { font-weight: 600; padding: 0 6px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); font-weight: 600; text-decoration: none; }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; width: min(760px, 100%); max-height: 92vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.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: 0; font-size: 22px; cursor: pointer; color: var(--muted); }

#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; white-space: pre-line; }
.toast.bad { background: var(--bad); color: #fff; }

.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--warn-soft); color: var(--warn); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth { width: min(420px, 100%); }
.upsell { text-align: center; padding: 48px 24px; }
.upsell .icon { font-size: 36px; }
.pkg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.pkg { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: var(--panel); }
.pkg.current { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.pkg .price { font-size: 24px; font-weight: 700; margin: 6px 0; }
.pkg ul { padding-left: 18px; margin: 10px 0 0; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--brand); }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
pre.code { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 12px; }

.slip { max-width: 760px; margin: 0 auto; }
.slip table td, .slip table th { padding: 6px 8px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; z-index: 40; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .g2, .g3, .g4 { grid-template-columns: 1fr 1fr; }
  .content { padding: 16px; } .top { padding: 10px 16px; }
  .kv { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .top .who .muted { display: none; } .top { flex-wrap: wrap; } }
@media print {
  .side, .top, .no-print { display: none !important; }
  .layout { display: block; } .content { padding: 0; } .card { box-shadow: none; border: 0; }
  body { background: #fff; color: #000; }
}

.client-brand { display: grid; place-items: center; height: 72px; margin-bottom: 8px; }
.client-brand img { max-width: 220px; max-height: 72px; object-fit: contain; }


/* e-invoicing additions */
.brand .logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.brand .name { line-height: 1.2; } .brand .name small { display: block; font-weight: 500; font-size: 11px; opacity: .65; }
.badge.info { background: #e0ecff; color: #1d4ed8; }
@media (prefers-color-scheme: dark) { .badge.info { background: #172554; color: #93c5fd; } }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 12px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { border-color: transparent; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--panel); border: 2px solid var(--brand); }
.timeline .when { color: var(--muted); font-size: 12px; }
.problems { margin: 0; padding-left: 18px; } .problems li { margin: 2px 0; }
.lines-edit td { padding: 4px; } .lines-edit input, .lines-edit select { padding: 6px 8px; }
.lines-edit td.num { padding-right: 10px; }
.totals { margin-left: auto; width: min(340px, 100%); } .totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-weight: 700; font-size: 16px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; }
.conn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.conn-type { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer; background: var(--panel); text-align: left; font: inherit; color: inherit; }
.conn-type:hover { border-color: var(--brand); } .conn-type[disabled] { opacity: .55; cursor: not-allowed; }
.flow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.flow span.step { padding: 6px 10px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.copy { display: flex; gap: 6px; } .copy input { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 2px; }
.sim { background: #eef2ff; color: #3730a3; } @media (prefers-color-scheme: dark) { .sim { background: #1e1b4b; color: #c7d2fe; } }
.doc-print { background: #fff; color: #111; padding: 28px; border: 1px solid var(--line); border-radius: 8px; }
.doc-print table td, .doc-print table th { padding: 6px; border-bottom: 1px solid #ddd; background: none; color: #111; }
@media print { .modal-back { position: static; background: none; padding: 0; } .modal { box-shadow: none; max-height: none; width: 100% !important; }
  .modal header, .modal footer, #toast-root { display: none !important; } #app { display: none; } }

td.num, th.num { white-space: nowrap; }
.card .kv { grid-template-columns: minmax(90px, max-content) minmax(0, 1fr); }
.kv > div { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 1100px) { .grid.g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.g3 > .card:last-child:nth-child(odd) { grid-column: 1 / -1; } }
.grid > * { min-width: 0; }

/* ---------- top bar: app mark + company menu (same pattern as Sales CRM) ---------- */
.app-mark { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; white-space: nowrap; min-width: 0; }
.app-ic { width: 30px; height: 30px; border-radius: 8px; display: inline-grid; place-items: center; color: #fff; flex: none; }
.side .brand { padding: 4px 10px 18px; }
.top-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.top-mark { display: none; color: var(--ink); }
.top .usage { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .who { display: flex; align-items: center; gap: 10px; flex: none; }
.top .user-name { white-space: nowrap; }
#logout svg { display: none; }
.btn.menu-btn { padding: 6px 8px; }

.org { position: relative; }
.org-btn { display: inline-flex; align-items: center; gap: 8px; max-width: 280px; padding: 4px 10px 4px 4px; border: 1px solid var(--line); border-radius: 99px; background: var(--panel); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.org-btn:hover, .org-btn[aria-expanded="true"] { border-color: var(--brand); }
.org-av { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 13px; overflow: hidden; flex: none; }
.org-av img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.org-av.lg { width: 40px; height: 40px; font-size: 17px; }
.org-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-caret { display: inline-flex; color: var(--muted); }
.org-panel { position: absolute; right: 0; top: calc(100% + 8px); width: 340px; max-width: calc(100vw - 24px); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.18); padding: 14px; z-index: 30; }
.org-panel[hidden] { display: none; }
.org-head { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.org-title { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.org-tick { color: var(--ok); display: inline-flex; }
.org-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.org-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 0 8px; }
.org-apps { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.org-app { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; color: var(--ink); font-weight: 500; font-size: 13px; }
.org-app .app-ic { width: 26px; height: 26px; border-radius: 7px; }
.org-app:hover { background: var(--bg); text-decoration: none; }
.org-app.current { background: var(--brand-soft); }
.org-link { display: block; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; font-weight: 600; }

/* below ~1700px the company button is a round initial so nothing collides */
@media (max-width: 1700px) {
  .org-btn { padding: 0; border-radius: 50%; width: 32px; height: 32px; justify-content: center; }
  .org-btn .org-name, .org-btn .org-caret { display: none; }
  .org-btn .org-av { width: 30px; height: 30px; }
}
@media (max-width: 1100px) { .top .usage { display: none; } }
@media (max-width: 900px) {
  .top-mark { display: inline-flex; }
  .org-panel { position: fixed; top: 58px; right: 12px; }
}
@media (max-width: 520px) {
  .top { flex-wrap: nowrap; }
  .top-mark .app-word { display: none; }
  .top .user-name { display: none; }
  #logout svg { display: inline; } #logout .lbl { display: none; } #logout { padding: 6px 8px; }
}
