:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #182033;
  --muted: #687386;
  --line: #dce2eb;
  --accent: #1967d2;
  --accent-dark: #1251a6;
  --danger: #b42318;
  --ok: #13795b;
  --shadow: 0 18px 40px rgba(31, 45, 61, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 248px; padding: 22px 18px;
  background: #121a2a; color: white; display: flex; flex-direction: column; gap: 24px;
  transition: width .18s ease, padding .18s ease;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; justify-content: center; color: white; font-weight: 800; font-size: 18px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 96px; height: 58px; border-radius: 8px; background: white; overflow: hidden; flex: 0 0 auto; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.brand-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-toggle { display: grid; place-items: center; width: 34px; min-height: 34px; padding: 0; flex: 0 0 auto; border-color: rgba(255,255,255,.2); background: rgba(255,255,255,.06); color: white; font-size: 24px; line-height: 1; }
.sidebar-toggle:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.32); }
.sidebar nav { display: grid; gap: 6px; }
.sidebar nav a, .logout { color: #d9e3f2; padding: 10px 12px; border-radius: 8px; }
.sidebar nav a:hover, .logout:hover { background: rgba(255,255,255,.08); text-decoration: none; color: white; }
.sidebar-footer { display: grid; gap: 10px; margin-top: auto; }
.logout { display: block; }
.copyright { color: #9aa8bb; font-size: 12px; line-height: 1.35; }
.main { margin-left: 248px; padding: 32px; max-width: 1420px; }
html.sidebar-collapsed .sidebar { width: 82px; padding-inline: 14px; }
html.sidebar-collapsed .main { margin-left: 82px; }
html.sidebar-collapsed .brand { justify-content: center; }
html.sidebar-collapsed .brand-text { display: none; }
html.sidebar-collapsed .brand-mark { width: 48px; height: 48px; }
html.sidebar-collapsed .sidebar-head { display: grid; justify-items: center; }
html.sidebar-collapsed .sidebar-toggle { transform: rotate(180deg); }
html.sidebar-collapsed .sidebar nav a,
html.sidebar-collapsed .logout {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 8px;
  font-size: 0;
}
html.sidebar-collapsed .sidebar-footer { justify-items: center; }
html.sidebar-collapsed .copyright { display: none; }
html.sidebar-collapsed .sidebar nav a::before,
html.sidebar-collapsed .logout::before {
  content: attr(data-short);
  display: grid;
  place-items: center;
  width: 34px;
  height: 28px;
  border-radius: 7px;
  background: rgba(255,255,255,.08);
  color: #d9e3f2;
  font-size: 12px;
  font-weight: 900;
}
.auth-main { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(430px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 32px; box-shadow: var(--shadow); }
h1, h2 { margin: 0 0 8px; letter-spacing: 0; }
h1 { font-size: 34px; line-height: 1.12; }
h2 { font-size: 19px; }
p { color: var(--muted); line-height: 1.55; }
.muted { color: var(--muted); }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 22px; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.button, button { border: 1px solid var(--line); background: white; color: var(--ink); border-radius: 8px; min-height: 40px; padding: 9px 14px; font-weight: 700; cursor: pointer; font-size: 14px; }
.button:hover, button:hover { text-decoration: none; border-color: #b9c4d4; }
.primary { background: var(--accent); color: white; border-color: var(--accent); }
.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.danger { color: white; background: var(--danger); border-color: var(--danger); }
.ghost { min-height: 32px; padding: 4px 9px; background: transparent; }
button:disabled { opacity: .45; cursor: not-allowed; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; padding: 24px; background: rgba(18, 26, 42, .58); }
.modal-backdrop.is-hidden { display: none; }
.modal-panel { width: min(760px, 100%); max-height: calc(100vh - 48px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: 0 30px 90px rgba(18, 26, 42, .34); }
.modal-panel h2 { font-size: 26px; margin-bottom: 18px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metrics div { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; box-shadow: var(--shadow); }
.metrics span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.metrics strong { font-size: 24px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.dashboard-grid { display: grid; grid-template-columns: 1.35fr .9fr; gap: 18px; margin-bottom: 18px; }
.chart-wide { grid-row: span 2; }
.chart-panel { min-height: 260px; }
.chart-note { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.line-chart { width: 100%; height: 210px; display: block; overflow: visible; }
.line-area { fill: rgba(25, 103, 210, .11); }
.line-stroke { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.line-dot { fill: white; stroke: var(--accent); stroke-width: 3; }
.chart-axis { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; margin-top: 8px; }
.donut-wrap { display: grid; grid-template-columns: 150px 1fr; gap: 18px; align-items: center; min-height: 170px; }
.donut { width: 148px; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; position: relative; box-shadow: inset 0 0 0 1px var(--line); }
.donut::after { content: ""; width: 86px; aspect-ratio: 1; border-radius: 50%; background: white; position: absolute; box-shadow: inset 0 0 0 1px var(--line); }
.donut span { position: relative; z-index: 1; font-size: 25px; font-weight: 900; color: var(--ink); }
.legend { display: grid; gap: 10px; }
.legend div { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 8px; font-size: 13px; }
.legend i { width: 10px; height: 10px; border-radius: 999px; }
.bar-list { display: grid; gap: 15px; padding-top: 8px; }
.bar-row { display: grid; gap: 7px; }
.bar-row div { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.bar-track { height: 10px; border-radius: 999px; background: #edf1f7; overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #1967d2, #13795b); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #516070; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.num { text-align: right; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.invoice-note { margin-top: 14px; padding: 12px 14px; border-left: 3px solid var(--accent); background: #f7f9fc; color: var(--ink); line-height: 1.5; }
.status { display: inline-flex; align-items: center; min-height: 26px; padding: 3px 9px; border-radius: 999px; background: #eef4ff; color: #174ea6; font-size: 12px; font-weight: 800; white-space: nowrap; }
.overdue-row td { background: #fff1f1; }
.overdue-row td:first-child { border-left: 4px solid var(--danger); }
.overdue-pill { display: inline-flex; margin-left: 8px; padding: 2px 7px; border-radius: 999px; background: #fee4e2; color: var(--danger); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.form { display: grid; gap: 14px; }
.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.inline-form { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; }
.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; gap: 14px; }
.filter-actions { align-self: end; }
.invoice-start-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.invoice-start-summary div { display: grid; gap: 5px; }
.invoice-start-summary span { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.invoice-start-summary strong { font-size: 15px; }
.wide { grid-column: 1 / -1; }
label { display: grid; gap: 6px; color: #3b4656; font-size: 13px; font-weight: 700; }
.static-field { display: grid; gap: 6px; align-content: start; color: #3b4656; font-size: 13px; font-weight: 700; }
.static-field strong { display: flex; align-items: center; min-height: 40px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #f7f9fc; color: var(--ink); font-size: 14px; }
input, select, textarea { width: 100%; border: 1px solid #cfd7e3; border-radius: 8px; min-height: 40px; padding: 9px 11px; font: inherit; color: var(--ink); background: white; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(25,103,210,.14); border-color: var(--accent); }
.searchbar { display: flex; gap: 10px; margin-bottom: 16px; }
.searchbar input { max-width: 560px; }
.flash-stack { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; gap: 12px; padding: 22px; pointer-events: none; }
.flash { display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 18px; width: min(620px, 100%); padding: 26px 26px 26px 30px; border-radius: 8px; background: white; border: 1px solid #c7dafc; border-left: 7px solid var(--accent); box-shadow: 0 28px 80px rgba(18, 26, 42, .28); color: var(--ink); pointer-events: auto; animation: flash-in .18s ease-out; }
.flash.error { border-color: #ffd0d0; border-left-color: var(--danger); }
.flash.success { border-color: #c8eadc; border-left-color: var(--ok); }
.flash span { line-height: 1.5; font-size: 18px; font-weight: 700; }
.flash-close { min-height: 34px; width: 34px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 26px; line-height: 1; }
.flash-close:hover { color: var(--ink); background: #f2f5f9; }
.flash.is-hiding { opacity: 0; transform: translateY(12px) scale(.98); transition: opacity .16s ease, transform .16s ease; }
@keyframes flash-in {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.logo-preview { display: block; max-width: 180px; max-height: 90px; object-fit: contain; margin-bottom: 8px; }
.icon-preview { display: block; width: 48px; height: 48px; object-fit: contain; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 8px; background: white; padding: 4px; }
.danger-form { margin: 10px 0 0; }
.inline-delete { display: inline-flex; margin: 0; }
.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line); vertical-align: middle; margin-left: 5px; }
.check { display: flex; grid-auto-flow: column; justify-content: start; align-items: center; gap: 9px; min-height: 40px; }
.check input { width: 18px; min-height: 18px; }
.checkline { display: flex; align-items: center; gap: 9px; min-height: 40px; color: var(--ink); }
.checkline input { width: 18px; min-height: 18px; }
.export-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.export-card { border: 1px solid var(--line); border-radius: 8px; padding: 18px; color: var(--ink); background: #fbfcfe; display: grid; gap: 8px; }
.export-card:hover { text-decoration: none; border-color: #b8c5d6; }
.export-card span { color: var(--muted); }
.permission-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.mail-preview pre { white-space: pre-wrap; background: #f7f9fc; border: 1px solid var(--line); border-radius: 8px; padding: 14px; font: inherit; color: var(--ink); }
.helper-box { background: #f7f9fc; border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.helper-box h2 { margin-bottom: 12px; }
.placeholder-grid { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; align-items: center; }
.placeholder-grid code { background: white; border: 1px solid var(--line); border-radius: 6px; padding: 4px 7px; color: var(--accent); }
small { color: var(--muted); }
@media (max-width: 900px) {
  .sidebar { position: static; width: auto; border-bottom: 1px solid rgba(255,255,255,.08); }
  .sidebar-head { display: block; }
  .sidebar-toggle { display: none; }
  .sidebar nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .main { margin-left: 0; padding: 20px; }
  html.sidebar-collapsed .sidebar { width: auto; padding: 22px 18px; }
  html.sidebar-collapsed .main { margin-left: 0; }
  html.sidebar-collapsed .brand { justify-content: flex-start; }
  html.sidebar-collapsed .brand-text { display: inline; }
  html.sidebar-collapsed .brand-mark { width: 96px; height: 58px; }
  html.sidebar-collapsed .sidebar nav a,
  html.sidebar-collapsed .logout {
    display: block;
    min-height: auto;
    padding: 10px 12px;
    font-size: 14px;
  }
  html.sidebar-collapsed .sidebar nav a::before,
  html.sidebar-collapsed .logout::before { content: none; }
  html.sidebar-collapsed .copyright { display: block; }
  .page-head, .split, .dashboard-grid { display: grid; grid-template-columns: 1fr; }
  .chart-wide { grid-row: auto; }
  .metrics, .export-grid, .permission-grid, .filter-grid, .invoice-start-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding: 16px; }
  h1 { font-size: 27px; }
  .metrics, .grid-form, .export-grid, .permission-grid, .placeholder-grid, .filter-grid, .invoice-start-summary { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 14px; }
  .modal-panel { padding: 22px; }
  .inline-form, .searchbar { display: grid; }
  th, td { padding: 10px 8px; }
}
