:root {
  --bg: #07080b;
  --bg-elevated: #0c0e13;
  --card: #14161c;
  --card-2: #1a1d25;
  --secondary: #22262f;
  --border: rgba(255, 255, 255, 0.07);
  --accent: #3d7cff;
  --accent-2: #5aa2ff;
  --accent-dim: rgba(61, 124, 255, 0.16);
  --accent-glow: 0 0 24px rgba(61, 124, 255, 0.35);
  --text: #f4f6fb;
  --muted: #8b93a7;
  --danger: #ff6b7a;
  --warning: #f5a524;
  --info: #5aa2ff;
  --success: #3ee0b0;
  --orange: #ff8a4c;
  --yellow: #f5d76e;
  --purple: #a78bfa;
  --teal: #2dd4bf;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  --radius: 26px;
  --sidebar: 88px;
  --font: "DM Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --hatch: repeating-linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.045) 0 1.5px,
    transparent 1.5px 7px
  );
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(61, 124, 255, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  letter-spacing: -0.015em;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
img { max-width: 100%; }

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar);
  background: transparent;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 30;
  gap: 8px;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 4px 0 10px;
}
.brand-copy { display: none; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px;
  background: #f4f6fb;
  color: #0b0d12;
  display: grid; place-items: center;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0,0,0,.35);
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow: auto;
  width: 100%;
  align-items: center;
  padding-top: 8px;
}
.nav a, .nav button.nav-link {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 16px;
  color: var(--muted);
  border: 0;
  background: transparent;
  cursor: pointer;
  position: relative;
  font-size: 0;
}
.nav a span { display: none; }
.nav a:hover { background: var(--secondary); color: var(--text); }
.nav a.active {
  background: #f4f6fb;
  color: #0b0d12;
  box-shadow: 0 10px 24px rgba(0,0,0,.28);
}
.nav svg { width: 20px; height: 20px; opacity: 0.9; }
.sidebar-foot { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 8px 18px 18px 0; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 8px 8px;
  background: transparent;
  position: sticky; top: 0; z-index: 20;
}
.search-wrap { flex: 1; position: relative; max-width: 560px; }
.search-wrap input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 12px 46px 12px 44px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
}
.search-wrap svg.search-icon { position: absolute; left: 16px; top: 13px; width: 18px; color: var(--muted); }
.search-send {
  position: absolute; right: 8px; top: 7px;
  width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
}
.search-results {
  position: absolute; top: 52px; left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow); display: none; overflow: hidden;
}
.search-results.open { display: block; }
.search-results a { display: block; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
.search-results a:hover { background: var(--secondary); }
.search-results small { color: var(--muted); }

.top-actions { display: flex; gap: 10px; align-items: center; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); display: grid; place-items: center; cursor: pointer;
}
.profile-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px 6px 6px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #3d7cff, #a78bfa);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.profile-chip strong { display: block; font-size: 12px; line-height: 1.1; }
.profile-chip small { color: var(--muted); font-size: 11px; }

