:root {
  --navy: #17222e;
  --navy-2: #202f3d;
  --ink: #17202a;
  --muted: #778290;
  --line: #e8edf2;
  --canvas: #f4f7f9;
  --green: #52a88c;
  --green-dark: #2e8067;
  --green-pale: #eaf4f0;
  --blue: #627d9a;
  --orange: #dba05d;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--canvas); }
button { font: inherit; cursor: pointer; }
.card, .kpi, .nav-item, .period-tabs button, .horizontal-fill { transition: .18s ease; }
.card.is-hidden { display: none; }
.dashboard-grid:has(.card:not(.is-hidden)) { align-items: start; }
.dashboard-grid.view-products, .dashboard-grid.view-customers { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dashboard-grid.view-products .product-card, .dashboard-grid.view-products .books-card,
.dashboard-grid.view-customers .activity-card, .dashboard-grid.view-customers .card { grid-column: auto; }
.nav-item:active, .period-tabs button:active, .icon-button:active { transform: scale(.96); }
.icon-button.loading { animation: spin .7s linear infinite; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--green-dark); }
.horizontal-row:hover .horizontal-fill { filter: brightness(.94); }
.horizontal-row:hover .horizontal-name { color: var(--ink); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 220px; z-index: 10; display: flex; flex-direction: column; padding: 28px 18px 20px; color: #fff; background: var(--navy); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 10px 38px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: var(--navy); background: #dcece6; font-weight: 800; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 14px; letter-spacing: .2px; }
.brand span { margin-top: 2px; color: #9eabb6; font-size: 11px; }
.sidebar nav { display: grid; gap: 6px; }
.nav-item { width: 100%; border: 0; border-radius: 9px; padding: 12px 13px; display: flex; align-items: center; gap: 11px; color: #aab6c0; background: transparent; text-align: left; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.04); }
.nav-item.active { color: #fff; background: var(--navy-2); box-shadow: inset 3px 0 var(--green); }
.nav-icon { width: 18px; text-align: center; font-size: 16px; }
.sidebar-status { margin-top: auto; display: flex; align-items: center; gap: 10px; border-top: 1px solid rgba(255,255,255,.07); padding: 18px 10px 0; font-size: 11px; }
.sidebar-status strong, .sidebar-status span { display: block; }
.sidebar-status strong { margin-bottom: 3px; }
.sidebar-status div span { color: #91a0ac; }
.status-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(82,168,140,.12); }

main { margin-left: 220px; min-height: 100vh; }
header { height: 96px; padding: 0 38px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.92); }
.eyebrow { margin: 0 0 5px; color: var(--green-dark); font-size: 10px; font-weight: 800; letter-spacing: 1.5px; }
h1 { margin: 0; font-size: 24px; letter-spacing: -.4px; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: #fff; font-size: 18px; }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: var(--navy); background: #dce8e5; font-size: 11px; font-weight: 800; }
.content { padding: 24px 38px 40px; }
.toolbar { height: 42px; margin-bottom: 18px; display: flex; align-items: flex-start; justify-content: space-between; }
.toolbar p { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.period-tabs { height: 38px; display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.period-tabs button { border: 0; padding: 0 13px; border-radius: 6px; color: var(--muted); background: transparent; font-size: 12px; }
.period-tabs button.active { color: var(--navy); background: var(--green-pale); font-weight: 700; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.kpi { min-height: 112px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 4px 14px rgba(23,34,46,.025); }
.kpi-label { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.kpi-icon { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--green-dark); background: var(--green-pale); }
.kpi-value { margin-top: 12px; font-size: 24px; font-weight: 750; letter-spacing: -.5px; }
.kpi-change { margin-top: 6px; color: var(--green-dark); font-size: 11px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .75fr); gap: 14px; }
.card { min-height: 250px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 4px 14px rgba(23,34,46,.025); overflow: hidden; }
.card-header { height: 72px; padding: 17px 20px 12px; display: flex; align-items: flex-start; justify-content: space-between; }
.card-header p { margin: 0 0 4px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; }
.card-header h2 { margin: 0; font-size: 14px; }
.revenue-card { grid-column: span 1; }
.activity-card { grid-column: span 1; }
.product-card, .books-card { min-height: 330px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 10px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 7px; height: 7px; border-radius: 50%; }
.legend .paid { background: var(--green); }
.legend .billed { background: #bbc4cc; }
.line-chart, .bar-chart { height: 178px; padding: 2px 14px 12px 8px; }
.line-chart svg, .bar-chart svg { width: 100%; height: 100%; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 9px; }
.chart-line-paid { fill: none; stroke: var(--green); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-line-billed { fill: none; stroke: #b7c1c9; stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart-area { fill: url(#paidGradient); }
.chart-dot { fill: #fff; stroke: var(--green); stroke-width: 2; }
.activity-bar { fill: var(--green); rx: 3; }
.activity-bar-alt { fill: var(--green-pale); rx: 3; }

.region-list { padding: 2px 20px 18px; }
.region-row { margin-bottom: 13px; }
.region-meta { margin-bottom: 6px; display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.region-meta strong { color: var(--ink); }
.region-track { height: 7px; border-radius: 10px; background: var(--canvas); overflow: hidden; }
.region-fill { height: 100%; border-radius: 10px; background: var(--green); }
.category-content { height: 178px; display: flex; align-items: center; justify-content: center; gap: 20px; padding: 0 20px 16px; }
.donut { width: 132px; height: 132px; flex: none; border-radius: 50%; position: relative; }
.donut::after { content: ""; position: absolute; inset: 24px; border-radius: 50%; background: #fff; }
.donut-center { position: absolute; z-index: 2; inset: 0; display: grid; place-content: center; text-align: center; }
.donut-center strong { font-size: 20px; }
.donut-center span { color: var(--muted); font-size: 9px; }
.category-legend { min-width: 125px; display: grid; gap: 9px; font-size: 10px; }
.category-item { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.category-item strong { color: var(--ink); }
.category-dot { width: 7px; height: 7px; display: inline-block; margin-right: 6px; border-radius: 50%; }
.horizontal-bars { display: grid; gap: 12px; padding: 4px 20px 20px; }
.horizontal-row { display: grid; grid-template-columns: 125px 1fr 40px; align-items: center; gap: 10px; font-size: 10px; }
.horizontal-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.horizontal-track { height: 8px; border-radius: 10px; background: var(--canvas); overflow: hidden; }
.horizontal-fill { height: 100%; border-radius: 10px; background: var(--green); }
.horizontal-row strong { text-align: right; }
.table-wrap { padding: 0 20px 16px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th { padding: 8px 8px; border-bottom: 1px solid var(--line); color: var(--muted); font-weight: 600; text-align: left; }
th:last-child, td:last-child { text-align: right; }
td { padding: 10px 8px; border-bottom: 1px solid #f2f4f6; }
td:first-child { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loading-screen { position: fixed; z-index: 50; inset: 0; display: grid; place-content: center; justify-items: center; color: var(--muted); background: rgba(244,247,249,.9); transition: opacity .2s; }
.loading-screen.hidden { opacity: 0; pointer-events: none; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; }
.loading-screen p { font-size: 12px; }
.login-overlay { position: fixed; z-index: 100; inset: 0; display: grid; place-content: center; background: rgba(23,34,46,.72); backdrop-filter: blur(8px); }
.login-overlay.hidden { display: none; }
.login-card { width: 340px; padding: 28px; border-radius: 14px; background: #fff; box-shadow: 0 24px 70px rgba(0,0,0,.25); }
.login-card > .brand-mark { margin-bottom: 18px; }
.login-card h2 { margin: 4px 0 20px; }
.login-card label { display: grid; gap: 7px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.login-card input, .data-toolbar select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; color: var(--ink); background: #fff; }
.login-card .primary-button { width: 100%; margin-top: 14px; }
.login-error { min-height: 18px; margin: 8px 0 0; color: #b04b4b; font-size: 11px; }
.primary-button, .secondary-button { border: 0; border-radius: 8px; padding: 9px 13px; font-size: 12px; }
.primary-button { color: #fff; background: var(--green-dark); }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: #fff; }
.data-manager { min-height: 420px; }
.data-toolbar { height: 58px; padding: 9px 20px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.data-toolbar select { width: 180px; padding: 8px 10px; }
.record-table td:nth-child(3) { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-actions { display: flex; gap: 6px; justify-content: flex-end; }
.record-actions button { border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; color: var(--muted); background: #fff; font-size: 10px; }
.record-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.record-summary span { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 999px; padding: 4px 7px; color: var(--ink); background: #eef4f1; }
dialog { width: min(620px, calc(100vw - 32px)); border: 0; border-radius: 12px; padding: 0; color: var(--ink); box-shadow: 0 24px 70px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(23,34,46,.45); }
.dialog-header { height: 62px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 16px; }
#record-form { display: grid; }
#record-json { height: 360px; margin: 18px; resize: vertical; font-family: ui-monospace, monospace; font-size: 12px; }
.record-fields { max-height: 520px; overflow-y: auto; margin: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.record-field { display: grid; gap: 6px; color: var(--muted); font-size: 11px; }
.record-field.full { grid-column: 1 / -1; }
.record-field input, .record-field select, .record-field textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: var(--ink); background: #fff; font: inherit; }
.record-field textarea { min-height: 72px; resize: vertical; }
#record-book-select { margin: 0; width: 100%; }
.dialog-actions { padding: 0 18px 18px; display: flex; justify-content: flex-end; gap: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1050px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .revenue-card, .activity-card { grid-column: span 1; }
}
@media (max-width: 720px) {
  .sidebar { position: static; width: 100%; height: 68px; padding: 10px 16px; flex-direction: row; align-items: center; }
  .brand { padding: 0; }
  .brand div:last-child, .sidebar-status { display: none; }
  .sidebar nav { margin-left: auto; display: flex; }
  .nav-item { width: 42px; height: 42px; justify-content: center; padding: 0; }
  .nav-item span:last-child { display: none; }
  main { margin-left: 0; }
  header { height: 82px; padding: 0 18px; }
  .content { padding: 18px; }
  .toolbar { height: auto; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi { min-height: 100px; padding: 15px; }
  .kpi-value { font-size: 19px; }
}
