:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #fbfcfb;
  --border: #e3e7e2;
  --border-strong: #cfd6cf;
  --text: #1c2621;
  --text-soft: #55635b;
  --muted: #7b877f;
  --accent: #0f766e;
  --accent-strong: #0b5d57;
  --accent-soft: #e7f5f2;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --ok: #067647;
  --ok-soft: #ecfdf3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.02rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75rem; }
p:last-child { margin-bottom: 0; }
code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }

.shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: #10201b;
  color: #d7e2dc;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  padding: 4px 8px 18px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(140deg, #14b8a6, #0f766e);
  color: #fff;
  font-weight: 750;
  font-size: 1.05rem;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
}
.brand-text { font-weight: 700; letter-spacing: .01em; font-size: 1.1rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: #b7c6be;
  font-size: .92rem;
  text-decoration: none;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(20, 184, 166, .16); color: #eafffa; box-shadow: inset 2px 0 0 #2dd4bf; }
.nav-icon { width: 18px; text-align: center; opacity: .85; font-size: .95rem; }
.nav-sep { height: 1px; background: rgba(255,255,255,.08); margin: 10px 6px; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 4px 6px 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(45, 212, 191, .18);
  color: #ccfbf1; display: inline-flex; align-items: center; justify-content: center;
  font-size: .76rem; font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-meta strong { color: #f0fdfa; font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: #8fa49a; font-size: .7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-form { padding: 0 6px; }
.version { color: #64806f; font-size: .66rem; padding: 10px 8px 0; }

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 32px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 24px 0 16px;
}
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: .82rem; }
.topbar-actions { display: flex; gap: 8px; }
.content { padding-bottom: 28px; }
.page-foot {
  margin-top: auto; display: flex; justify-content: space-between;
  padding: 18px 0 22px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: .72rem;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card-narrow { max-width: 640px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.card-head h2 { font-size: .98rem; }
.card-head.mt-s { margin-top: 20px; }
.mt { margin-top: 16px; }
.mt-s { margin-top: 10px; }
.empty-state { text-align: center; padding: 42px 24px; }
.empty-state h3 { margin-bottom: 6px; }
.empty-state p { color: var(--muted); margin-bottom: 16px; }
.empty { color: var(--muted); font-size: .9rem; padding: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.strong { font-weight: 600; }

/* Grids */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* Stats */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-sub { color: var(--text-soft); font-size: .78rem; }
.stat-warn { border-color: #f4c7a1; background: linear-gradient(180deg, #fff, var(--warn-soft)); }
.stat-warn .stat-value { color: var(--warn); }

/* Toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar-search { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar-search input[type=search] { min-width: 260px; }
.toolbar-search-wide input[type=search] { min-width: 220px; }
.toolbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.input-year { width: 90px; }
.month-nav { display: flex; align-items: center; gap: 10px; }
.month-current { font-weight: 650; min-width: 170px; text-align: center; }
.page-actions { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.card .table-wrap { margin: 0 -18px -18px; }
.card .table { margin: 0; }
.table th {
  text-align: left; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); font-weight: 650;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-hover tbody tr:hover { background: #f8faf9; }
.table tfoot td { background: var(--surface-2); font-weight: 600; border-top: 1px solid var(--border-strong); }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .check { width: 36px; text-align: center; }
.table-tight td, .table-tight th { padding: 8px 10px; }
.table .desc { max-width: 420px; }
.table .grand td { font-size: 1rem; }
.card > .table-wrap:last-child { border-radius: 0 0 var(--radius) var(--radius); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.list-main small { color: var(--muted); font-size: .76rem; }
.list-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.compact-list { margin: 0; padding-left: 18px; font-size: .86rem; color: var(--text-soft); }
.compact-list li { margin: 3px 0; }
.report-list { color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: inherit; font-size: .88rem; font-weight: 550;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, transform .05s ease;
}
.btn:hover { background: var(--surface-2); text-decoration: none; border-color: #b9c3bb; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent-strong); }
.btn-danger { background: var(--danger-soft); border-color: #fda29b; color: var(--danger); }
.btn-danger:hover { background: #fee4e2; }
.btn-sm { padding: 6px 10px; font-size: .82rem; }
.btn-block { width: 100%; }
.btn-active { background: var(--accent-soft); border-color: #99e0d6; color: var(--accent-strong); }
.btn-link, .btn-link-danger {
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit;
  font-size: .82rem; color: var(--accent); text-decoration: underline;
}
.btn-link-danger { color: var(--danger); }
.inline-form { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.inline-form + .inline-form { margin-left: 8px; }
.link { font-size: .84rem; font-weight: 550; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: .7rem; font-weight: 650; letter-spacing: .01em;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-draft { background: #f2f4f7; color: #475467; border-color: #e4e7ec; }
.badge-open { background: #eff8ff; color: #175cd3; border-color: #b2ddff; }
.badge-partial { background: var(--warn-soft); color: var(--warn); border-color: #fedf89; }
.badge-paid { background: var(--ok-soft); color: var(--ok); border-color: #abefc6; }
.badge-overdue { background: var(--danger-soft); color: var(--danger); border-color: #fecdca; }
.badge-cancelled { background: #f9fafb; color: #667085; border-color: #e4e7ec; text-decoration: line-through; }
.badge-imported { background: #f4f3ff; color: #5925dc; border-color: #d9d6fe; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-section { display: flex; flex-direction: column; gap: 12px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: 0; padding-bottom: 0; }
.form-section h2 { margin-bottom: 2px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-compact { gap: 10px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .82rem; font-weight: 600; color: var(--text-soft); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=date], input[type=file], select, textarea {
  font: inherit; font-size: .9rem; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 10px; width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}
textarea { resize: vertical; }
input[disabled] { background: var(--surface-2); color: var(--muted); }
.checkbox-label { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; padding-top: 20px; }
.checkbox-label input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; align-items: center; margin-top: 4px; }
.form-actions-left { justify-content: flex-start; }
.hint { color: var(--muted); font-size: .78rem; }
.hint-block { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.hint-block h4 { margin-bottom: 6px; }
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: .87rem; border: 1px solid transparent; margin-bottom: 14px; }
.alert-err { background: var(--danger-soft); color: var(--danger); border-color: #fecdca; }
.alert-info { background: #eff8ff; color: #175cd3; border-color: #b2ddff; }
.flash {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px;
  border-radius: var(--radius-sm); border: 1px solid transparent; margin-bottom: 14px; font-size: .87rem;
}
.flash-ok { background: var(--ok-soft); color: #05603a; border-color: #abefc6; }
.flash-err { background: var(--danger-soft); color: var(--danger); border-color: #fecdca; }
.flash-info { background: #eff8ff; color: #175cd3; border-color: #b2ddff; }
.flash-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: 0 0 8px; }
.flash-close { margin-left: auto; background: none; border: 0; font-size: 1.1rem; line-height: 1; color: inherit; cursor: pointer; opacity: .6; }
.flash-close:hover { opacity: 1; }

/* Facts */
.facts { display: flex; flex-wrap: wrap; gap: 18px; margin: 12px 0 0; }
.facts > div { display: flex; flex-direction: column; gap: 1px; }
.facts dt { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.facts dd { margin: 0; font-size: .88rem; font-weight: 550; }
.facts-vertical { flex-direction: column; gap: 10px; }
.address { display: flex; flex-direction: column; gap: 1px; font-style: normal; font-size: .88rem; color: var(--text-soft); margin: 10px 0 0; }
.address strong { color: var(--text); font-size: .95rem; margin-bottom: 2px; }

/* Dashboard extras */
.kpi-row { display: flex; gap: 12px; margin: 12px 0 14px; }
.kpi { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; display: flex; flex-direction: column; }
.kpi-value { font-weight: 700; font-size: 1.05rem; }
.kpi-label { color: var(--muted); font-size: .72rem; }
.totals-bar {
  display: flex; gap: 22px; flex-wrap: wrap; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 16px; margin-bottom: 14px; font-size: .86rem; color: var(--text-soft);
}
.totals-bar strong { color: var(--text); }
.sticky-actions { position: sticky; bottom: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-top: 12px; box-shadow: 0 -2px 12px rgba(16,24,40,.05); }
.sticky-actions .muted { font-size: .78rem; max-width: 620px; }
.detail-row td { background: var(--surface-2); padding: 4px 12px 14px; }
.detail-block { margin: 6px 0; }
.detail-block h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; }

/* Invoice detail */
.invoice-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.invoice-number { font-family: var(--mono); font-size: .82rem; color: var(--accent-strong); background: var(--accent-soft); padding: 2px 8px; border-radius: 5px; display: inline-block; margin-bottom: 6px; }
.invoice-head h2 { font-size: 1.2rem; }
.invoice-meta { min-width: 260px; }
.invoice-meta .facts { margin-top: 0; }
.items-table td { padding: 8px; }
.items-table input[type=text], .items-table select { padding: 6px 8px; font-size: .85rem; }
.items-table .w-qty { width: 80px; }
.items-table .w-unit { width: 92px; }
.items-table .w-price { width: 110px; }
.items-table .w-vat { width: 86px; }
.items-table td:first-child input + input { margin-top: 4px; }
.totals-box { margin: 16px 0 0 auto; max-width: 320px; display: flex; flex-direction: column; gap: 6px; }
.totals-box > div { display: flex; justify-content: space-between; font-size: .9rem; color: var(--text-soft); }
.totals-box .grand { border-top: 1px solid var(--border-strong); padding-top: 6px; font-size: 1.05rem; color: var(--text); }
.invoice-notes { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--text-soft); font-size: .88rem; white-space: pre-wrap; }

/* Import */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: .76rem; font-family: var(--mono); color: var(--text-soft); }
.logo-preview { display: flex; align-items: flex-end; padding-bottom: 8px; }
.error-code { display: block; font-size: 2.4rem; font-weight: 750; color: var(--border-strong); letter-spacing: -.03em; }

/* Auth */
.auth-body { background: radial-gradient(900px 500px at 50% -10%, #d9f0ec 0%, transparent 65%), var(--bg); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px 18px; }
.auth-wrap { width: 100%; max-width: 520px; }
.auth-brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 22px; }
.auth-brand strong { display: block; font-size: 1.15rem; }
.auth-brand small { color: var(--muted); font-size: .76rem; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 18px 50px rgba(16,24,40,.08); padding: 28px; }
.auth-card h1 { margin-bottom: 6px; }
.lead { color: var(--muted); font-size: .88rem; margin: 4px 0 18px; }
.auth-foot { text-align: center; color: var(--muted); font-size: .72rem; margin-top: 18px; }

/* Public */
.public-body { background: radial-gradient(800px 400px at 50% 0%, #e3f4f0 0%, transparent 60%), var(--bg); min-height: 100vh; }
.public-wrap { max-width: 720px; margin: 0 auto; padding: 28px 18px 40px; }
.public-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.public-company { font-weight: 700; }
.public-secure { margin-left: auto; color: var(--muted); font-size: .76rem; }
.public-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 18px 50px rgba(16,24,40,.08); padding: 28px; }
.public-invoice-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; border-bottom: 1px solid var(--border); padding-bottom: 18px; margin-bottom: 4px; }
.public-invoice-head h1 { font-family: var(--mono); font-size: 1.35rem; margin: 2px 0; }
.public-amount { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.public-amount strong { font-size: 1.5rem; letter-spacing: -.02em; }
.public-facts { margin: 16px 0 20px; }
.secure-box { background: var(--accent-soft); border: 1px solid #c3ece6; border-radius: var(--radius); padding: 18px; }
.secure-box h2 { margin-bottom: 6px; }
.secure-box p { color: var(--text-soft); font-size: .88rem; }
.public-contact { margin-top: 18px; font-size: .8rem; text-align: center; }
.public-foot { text-align: center; color: var(--muted); font-size: .74rem; margin-top: 20px; }
.code-form { margin: 16px 0 10px; }
.code-input { font-family: var(--mono); font-size: 1.6rem !important; letter-spacing: .5em; text-align: center; padding: 10px !important; }

/* Responsive */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; padding: 12px 14px; }
  .brand { padding-bottom: 10px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-item { padding: 7px 9px; }
  .nav-sep { display: none; }
  .sidebar-foot { display: none; }
  .main { padding: 0 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .form-row, .form-row-3 { grid-template-columns: minmax(0, 1fr); }
  .invoice-head, .public-invoice-head { flex-direction: column; }
  .invoice-meta, .public-amount { text-align: left; align-items: flex-start; min-width: 0; }
  .topbar { padding-top: 18px; flex-wrap: wrap; }
  .toolbar-search input[type=search] { min-width: 0; flex: 1; }
  .card .table-wrap { margin: 0 -18px -18px; }
  .checkbox-label { padding-top: 0; }
}

@media print {
  .sidebar, .topbar, .page-actions, .page-foot, .toolbar, .form-actions, .flash { display: none !important; }
  .main { padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
}
