:root {
  --bg: #f4f8f8;
  --panel: #ffffff;
  --ink: #0f2e2b;
  --muted: #5f7a76;
  --line: #e2ecea;
  --brand: #0d9488;
  --brand-deep: #0f766e;
  --brand-soft: #ccfbf1;
  --brand-tint: #f0fdfa;
  --grad: linear-gradient(135deg, #2dd4bf 0%, #14b8a6 55%, #0e7490 100%);
  --green: #0e9f6e;
  --green-soft: #e7f8f1;
  --red: #c2410c;
  --red-soft: #fff1eb;
  --amber: #b45309;
  --amber-soft: #fef7e0;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 46, 43, .04), 0 6px 18px -8px rgba(15, 46, 43, .10);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

.layout { display: flex; min-height: 100vh; }

/* ------------------------------------------------------ slim icon sidebar */

.sidebar {
  width: 92px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 10px 14px;
  z-index: 10;
}
.brand { margin-bottom: 18px; }
.brand img { display: block; border-radius: 12px; box-shadow: var(--shadow); }

#nav { display: flex; flex-direction: column; gap: 4px; width: 100%; }
#nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); text-decoration: none;
  padding: 9px 4px 7px; border-radius: 12px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .01em;
}
#nav a svg {
  width: 20px; height: 20px; fill: none;
  stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
#nav a:hover { background: var(--brand-tint); color: var(--brand-deep); }
#nav a.active { background: var(--brand-soft); color: var(--brand-deep); }
.sidebar-foot { margin-top: auto; }

/* -------------------------------------------------------------- top bar */

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 0 32px;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 9;
}
.topbar-brand { font-size: 17px; font-weight: 800; letter-spacing: -.01em; }
.topbar-co { color: var(--brand); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .14em; margin-left: 6px; }
#user-chip { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); }
#user-chip b { color: var(--ink); font-weight: 600; }
#user-chip a { color: var(--brand); text-decoration: none; font-weight: 600; }
#user-chip a:hover { text-decoration: underline; }

.main { flex: 1; padding: 28px 32px 70px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ------------------------------------------------------------- headings */

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.page-head .actions { display: flex; gap: 8px; }

/* ------------------------------------------------------------ stat cards */

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.card .label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; margin-bottom: 8px; }
.card .value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 5px; }
.card .value.pos { color: var(--green); }
.card .value.neg { color: var(--red); }

