:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --ink: #162033;
  --muted: #687385;
  --muted-2: #98a2b3;
  --line: #dde3eb;
  --line-strong: #c8d0dc;
  --accent: #155e75;
  --accent-2: #0f766e;
  --accent-3: #334155;
  --accent-soft: #e5f4f4;
  --gold: #a16207;
  --gold-soft: #fef7c3;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --warning: #b54708;
  --warning-soft: #ffead5;
  --success: #067647;
  --success-soft: #dcfae6;
  --shadow: 0 18px 44px rgba(22, 32, 51, .09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, rgba(21, 94, 117, .15), transparent 34%),
    radial-gradient(circle at 95% 8%, rgba(161, 98, 7, .13), transparent 27%),
    linear-gradient(135deg, rgba(15, 23, 42, .04), transparent 35%),
    var(--bg);
  color: var(--ink);
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .94), rgba(248, 250, 252, .9)),
    var(--surface);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 8px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: 0 12px 30px rgba(21, 94, 117, .24);
}

.brand strong, .brand span {
  display: block;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  position: relative;
  border: 0;
  background: transparent;
  color: #344054;
  border-radius: 8px;
  padding: 12px 14px 12px 44px;
  text-align: left;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

.nav-item::before {
  content: attr(data-icon);
  position: absolute;
  left: 10px;
  top: 50%;
  width: 24px;
  height: 24px;
  transform: translateY(-50%);
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: #eef3f6;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
}

.nav-item:hover {
  background: #eef3f6;
}

.nav-item.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 10px 22px rgba(21, 94, 117, .22);
}

.nav-item.active::before {
  background: rgba(255, 255, 255, .18);
  color: white;
}

.sidebar-card {
  margin-top: auto;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(21, 94, 117, .08), rgba(161, 98, 7, .08)),
    var(--surface-soft);
  border-radius: 8px;
  padding: 16px;
}

.sidebar-card span, .sidebar-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-card strong {
  display: block;
  margin: 8px 0 2px;
  font-size: 24px;
}

.mini-bars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: end;
  gap: 6px;
  height: 34px;
  margin-top: 14px;
}

.mini-bars i {
  display: block;
  border-radius: 999px 999px 4px 4px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}

.mini-bars i:nth-child(1) { height: 45%; opacity: .55; }
.mini-bars i:nth-child(2) { height: 78%; opacity: .75; }
.mini-bars i:nth-child(3) { height: 58%; opacity: .65; }
.mini-bars i:nth-child(4) { height: 100%; }

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
  padding: 6px 2px 2px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 22px;
  letter-spacing: 0;
}

h3 {
  font-size: 16px;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.primary-button, .ghost-button, .danger-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 10px 14px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 24px rgba(21, 94, 117, .22);
}

.ghost-button {
  color: var(--ink);
  background: rgba(255, 255, 255, .88);
  border-color: var(--line);
}

.danger-button {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #fecdca;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.view {
  display: grid;
  gap: 20px;
}

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

.kpi {
  position: relative;
  min-height: 142px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .96), rgba(255, 255, 255, .88)),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.kpi::after {
  content: "";
  position: absolute;
  inset: auto -20px -42px auto;
  width: 110px;
  height: 110px;
  border-radius: 999px;
  background: rgba(21, 94, 117, .08);
}

.kpi.danger::after { background: rgba(180, 35, 24, .1); }
.kpi.warning::after { background: rgba(181, 71, 8, .11); }
.kpi.success::after { background: rgba(6, 118, 71, .1); }

.kpi-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.kpi span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi em {
  font-style: normal;
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 900;
  color: var(--muted-2);
}

.kpi strong {
  display: block;
  margin: 12px 0 8px;
  font-size: 34px;
  line-height: 1;
}

.kpi small {
  color: var(--muted);
}

.sparkline {
  display: flex;
  align-items: end;
  gap: 4px;
  height: 24px;
  margin-top: 16px;
}

