/* ================================================================ base */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #1e293b;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #e6e9f0;
  --line-strong: #d8dde8;
  --accent: #4f46e5;
  --accent-2: #6366f1;
  --accent-soft: #eef2ff;
  --green: #15803d;
  --green-soft: #e8f7ee;
  --red: #dc2626;
  --red-soft: #fdecec;
  --amber: #b45309;
  --amber-soft: #fef4e6;
  --blue: #1d4ed8;
  --blue-soft: #eaf1ff;
  --slate-soft: #eef1f6;
  --sidebar: #0b1224;
  --sidebar-2: #111a30;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .05);
  --shadow-lg: 0 24px 70px rgba(11, 18, 36, .28);
  --font: "Segoe UI", system-ui, -apple-system, "Inter", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; letter-spacing: -0.02em; }

button { font-family: inherit; }

::selection { background: #c7d2fe; }

/* ============================================================== layout */

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 10px 22px;
  color: #fff;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(140deg, #6366f1, #8b5cf6 55%, #22d3ee);
  color: #fff;
  box-shadow: 0 6px 16px rgba(99, 102, 241, .35);
  flex: none;
}

.brand-mark svg { width: 19px; height: 19px; }

.brand-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.company-switch {
  padding: 0 6px 15px;
}

.company-switch > label {
  display: block;
  margin-bottom: 7px;
  color: #7f8daa;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.company-switch-row {
  position: relative;
  display: flex;
  align-items: center;
}

.company-switch-icon {
  position: absolute;
  left: 10px;
  display: inline-flex;
  color: #8fa0bd;
  pointer-events: none;
}

.company-switch-icon svg { width: 15px; height: 15px; }

.company-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 9px;
  background-color: rgba(255, 255, 255, .06);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238fa0bd' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  color: #fff;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 30px 8px 33px;
  cursor: pointer;
}

.company-select:hover { border-color: rgba(255, 255, 255, .24); }

.company-select:focus {
  outline: none;
  border-color: rgba(129, 140, 248, .8);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .2);
}

.company-select:disabled { opacity: .55; cursor: wait; }
.company-select option { background: #fff; color: #172033; }

.company-manage {
  display: inline-block;
  margin-top: 7px;
  color: #8fa0bd;
  font-size: 11.5px;
  text-decoration: none;
}

.company-manage:hover { color: #fff; text-decoration: none; }

.company-list { display: flex; flex-direction: column; gap: 8px; }

.company-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
}

.company-row.active {
  border-color: #c7d2fe;
  background: #eef2ff;
}

.company-row-info { min-width: 0; flex: 1; }

.company-row-name {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.company-row-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
}

.company-row-check {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #dcfce7;
  color: #15803d;
  flex: none;
}

.company-row-check svg { width: 15px; height: 15px; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #aab6cc;
  font-weight: 500;
  font-size: 14px;
  transition: background .15s, color .15s;
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, .06);
  color: #fff;
  text-decoration: none;
}

.nav-item.active {
  background: rgba(99, 102, 241, .16);
  color: #fff;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: #818cf8;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  color: #8fa0bd;
}

.nav-item.active .nav-icon { color: #a5b4fc; }
.nav-icon svg { width: 18px; height: 18px; }

.nav-count {
  margin-left: auto;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 99px;
  background: rgba(239, 68, 68, .18);
  color: #fca5a5;
  font-size: 11.5px;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
}

.sidebar-foot {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, .08);
  padding: 14px 8px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #8fa0bd;
  line-height: 1.35;
}

.sync-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #64748b;
  flex: none;
}

.sync-status.ok .dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .15); }
.sync-status.warn .dot { background: #f59e0b; }

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 9px;
  background: none;
  border: 0;
  color: #8fa0bd;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 4px;
  border-radius: 8px;
  text-align: left;
}