.card.hero { background: var(--grad); border: none; color: #fff; }
.card.hero .label { color: rgba(255, 255, 255, .85); }
.card.hero .value { color: #fff; font-size: 30px; }
.card.hero .sub { color: rgba(255, 255, 255, .8); }

/* --------------------------------------------------------------- panels */

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 22px; box-shadow: var(--shadow);
}
.panel h2 { font-size: 13.5px; margin: 0; padding: 14px 20px; border-bottom: 1px solid var(--line); font-weight: 700; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 20px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); background: #fafcfc; font-weight: 700; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--brand-tint); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.total-row, tr.total-row td { font-weight: 700; background: #fafcfc; }
.empty { padding: 34px 20px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge.open { background: var(--amber-soft); color: var(--amber); }
.badge.paid { background: var(--green-soft); color: var(--green); }
.badge.void { background: #eef2f2; color: var(--muted); }
.badge.overdue { background: var(--red-soft); color: var(--red); }
.badge.inactive { background: #eef2f2; color: var(--muted); }

/* -------------------------------------------------------------- controls */

button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); padding: 8px 15px; font-weight: 600;
  transition: background .12s, border-color .12s;
}
button:hover { background: var(--brand-tint); border-color: #c9e8e2; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 4px 12px -4px rgba(13, 148, 136, .5); }
button.primary:hover { background: var(--brand-deep); }
button.danger { color: var(--red); }
button.small { padding: 4px 11px; font-size: 12.5px; font-weight: 500; border-radius: 8px; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font: inherit; padding: 8px 11px; border: 1px solid #cfdedb; border-radius: 10px;
  background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label { display: block; font-size: 12.5px; font-weight: 600; color: #38524e; margin-bottom: 4px; }
.field { margin-bottom: 13px; }
.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; }

/* ---------------------------------------------------------------- modals */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(9, 35, 32, .4);
  display: flex; align-items: flex-start; justify-content: center; padding: 42px 16px; z-index: 50;
  overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 18px; width: 100%; max-width: 640px;
  box-shadow: 0 24px 60px rgba(9, 35, 32, .25);
}
.modal.wide { max-width: 840px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal .body { padding: 20px 22px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line); background: #fafcfc; border-radius: 0 0 18px 18px; }
.modal .close { border: none; background: none; font-size: 20px; color: var(--muted); padding: 0 4px; box-shadow: none; }
.modal .close:hover { background: none; color: var(--ink); }

.lines-table td { padding: 6px 8px; border-bottom: none; }
.lines-table th { padding: 6px 8px; }
.lines-table input, .lines-table select { padding: 6px 9px; }

/* ----------------------------------------------------------------- toast */

#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: #0f2e2b; color: #fff; padding: 11px 17px; border-radius: 12px;
  font-size: 13.5px; box-shadow: 0 10px 24px rgba(9, 35, 32, .3); max-width: 380px;
}
.toast.error { background: #b3300f; }

/* --------------------------------------------------------------- filters */

.filters { display: flex; gap: 10px; align-items: end; margin-bottom: 16px; flex-wrap: wrap; }
.filters .field { margin-bottom: 0; }
.filters input, .filters select { width: auto; }

.report-tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.report-tabs button { border-radius: 999px; padding: 7px 16px; }
.report-tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; margin-bottom: 14px; font-size: 13.5px; }
.detail-grid .k { color: var(--muted); }

a.rowlink { color: var(--brand-deep); text-decoration: none; font-weight: 700; }
a.rowlink:hover { text-decoration: underline; }

.muted { color: var(--muted); }

/* ------------------------------------------------------------ auth screen */

.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1100px 500px at 85% -10%, #ccfbf1 0%, transparent 60%),
              radial-gradient(900px 500px at -10% 110%, #cffafe 0%, transparent 55%),
              var(--bg);
  padding: 20px;
}
.auth-card {
  background: #fff; border-radius: 22px; padding: 38px 40px; width: 100%; max-width: 400px;
  box-shadow: 0 24px 70px -20px rgba(9, 35, 32, .35); border: 1px solid var(--line);
}
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.auth-logo img { border-radius: 12px; }
.auth-logo .n { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.auth-logo .c { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--brand); }

/* -------------------------------------------------------------- responsive */

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; padding: 8px 10px; }
  .brand { margin: 0 8px 0 0; }
  .brand img { width: 32px; height: 32px; }
  #nav { flex-direction: row; flex-wrap: wrap; }
  #nav a { padding: 6px 8px; }
  .sidebar-foot { display: none; }
  .topbar { padding: 0 16px; }
  .topbar-co { display: none; }
  .main { padding: 16px; }
  .form-row { flex-direction: column; gap: 0; }
}

/* --------------------------------------------------- business overview */

.ov-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 16px; margin-bottom: 22px; }
.viz-card { display: flex; flex-direction: column; }
.viz-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.viz-sub { font-size: 11.5px; color: var(--muted); }
.viz-big { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.viz-caption { font-size: 11.5px; color: var(--muted); margin: 2px 0 12px; }
.viz-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.viz-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.donut-wrap { display: flex; gap: 14px; align-items: center; }
.viz-list { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }
.viz-row { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.viz-row i { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.viz-row .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-row .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.bank-row { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.bank-row:last-child { border-bottom: none; }
.pl-row { display: flex; align-items: center; gap: 10px; margin: 7px 0; font-size: 12px; }
.pl-row .n { width: 72px; color: var(--muted); flex-shrink: 0; }
.pl-row .v { width: 84px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; flex-shrink: 0; }
.hbar { flex: 1; height: 12px; border-radius: 4px; background: rgba(127,127,127,.14); overflow: hidden; }
.hbar span { display: block; height: 100%; border-radius: 4px; }
.stackbar { display: flex; gap: 2px; height: 14px; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.stackbar span { display: block; height: 100%; border-radius: 3px; }
svg [data-tip] { cursor: default; }
svg rect[data-tip]:hover, svg circle[data-tip]:hover { opacity: .82; }
#viz-tip {
  position: fixed; display: none; z-index: 120; pointer-events: none;
  background: #04101f; color: #f1f5fc; font-size: 12px; padding: 6px 10px;
  border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,.4); max-width: 260px;
}
.viz-big.pos { color: var(--green); }
.viz-big.neg { color: var(--red); }
.pnl-net.pos { color: var(--green); font-weight: 600; }
.pnl-net.neg { color: var(--red); font-weight: 600; }
.nav-badge:not(:empty) { display: inline-block; margin-left: 4px; min-width: 15px; padding: 0 4px; height: 15px; line-height: 15px; font-size: 9.5px; font-weight: 800; text-align: center; border-radius: 999px; background: var(--red); color: #fff; vertical-align: 1px; }