.sparkline i {
  display: block;
  width: 18px;
  border-radius: 999px;
  background: currentColor;
  opacity: .2;
}

.sparkline i:nth-child(1) { height: 38%; }
.sparkline i:nth-child(2) { height: 68%; }
.sparkline i:nth-child(3) { height: 52%; }
.sparkline i:nth-child(4) { height: 88%; }
.sparkline i:nth-child(5) { height: 62%; }

.kpi.danger strong { color: var(--danger); }
.kpi.warning strong { color: var(--warning); }
.kpi.success strong { color: var(--success); }
.kpi.accent strong { color: var(--accent); }

.command-strip {
  display: grid;
  grid-template-columns: 1.4fr .8fr .8fr;
  gap: 14px;
}

.insight-card {
  min-height: 132px;
  background:
    linear-gradient(135deg, rgba(21, 94, 117, .08), transparent 46%),
    linear-gradient(315deg, rgba(161, 98, 7, .09), transparent 36%),
    white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: grid;
  align-content: space-between;
}

.insight-card.wide {
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 20px;
}

.insight-card h2 {
  margin-bottom: 6px;
  font-size: 24px;
}

.insight-card strong {
  display: block;
  margin-top: 12px;
  font-size: 28px;
}

.insight-card small,
.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.score-ring {
  width: 92px;
  height: 92px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle, white 58%, transparent 60%),
    conic-gradient(var(--accent) var(--score), #e6ebf1 0);
  color: var(--accent);
}

.score-ring strong {
  margin: 0;
  font-size: 28px;
  line-height: 1;
}

.score-ring span {
  margin-top: -26px;
  color: var(--muted);
  font-size: 11px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.25fr .75fr;
  gap: 18px;
}

.panel {
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  min-height: 64px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #fbfcfe);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-header h2, .panel-header h3 {
  margin: 0;
}

.panel-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.panel-body {
  padding: 18px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th, td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: #f7f9fc;
}

tbody tr {
  transition: background .16s ease;
}

tbody tr:hover {
  background: #fbfdff;
}

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

.muted {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 12px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: linear-gradient(180deg, white, var(--surface-soft));
}

.item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: #fecdca; }
.badge.warning { background: var(--warning-soft); color: var(--warning); border-color: #fedf89; }
.badge.success { background: var(--success-soft); color: var(--success); border-color: #abefc6; }
.badge.neutral { background: #eef2f6; color: #475467; border-color: #d0d5dd; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: #b9e6e5; }

.amount-pill {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-weight: 800;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.search-row input, .search-row select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: var(--ink);
}

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

.client-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .96), rgba(248, 250, 252, .92)),
    white;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  position: relative;
  overflow: hidden;
}

.client-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--accent), var(--gold));
}

.client-card footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mini-list {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

.form-grid label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: white;
}

.form-grid textarea {
  min-height: 92px;
  resize: vertical;
}

.full {
  grid-column: 1 / -1;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 23, 42, .42);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: min(720px, 100%);
  max-height: min(880px, 92vh);
  overflow-y: auto;
  background: white;
  border-radius: 8px;
  box-shadow: 0 26px 70px rgba(15, 23, 42, .26);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
}

#modalForm {
  padding: 18px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

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

.error-box {
  white-space: pre-wrap;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecdca;
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}

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

  .dashboard-grid, .settings-grid, .command-strip {
    grid-template-columns: 1fr;
  }

  .insight-card.wide {
    grid-template-columns: 1fr auto;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-item {
    flex: 0 0 auto;
    padding-right: 16px;
  }

  .sidebar-card {
    display: none;
  }

  .main {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  .kpi-grid, .card-grid, .form-grid {
    grid-template-columns: 1fr;
  }

  .full, .form-actions {
    grid-column: auto;
  }

  h1 {
    font-size: 30px;
  }

  .kpi {
    min-height: 120px;
  }

  .insight-card.wide {
    grid-template-columns: 1fr;
  }
}