.sidebar-logout:hover { color: #fff; background: rgba(255, 255, 255, .05); }
.sidebar-logout svg { width: 16px; height: 16px; }

.main {
  flex: 1;
  min-width: 0;
  margin-left: 248px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 32px 16px;
  background: rgba(244, 246, 251, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(216, 221, 232, .7);
}

.topbar-title h1 {
  font-size: 20px;
  font-weight: 700;
}

.topbar-title p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-demo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 99px;
  background: #fef3c7;
  color: #92400e;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.view {
  padding: 24px 32px 56px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.view:focus { outline: none; }

.menu-btn { display: none !important; }

/* ================================================================ cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 0;
}

.card-head.bordered {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-sub {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 2px;
}

.card-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.card-body { padding: 18px 20px 20px; }
.card-body.tight { padding: 12px 12px 12px; }

.page-head {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.page-head h2 { font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.page-head .spacer { flex: 1; }

.section-gap { margin-top: 20px; }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

/* ================================================================== kpi */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.kpi {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.kpi::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--line);
}

.kpi.danger::after { background: linear-gradient(90deg, #ef4444, #f97316); }
.kpi.warning::after { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.kpi.success::after { background: linear-gradient(90deg, #16a34a, #34d399); }
.kpi.info::after { background: linear-gradient(90deg, #4f46e5, #818cf8); }

.kpi-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.kpi-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  background: var(--slate-soft);
  color: var(--muted);
  flex: none;
}

.kpi-icon svg { width: 18px; height: 18px; }

.kpi.danger .kpi-icon { background: var(--red-soft); color: var(--red); }
.kpi.warning .kpi-icon { background: var(--amber-soft); color: var(--amber); }
.kpi.success .kpi-icon { background: var(--green-soft); color: var(--green); }
.kpi.info .kpi-icon { background: var(--accent-soft); color: var(--accent); }

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .045em;
}

.kpi-value {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.15;
  white-space: nowrap;
}

.kpi-value.sm { font-size: 21px; }

.kpi-sub {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.kpi-sub strong { color: var(--ink-2); font-weight: 600; }

.kpi-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
}

/* =============================================================== tables */

.table-scroll {
  overflow-x: auto;
  border-radius: 0 0 var(--radius) var(--radius);
}

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}

table.data th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted-2);
  background: var(--surface-2);
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.data td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.data tr:last-child td { border-bottom: 0; }

table.data tbody tr.clickable { cursor: pointer; }

table.data tbody tr.clickable:hover { background: #fafbff; }
table.data tbody tr.clickable:hover .cell-title { color: var(--accent); }

table.data .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data th.num { text-align: right; }

table.data .strong { font-weight: 700; }
table.data .muted { color: var(--muted); }
table.data .small { font-size: 12px; }

.cell-title { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  white-space: nowrap;
}

.table-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.overdue-days {
  display: inline-block;
  margin-left: 6px;
  color: var(--red);
  font-weight: 700;
  font-size: 11.5px;
  background: var(--red-soft);
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
}

/* ================================================================ chips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
  background: var(--slate-soft);
  color: var(--muted);
}

.chip::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: .8;
}

.chip-paid { background: var(--green-soft); color: var(--green); }
.chip-open { background: var(--blue-soft); color: var(--blue); }
.chip-overdue { background: var(--red-soft); color: var(--red); }
.chip-partial { background: var(--amber-soft); color: var(--amber); }
.chip-cancelled { background: var(--slate-soft); color: var(--muted-2); }
.chip-corrected { background: #eef2f7; color: #475569; }
.chip-muted { background: var(--slate-soft); color: var(--muted); }

.chip-plain::before { display: none; }

/* =============================================================== buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, .22);
}

.btn-primary:hover { background: #4338ca; }

.btn-ghost {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink-2);
}

.btn-ghost:hover { background: var(--surface-2); border-color: #c3c9d6; }

.btn-subtle {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink-2);
}

.btn-subtle:hover { background: #f1f4f9; }

.btn-danger {
  background: var(--red-soft);
  color: var(--red);
  border-color: #f7cccb;
}

.btn-danger:hover { background: #fbdcdb; }

.btn-success {
  background: var(--green-soft);
  color: var(--green);
  border-color: #c6ead4;
}

.btn-success:hover { background: #dcf3e4; }

.btn-sm { padding: 7px 11px; font-size: 12.5px; border-radius: 9px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-xs { padding: 4px 8px; font-size: 11.5px; border-radius: 7px; font-weight: 600; }
.btn-block { width: 100%; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  flex: none;
}

.icon-btn:hover { color: var(--ink); background: var(--surface-2); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.danger:hover { color: var(--red); background: var(--red-soft); border-color: #f3cfcf; }

.link-btn {
  background: none;
  border: 0;
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--red); }

/* ================================================================ forms */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  min-width: 0;
}

.field > span { color: var(--muted); font-weight: 600; }

.input, .select, .textarea {
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: #a5b4fc;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .14);
}

.input::placeholder, .textarea::placeholder { color: #a8b1c2; }

.textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.55;
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 32px;
}

.search-wrap { position: relative; }
.search-wrap .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted-2);
  pointer-events: none;
  display: flex;
}
.search-wrap .search-icon svg { width: 16px; height: 16px; }
.search-wrap .input { padding-left: 34px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid .span-2 { grid-column: span 2; }

.form-error {
  color: var(--red);
  font-size: 12.5px;
  background: var(--red-soft);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0;
}

.form-hint { color: var(--muted); font-size: 12px; margin: 0; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 13.5px;
  color: var(--ink-2);
  cursor: pointer;
}

.checkbox input { margin-top: 2px; width: 16px; height: 16px; accent-color: var(--accent); }

/* =============================================================== filters */

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 14px 16px;
}

.filters .field { min-width: 130px; }
.filters .field.grow { flex: 1; min-width: 200px; }
.filters .spacer { flex: 1; }

.tabs {
  display: inline-flex;
  gap: 3px;
  background: var(--slate-soft);
  border-radius: 11px;
  padding: 3px;
  flex-wrap: wrap;
}

.tab {
  padding: 7px 12px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover { color: var(--ink); }

.tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
}

.tab .tab-count {
  display: inline-block;
  margin-left: 5px;
  font-size: 11px;
  color: var(--muted-2);
}

.result-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  flex-wrap: wrap;
}

.result-bar strong { color: var(--ink-2); }
.result-bar .spacer { flex: 1; }

.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination .page-info { color: var(--muted); font-size: 12.5px; }

/* ================================================================ charts */

.aging-list { display: flex; flex-direction: column; gap: 13px; }

.aging-row {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) 108px;
  align-items: center;
  gap: 12px;
}

