:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #1d2433;
  --ink-2: #4a5468;
  --muted: #7b8496;
  --line: #e3e7ef;
  --line-2: #eef1f6;
  --primary: #2f6fed;
  --primary-ink: #ffffff;
  --primary-soft: #eaf1ff;
  --ok: #1f9d55;
  --ok-soft: #e4f6ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --bad: #d64545;
  --bad-soft: #fdeaea;
  --info: #5b57d1;
  --info-soft: #ecebfb;
  --side: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .05), 0 2px 8px rgba(20, 30, 60, .04);
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Noto Sans", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 15px; margin: 0; font-weight: 650; }
small, .small { font-size: 12px; }
.muted { color: var(--muted); }
.ok-t { color: var(--ok); } .bad-t { color: var(--bad); } .warn-t { color: var(--warn); }
.center { text-align: center; }
.mt { margin-top: 12px; }
.ic { flex: none; vertical-align: middle; }
[hidden] { display: none !important; }

/* layout */
.app { display: flex; min-height: 100vh; }
.side { width: 252px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #2f6fed, #6a4cf0); color: #fff; display: grid; place-items: center; font-weight: 800; }
.company-switch { border: 1px solid var(--line); border-radius: var(--radius); background: #fafbfd; }
.company-switch summary { list-style: none; cursor: pointer; padding: 10px 12px; display: flex; flex-direction: column; }
.company-switch summary::-webkit-details-marker { display: none; }
.cs-title { font-weight: 650; }
.cs-sub { font-size: 12px; color: var(--muted); }
.cs-menu { border-top: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; }
.cs-menu form { margin: 0; }
.cs-menu button, .cs-menu a { display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; background: none; border: 0; padding: 8px; border-radius: 8px; font: inherit; color: var(--ink); cursor: pointer; }
.cs-menu button:hover, .cs-menu a:hover { background: var(--line-2); text-decoration: none; }
.cs-menu small { color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 10px 4px; font-weight: 600; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav-item:hover { background: var(--line-2); text-decoration: none; color: var(--ink); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.side-user { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 10px 6px 0; border-top: 1px solid var(--line); }
.side-user form { margin: 0 0 0 auto; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--info-soft); color: var(--info); display: grid; place-items: center; font-weight: 700; }
.su-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.85); backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 20; }
.global-search { flex: 1; max-width: 560px; display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; color: var(--muted); }
.global-search input { border: 0; background: transparent; padding: 9px 0; width: 100%; font: inherit; outline: none; color: var(--ink); }
.top-company { font-weight: 600; margin-left: auto; }
.content { padding: 24px; max-width: 1400px; width: 100%; }
.only-mobile { display: none !important; }
.backdrop { display: none; }

/* components */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.flush { padding: 0; overflow-x: auto; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card.empty { text-align: center; padding: 40px; color: var(--ink-2); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { background: #f7f9fc; text-decoration: none; border-color: #d4dae5; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: #255fd6; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--line-2); color: var(--ink); }
.icon-btn.ok:hover { color: var(--ok); background: var(--ok-soft); }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; font: inherit; }
.inline { display: inline; margin: 0; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; letter-spacing: .01em; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: var(--line-2); color: var(--muted); }
.badge.draft { background: #fff6d8; color: #8a6d00; }
.flash { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.flash.success { background: var(--ok-soft); border-color: #bfe8cf; color: #146c3c; }
.flash.error { background: var(--bad-soft); border-color: #f4c4c4; color: #9d2b2b; }
.flash.info { background: var(--primary-soft); border-color: #cfdcfb; color: #1f4fb4; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin: 0 4px 0 10px; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }

/* forms */
label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; color: var(--ink-2); }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #d6dce7; border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,111,237,.15); }
textarea { resize: vertical; }
input.num { text-align: right; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; margin-top: 12px; }
label.check input { width: auto; }
.form-grid { display: grid; gap: 14px; }
.form-grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span3 { grid-column: span 3; }
.form-grid .kred-only { display: contents; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-l > .card:last-child { margin-bottom: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.form-actions.sticky { position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 70%, transparent); padding: 14px 0 6px; z-index: 5; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 2px 8px; font-size: 12px; cursor: pointer; color: var(--ink-2); }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { flex-direction: row; align-items: center; gap: 6px; padding: 6px 12px; cursor: pointer; font-weight: 500; }
.seg label input { width: auto; margin: 0; }
.seg label:has(input:checked) { background: var(--primary-soft); color: var(--primary); }

/* autocomplete */
.ac-wrap { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; margin-top: 4px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(20,30,60,.14); max-height: 280px; overflow-y: auto; }
.ac-item { padding: 8px 10px; cursor: pointer; display: flex; flex-direction: column; font-weight: 500; color: var(--ink); }
.ac-item small { color: var(--muted); font-weight: 400; }
.ac-item:hover, .ac-item.on { background: var(--primary-soft); }

/* tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfd; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; white-space: nowrap; }
.table th { white-space: nowrap; }
.table td.wrap { white-space: normal; }
.table .num { text-align: right; white-space: nowrap; }
.table .act { text-align: right; white-space: nowrap; width: 1%; }
.table .clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table tr.group td { background: #f7f9fc; font-size: 13px; color: var(--ink-2); padding: 9px 12px; }
.table tr.group .g-right { float: right; }
.table .count { display: inline-grid; place-items: center; min-width: 22px; height: 22px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 11px; margin-left: 6px; padding: 0 6px; }
.rows-link tbody tr[data-href] { cursor: pointer; }
.rows-link tbody tr[data-href]:hover td { background: #f9fbff; }
.table tr.nullified td { color: var(--muted); }
.table tr.nullified strong { text-decoration: line-through; }
.table.compact td, .table.compact th { padding: 6px 8px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px; }
.filters select { width: auto; }
.f-search { display: flex; align-items: center; gap: 6px; border: 1px solid #d6dce7; border-radius: 8px; padding: 0 10px; flex: 1; min-width: 220px; color: var(--muted); background: #fff; }
.f-search input { border: 0; box-shadow: none !important; padding: 8px 0; }
.sumbar { display: flex; gap: 20px; flex-wrap: wrap; margin: 0 0 10px; color: var(--ink-2); }
.pager { display: flex; gap: 4px; justify-content: center; margin: 16px 0; flex-wrap: wrap; }
.pager a, .pager span { min-width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); background: #fff; padding: 0 8px; }
.pager .cur { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager .gap { border: 0; background: transparent; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-2); align-items: center; }
.list li:last-child { border-bottom: 0; }
.list li a { color: var(--ink); display: flex; gap: 8px; min-width: 0; }
.list li a span { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .r { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.list.small li { font-size: 12.5px; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; text-align: right; }
.note-box { margin-top: 12px; background: #fffbea; border: 1px solid #f3e3a5; border-radius: 8px; padding: 10px; font-size: 13px; }

/* dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.kpi span { color: var(--muted); font-size: 12.5px; }
.kpi strong { font-size: 22px; letter-spacing: -.01em; }
.kpi small { color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.chart { width: 100%; height: auto; display: block; margin-bottom: 12px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .bar-in { fill: var(--primary); }
.chart .bar-out { fill: #f0a35e; }
.legend { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.lg-in { background: var(--primary); } .lg-out { background: #f0a35e; }

/* invoice form */
.lines-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.lines { width: 100%; border-collapse: collapse; min-width: 760px; }
.lines th { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 4px; font-weight: 650; letter-spacing: .04em; }
.lines td { padding: 6px 4px; vertical-align: top; border-top: 1px solid var(--line-2); }
.lines .l-title { width: 38%; }
.lines .l-qty { width: 8%; } .lines .l-unit { width: 8%; } .lines .l-price { width: 13%; } .lines .l-disc { width: 7%; } .lines .l-vat { width: 9%; }
.lines .l-sum { width: 12%; text-align: right; font-weight: 600; padding-top: 14px; white-space: nowrap; }
.lines .ln-desc { margin-top: 6px; font-size: 13px; }
.lines .toggle-desc { margin-top: 4px; font-size: 12px; }
.no-vat .vat-col { display: none; }
.totals { margin-left: auto; max-width: 360px; margin-top: 16px; display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; }
.totals .t-label { color: var(--ink-2); text-align: right; }
.totals .t-val { text-align: right; font-variant-numeric: tabular-nums; }
.totals .t-grand { font-size: 18px; font-weight: 700; color: var(--ink); }

/* show */
.show-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.preview iframe { width: 100%; height: 82vh; min-height: 560px; border: 0; display: block; background: #e9ecf2; }
.big-total { font-size: 28px; font-weight: 700; margin-bottom: 8px; letter-spacing: -.01em; }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 34px rgba(20,30,60,.16); padding: 6px; min-width: 270px; z-index: 40; display: flex; flex-direction: column; }
.menu-list a, .menu-list button { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--ink); background: none; border: 0; font: inherit; text-align: left; cursor: pointer; width: 100%; }
.menu-list a:hover, .menu-list button:hover { background: var(--line-2); text-decoration: none; }
.menu-list form { margin: 0; }
.menu-list .danger { color: var(--bad); }
.addpay summary { cursor: pointer; margin-top: 8px; list-style: none; }
.dlg { border: 0; border-radius: 14px; padding: 20px; width: min(620px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(10,20,50,.3); }
.dlg::backdrop { background: rgba(15, 23, 42, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; border-bottom: 2px solid transparent; color: var(--ink-2); font-weight: 550; }
.tabs a.on { border-color: var(--primary); color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.file { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; gap: 8px; align-items: center; background: #fafbfd; }
.file a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.dropzone { border: 2px dashed #c9d3e6; border-radius: 12px; padding: 22px; text-align: center; background: #fafcff; color: var(--ink-2); }
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.logo-prev { max-height: 70px; max-width: 220px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
code { background: var(--line-2); padding: 2px 6px; border-radius: 6px; font-size: 12.5px; word-break: break-all; }

/* auth / public */
body.bare { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.bare-wrap { width: 100%; max-width: 420px; }
.auth-card { padding: 28px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.public-wrap { width: 100%; max-width: 900px; display: flex; flex-direction: column; gap: 0; }
body.public { place-items: start center; }
.public .dl dd { text-align: left; }

@media (max-width: 1200px) {
  .hide-md { display: none; }
}
@media (max-width: 1100px) {
  .grid-2, .show-grid { grid-template-columns: 1fr; }
  .preview iframe { height: 70vh; }
}
@media (max-width: 860px) {
  .only-mobile { display: inline-grid !important; }
  span.only-mobile { display: inline !important; }
  .side { position: fixed; z-index: 60; left: 0; top: 0; bottom: 0; transform: translateX(-105%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  body.side-open .side { transform: none; }
  body.side-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 50; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px; }
  .form-grid.g3, .form-grid.g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hide-sm { display: none; }
  .show-grid > .preview { display: none; }
  .head-actions .btn { padding: 8px 11px; }
  .table .clip { max-width: 140px; }
  .table tr.group .g-right { float: none; display: block; margin-top: 2px; }
}
@media (max-width: 560px) {
  .form-grid.g2, .form-grid.g3, .form-grid.g4 { grid-template-columns: 1fr; }
  .form-grid .span2, .form-grid .span3 { grid-column: auto; }
  h1 { font-size: 19px; }
  .table th, .table td { padding: 8px; }
  .kpi strong { font-size: 19px; }
  .global-search { display: none; }
}
@media print {
  .side, .topbar, .head-actions, .form-actions { display: none !important; }
  .content { padding: 0; }
}