.content { padding: 8px 8px 28px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 30px; font-weight: 650; letter-spacing: -0.04em; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--secondary);
  color: var(--text); border-radius: 14px; padding: 9px 14px;
  cursor: pointer; font-size: 14px; font-weight: 500;
  transition: transform .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  background: var(--accent); color: #fff; border-color: transparent;
  font-weight: 700; box-shadow: var(--accent-glow);
}
.btn-danger { background: rgba(255,107,122,0.12); color: var(--danger); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 10px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi::after {
  content: "";
  position: absolute; inset: 0;
  background: var(--hatch);
  opacity: .35;
  pointer-events: none;
}
.kpi .label, .kpi .value, .kpi .delta { position: relative; z-index: 1; }
.kpi .label { color: var(--muted); font-size: 12px; letter-spacing: 0.02em; }
.kpi .value { font-family: var(--mono); font-size: 22px; margin-top: 8px; font-weight: 600; }
.kpi .delta { font-size: 12px; margin-top: 6px; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1.45fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; color: var(--muted); font-weight: 500; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data td { padding: 11px 12px; border-bottom: 1px solid rgba(255,255,255,.04); vertical-align: middle; }
table.data tr:hover td { background: rgba(255,255,255,0.02); }
table.data .num { text-align: right; font-family: var(--mono); }
.income { color: var(--success); }
.expense { color: var(--danger); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.badge-success { background: rgba(62,224,176,.12); color: var(--success); }
.badge-danger { background: rgba(255,107,122,.12); color: var(--danger); }
.badge-warning { background: rgba(245,165,36,.12); color: var(--warning); }
.badge-info { background: rgba(90,162,255,.12); color: var(--info); }
.badge-muted { background: var(--secondary); color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters input, .filters select, .form-control {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 14px; padding: 9px 11px; font-size: 14px;
}
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.form-row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  border-radius: 14px; padding: 10px 12px; font-size: 14px; width: 100%;
}
.field textarea { min-height: 88px; resize: vertical; }
.field .hint { font-size: 11px; color: var(--muted); line-height: 1.4; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }

.alert { padding: 10px 14px; border-radius: 16px; margin-bottom: 14px; font-size: 14px; }
.alert-success { background: rgba(62,224,176,.12); color: var(--success); }
.alert-error { background: rgba(255,107,122,.12); color: var(--danger); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.62);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 50; overflow: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(720px, 100%); background: var(--card); border: 1px solid var(--border);
  border-radius: 28px; padding: 22px; box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 16px; font-size: 20px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { background: var(--secondary); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.chip:hover, .chip.active { color: #fff; border-color: var(--accent); background: var(--accent-dim); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a, .tabs button {
  background: var(--card-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 7px 12px; font-size: 13px; cursor: pointer;
}
.tabs a.active, .tabs button.active { color: #fff; background: var(--accent); border-color: var(--accent); font-weight: 700; }

.pagination { display: flex; gap: 6px; margin-top: 14px; }
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: var(--hatch), var(--bg);
}
.auth-card { width: min(420px, 100%); }
.menu-toggle { display: none; }

.flow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.flow-item {
  background: var(--card-2);
  border-radius: 18px;
  padding: 14px;
  background-image: var(--hatch);
}
.flow-item span { color: var(--muted); font-size: 12px; display: block; }

.line-items { width: 100%; }
.line-items input, .line-items select { min-width: 0; }
.sticky-totals { position: sticky; bottom: 0; background: var(--card); padding-top: 10px; }

.mobile-fab {
  display: none; position: fixed; right: 16px; bottom: 16px; z-index: 40;
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 28px; font-weight: 700;
  box-shadow: var(--accent-glow); cursor: pointer;
}

.dash-top { display: grid; grid-template-columns: 1.7fr 1fr; gap: 14px; margin-bottom: 14px; }
.hero-card { min-height: 360px; position: relative; overflow: hidden; }
.hero-card h2 { margin: 0; font-size: 13px; color: var(--muted); font-weight: 500; }
.hero-metric { display: flex; align-items: flex-end; gap: 12px; margin: 10px 0 18px; }
.hero-metric strong { font-size: 42px; letter-spacing: -0.05em; line-height: 1; }
.growth-pill {
  background: rgba(62,224,176,.12); color: var(--success);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700;
}
.growth-pill.down { background: rgba(255,107,122,.12); color: var(--danger); }

.cal-card { display: flex; flex-direction: column; gap: 14px; }
.cal-head { display: flex; justify-content: space-between; align-items: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; color: var(--muted); font-size: 11px; padding-bottom: 4px; }
.cal-day {
  aspect-ratio: 1;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 12px; color: var(--muted);
  background-image: var(--hatch);
  background-color: rgba(255,255,255,.02);
}
.cal-day.in { color: var(--text); background-image: none; background: transparent; }
.cal-day.today {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--accent-glow);
  position: relative;
}
.cal-day.today::after {
  content: "";
  position: absolute; bottom: 4px;
  width: 4px; height: 4px; border-radius: 50%; background: #fff;
}
.mini-stat {
  background: var(--card-2);
  border-radius: 20px;
  padding: 14px 16px;
  display: flex; justify-content: space-between; align-items: center;
  background-image: var(--hatch);
}
.sparkle { color: var(--yellow); }

.insight-grid { display: grid; grid-template-columns: 1.1fr 1.1fr 1fr; gap: 14px; margin-bottom: 14px; }
.help-card .pills { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 16px; }
.soft-pill { border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 700; }
.soft-pill.orange { background: rgba(255,138,76,.16); color: var(--orange); }
.soft-pill.green { background: rgba(62,224,176,.14); color: var(--success); }
.mini-list { display: flex; flex-direction: column; gap: 10px; }
.mini-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }

.donut-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 8px; }

.score-bar {
  width: 100%;
  height: 18px;
  border-radius: 8px;
  background: repeating-linear-gradient(
    90deg,
    #f5d76e 0 6px,
    #ff8a4c 6px 12px,
    transparent 12px 16px
  );
  margin: 8px 0 16px;
  opacity: .95;
}
.invoice-row {
  display: grid;
  grid-template-columns: 72px 12px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
  font-size: 13px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.status-dot.paid { background: var(--success); color: var(--success); }
.status-dot.pending { background: var(--warning); color: var(--warning); }
.status-dot.overdue { background: var(--danger); color: var(--danger); }
.status-dot.draft { background: var(--muted); color: var(--muted); }

.doodle {
  position: absolute;
  pointer-events: none;
  opacity: .55;
}
.doodle.star { right: 18px; top: 18px; }

@media (max-width: 1200px) {
  .dash-top, .insight-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1100px) {
  .kpi-grid, .grid-2, .grid-3, .flow { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  :root { --sidebar: 248px; }
  .sidebar { position: fixed; left: -270px; transition: left .2s ease; align-items: stretch; width: 248px; background: #0c0e13; }
  .sidebar.open { left: 0; }
  .nav { align-items: stretch; }
  .nav a { width: auto; height: auto; display: flex; gap: 10px; justify-content: flex-start; padding: 10px 12px; font-size: 14px; }
  .nav a span { display: inline; }
  .brand-copy { display: block; text-align: center; margin-top: 8px; }
  .menu-toggle { display: inline-flex; }
  .kpi-grid, .grid-2, .grid-3, .form-row, .form-row-3, .form-row-4, .flow, .dash-top, .insight-grid, .donut-wrap { grid-template-columns: 1fr; }
  .span-2, .span-3, .span-4 { grid-column: span 1; }
  .content { padding: 16px; }
  .mobile-fab { display: grid; place-items: center; }
  .topbar { padding: 12px; }
  .profile-chip small, .profile-chip strong { display: none; }
  .main { padding: 0; }
}

.card-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  position: relative;
  z-index: 1;
}
.card-metrics .m { font-size: 11px; color: var(--muted); }
.card-metrics .m strong {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  margin-top: 3px;
  font-weight: 600;
}
.util-bar {
  height: 8px;
  border-radius: 99px;
  background: rgba(255,255,255,.08);
  margin-top: 10px;
  overflow: hidden;
  position: relative;
  z-index: 1;
}
.util-bar > span {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  min-width: 0;
}
.util-bar.warn > span { background: #f5d76e; }
.util-bar.hot > span { background: var(--danger); }

.hidden { display: none !important; }
.inline { display: inline; }