.aging-label { font-size: 12.5px; font-weight: 650; color: var(--muted); }

.aging-track {
  height: 10px;
  border-radius: 99px;
  background: #f0f2f8;
  overflow: hidden;
}

.aging-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  transition: width .4s ease;
}

.aging-amount { text-align: right; font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.aging-amount small { display: block; font-weight: 500; color: var(--muted-2); font-size: 11px; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 150px;
  padding-top: 8px;
}

.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 7px;
  height: 100%;
  min-width: 0;
}

.chart-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }

.chart-bar {
  width: 100%;
  max-width: 46px;
  border-radius: 7px 7px 3px 3px;
  background: linear-gradient(180deg, #818cf8, #4f46e5);
  min-height: 3px;
  transition: height .4s ease;
}

.chart-col.muted .chart-bar { background: #e2e7f0; }

.chart-label { font-size: 11px; color: var(--muted-2); text-transform: capitalize; }
.chart-value { font-size: 10.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }

/* ============================================================ list rows */

.list { display: flex; flex-direction: column; }

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }

.list-main { min-width: 0; flex: 1; }
.list-title {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
.list-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.list-amount small { display: block; color: var(--muted); font-weight: 500; font-size: 11.5px; }

.suggestion {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #dfe4ff;
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 650;
  white-space: nowrap;
}

.suggestion .score { color: #6d6ae0; font-weight: 700; }

/* ================================================================ empty */

.empty {
  text-align: center;
  padding: 46px 24px;
  color: var(--muted);
}

.empty .empty-icon {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: inline-grid;
  place-items: center;
  color: var(--muted-2);
  margin-bottom: 12px;
}

.empty h3 { font-size: 15px; color: var(--ink-2); margin-bottom: 4px; }
.empty p { margin: 0 auto; max-width: 380px; font-size: 13px; }
.empty .btn { margin-top: 14px; }

/* ================================================================ modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 18, 36, .55);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
  animation: fade-in .15s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }

.modal {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  margin: auto;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
  animation: pop-in .18s ease;
  border: 1px solid rgba(255, 255, 255, .5);
}

.modal.wide { max-width: 920px; }
.modal.medium { max-width: 700px; }

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.modal-head h2 { font-size: 17px; }
.modal-head p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.modal-head .icon-btn { margin-left: auto; }

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 18px 18px;
  flex-wrap: wrap;
  flex: none;
}

.modal-foot .spacer { flex: 1; }

.modal-close { margin-left: auto; }

/* =========================================================== invoice modal */

.inv-head-amount {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.inv-stat {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.inv-stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); font-weight: 700; }
.inv-stat .value { font-size: 17px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.inv-stat.highlight { background: var(--red-soft); border-color: #f6d5d5; }
.inv-stat.highlight .value { color: var(--red); }
.inv-stat.ok { background: var(--green-soft); border-color: #d3ecd9; }
.inv-stat.ok .value { color: var(--green); }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 24px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.meta-row { display: flex; flex-direction: column; gap: 2px; }
.meta-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); font-weight: 700; }
.meta-value { font-size: 13.5px; font-weight: 550; }

.drawer-section { padding: 18px 0 0; }
.drawer-section:first-child { padding-top: 0; }
.drawer-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted-2);
  margin-bottom: 10px;
}

.reminder-toolbar { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 10px; flex-wrap: wrap; }
.reminder-toolbar .field { min-width: 180px; }
.reminder-text { font-size: 13px; min-height: 210px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; line-height: 1.55; }

.reminder-history { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }

.mini-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mini-table th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.mini-table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.mini-table tr:last-child td { border-bottom: 0; }
.mini-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ================================================================ toast */

.toast-root {
  position: fixed;
  right: 22px;
  bottom: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  max-width: 380px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--ink);
  color: #fff;
  border-radius: 11px;
  padding: 11px 14px;
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(11, 18, 36, .3);
  animation: toast-in .2s ease;
  line-height: 1.4;
}

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.toast svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
.toast.info { background: #1e293b; }
.toast .toast-close { margin-left: auto; background: none; border: 0; color: rgba(255, 255, 255, .6); cursor: pointer; padding: 0; line-height: 1; font-size: 16px; }

/* ================================================================ banner */

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: 12px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  font-size: 13px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.banner .banner-actions { margin-left: auto; display: flex; gap: 8px; }
.banner.info { background: var(--accent-soft); border-color: #dbe1ff; color: #3730a3; }
.banner.warn { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }

/* ================================================================ import */

.dropzone {
  border: 1.5px dashed #c7cedd;
  border-radius: 14px;
  background: var(--surface-2);
  padding: 26px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  position: relative;
}

.dropzone:hover, .dropzone.drag {
  border-color: #818cf8;
  background: #f7f8ff;
}

.dropzone .dz-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-grid;
  place-items: center;
  margin-bottom: 9px;
}

.dropzone .dz-icon svg { width: 20px; height: 20px; }
.dropzone h4 { font-size: 14px; margin-bottom: 3px; }
.dropzone p { margin: 0; color: var(--muted); font-size: 12.5px; }
.dropzone .dz-formats { margin-top: 8px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.dropzone input[type=file] { display: none; }

.dz-busy { opacity: .6; pointer-events: none; }

.format-pill {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}

.import-result { margin-top: 14px; }
.import-result .ok { color: var(--green); font-weight: 600; }
.import-result .warn { color: var(--amber); font-weight: 600; }
.import-result .err { color: var(--red); font-weight: 600; }

.mapping-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.details-toggle {
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

details.help { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
details.help summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details.help ol { margin: 8px 0 0; padding-left: 18px; line-height: 1.6; }

.history-table td { font-size: 12.5px; }

/* ================================================================ auth */

.auth-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  background: var(--surface);
}

.auth-aside {
  background:
    radial-gradient(900px 500px at 15% 10%, rgba(99, 102, 241, .35), transparent 60%),
    radial-gradient(700px 500px at 85% 90%, rgba(34, 211, 238, .18), transparent 60%),
    linear-gradient(150deg, #0b1224, #131c33 55%, #0b1224);
  color: #fff;
  padding: 54px 58px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.auth-aside::after {
  content: "";
  position: absolute;
  inset: auto -120px -160px auto;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .08);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.03em;
  margin-bottom: 54px;
}

.auth-aside h1 {
  font-size: clamp(30px, 3.4vw, 44px);
  line-height: 1.12;
  font-weight: 750;
  letter-spacing: -0.035em;
  margin-bottom: 18px;
}

.auth-aside > p {
  color: #a9b6d0;
  font-size: 15px;
  max-width: 430px;
  line-height: 1.6;
  margin: 0 0 30px;
}

.auth-points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.auth-points li { display: flex; align-items: center; gap: 10px; color: #c9d4e8; font-size: 13.5px; }
.auth-points span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(99, 102, 241, .25);
  border: 1px solid rgba(129, 140, 248, .5);
  display: inline-grid;
  place-items: center;
  flex: none;
}
.auth-points span::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #818cf8;
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 26px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 30px 28px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-logo { display: none; align-items: center; gap: 9px; font-weight: 750; font-size: 17px; margin-bottom: 12px; }
.auth-logo .brand-mark { width: 30px; height: 30px; }
.auth-logo .brand-mark svg { width: 16px; height: 16px; }

.auth-card-head { margin-bottom: 2px; }
.auth-card-head h2 { font-size: 21px; margin-bottom: 6px; }
.auth-card-head p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.auth-hint { margin: 0; text-align: center; color: var(--muted-2); font-size: 11.5px; }

/* ============================================================ responsive */

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 20px 0 60px rgba(0, 0, 0, .3);
  }
  .sidebar.open { transform: none; }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 18, 36, .5);
    z-index: 35;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
  }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid !important; }
  .topbar { padding: 14px 18px; }
  .topbar-title p { display: none; }
  .topbar-actions .btn span:not([data-icon]) { display: none; }
  .topbar-actions .btn { padding: 8px 10px; }
  .view { padding: 18px 16px 48px; }
  .auth-screen { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .auth-logo { display: flex; }
  .auth-panel { min-height: 100vh; }
}

@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 20px; }
  .kpi-icon { width: 30px; height: 30px; border-radius: 8px; }
  .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .inv-head-amount { grid-template-columns: 1fr 1fr; }
  .meta-grid { grid-template-columns: 1fr; }
  .filters { padding: 12px; }
  .filters .field { min-width: calc(50% - 5px); flex: 1; }
  .filters .field.grow { min-width: 100%; }
  .mapping-grid { grid-template-columns: 1fr; }
  .topbar-actions .badge-demo { display: none; }
  .modal-overlay { padding: 12px; }
  .modal { max-height: calc(100vh - 24px); }
  .modal-head, .modal-body, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .chart { gap: 6px; }
  .chart-value { display: none; }
  .aging-row { grid-template-columns: 52px minmax(0, 1fr) 88px; gap: 8px; }
  .aging-amount { font-size: 11.5px; }
  .toast-root { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
