:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --surface-muted: #eef2f6;
  --ink: #17212b;
  --muted: #647282;
  --line: #dfe5ec;
  --line-strong: #cbd5df;
  --navy: #12202d;
  --navy-soft: #1d3142;
  --accent: #0b7a70;
  --accent-strong: #075c55;
  --accent-soft: #e5f5f2;
  --good: #16834b;
  --warn: #a46611;
  --danger: #bb3028;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 10px 28px rgba(16, 24, 40, .07);
  --radius: 12px;
}

html.dark {
  --bg: #111827;
  --surface: #182230;
  --surface-subtle: #202c3d;
  --surface-muted: #273548;
  --ink: #e9eef6;
  --muted: #9caabd;
  --line: #2c3b4f;
  --line-strong: #3a4c62;
  --navy: #101827;
  --navy-soft: #1d2a3c;
  --accent-soft: #153f3b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.18);
  --shadow-md: 0 16px 34px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(11,122,112,.28); outline-offset: 2px; }

.app { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 28px; padding: 26px 18px 18px; background: var(--navy); color: #eef4f7; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand img { width: 42px; height: 42px; border-radius: 11px; object-fit: cover; border: 1px solid rgba(255,255,255,.18); }
.brand-title strong { display: block; font-size: 16px; letter-spacing: .02em; }
.brand-title span { display: block; margin-top: 2px; color: #9eb0bd; font-size: 12px; }
.nav { display: grid; gap: 5px; }
.nav button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: #b7c5cf; text-align: left; cursor: pointer; transition: background .16s, color .16s; }
.nav button:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav button.active { background: var(--navy-soft); border-color: rgba(255,255,255,.08); color: #fff; box-shadow: inset 3px 0 var(--accent); }
.nav .icon { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: rgba(255,255,255,.08); color: #dce8ed; font-size: 12px; font-weight: 800; }
.nav button.active .icon { background: var(--accent); color: #fff; }
.sidebar-note { margin-top: auto; padding: 13px 14px; border: 1px solid rgba(255,255,255,.1); border-radius: 9px; background: rgba(255,255,255,.045); color: #9eb0bd; font-size: 12px; line-height: 1.5; }

main { min-width: 0; padding: 34px clamp(20px, 4vw, 56px) 52px; }
.topbar { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; margin-bottom: 28px; }
.eyebrow, .panel-kicker { margin: 0 0 6px; color: var(--accent); font-size: 10px; font-weight: 850; letter-spacing: .13em; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.icon-button { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--muted); cursor: pointer; font-size: 18px; box-shadow: var(--shadow-sm); }
.icon-button:hover { color: var(--accent); border-color: #70b9b1; }
h1 { margin: 0; font-size: clamp(24px, 2.5vw, 32px); line-height: 1.15; letter-spacing: -.025em; }
.subtitle { max-width: 700px; margin: 9px 0 0; color: var(--muted); }
.status-pill { display: inline-flex; align-items: center; gap: 8px; min-height: 34px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); white-space: nowrap; box-shadow: var(--shadow-sm); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px rgba(22,131,75,.12); }
.dot.error { background: var(--danger); box-shadow: 0 0 0 3px rgba(187,48,40,.12); }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.metric, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.metric { min-height: 126px; padding: 18px 20px; display: flex; flex-direction: column; justify-content: space-between; }
.metric span { color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: .01em; }
.metric strong { margin-top: 13px; font-size: 30px; line-height: 1; letter-spacing: -.03em; }
.metric small { margin-top: 9px; color: var(--muted); font-size: 12px; }
.metric-icon { display: inline-grid; place-items: center; width: 36px; height: 36px; margin-bottom: 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 18px; font-weight: 800; }
.metric-users .metric-icon { color: #5850ec; background: #eeedff; } .metric-subscriptions .metric-icon { color: #0b7a70; background: #e5f5f2; } .metric-keys .metric-icon { color: #ca8a04; background: #fff6d8; } .metric-balance .metric-icon { color: #c2410c; background: #fff0e8; }
html.dark .metric-users .metric-icon { background:#2a2856; } html.dark .metric-keys .metric-icon { background:#4d3c14; } html.dark .metric-balance .metric-icon { background:#4b291d; }

.toolbar { display: grid; grid-template-columns: minmax(260px, 1fr) 190px 180px; gap: 10px; margin: 20px 0; }
.field { display: flex; align-items: center; gap: 9px; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.field:focus-within { border-color: #70b9b1; box-shadow: 0 0 0 3px rgba(11,122,112,.1); }
.field span { color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.field input, .field select { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); }

.section { display: none; }
.section.active { display: block; }
.overview-grid, .server-renewal-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, .75fr); gap: 18px; }
.analytics-grid { display: grid; grid-template-columns: minmax(380px, 1.35fr) minmax(260px, .8fr) minmax(260px, .85fr); gap: 18px; margin-bottom: 18px; }
.chart-panel, .distribution-panel, .insight-panel { min-height: 266px; }
.chart-total { color: var(--accent) !important; font-weight: 750; }
.chart-wrap { height: 194px; padding: 17px 20px 16px; }
.bar-chart { display: flex; align-items: end; justify-content: space-between; gap: 10px; height: 100%; }
.bar-column { display: grid; grid-template-rows: 20px 1fr 17px; align-items: end; flex: 1; min-width: 24px; height: 100%; text-align: center; }
.bar-value, .bar-column small { color: var(--muted); font-size: 10px; font-weight: 700; }.bar-track { display: flex; align-items: end; height: 100%; border-radius: 5px 5px 0 0; background: repeating-linear-gradient(to bottom, transparent 0, transparent 32%, var(--line) 33%, transparent 34%); }.bar { width: 100%; min-height: 4px; border-radius: 5px 5px 0 0; background: linear-gradient(180deg, #20b9a8, var(--accent)); transition: height .3s ease; }
.distribution-content { display: flex; align-items: center; gap: 21px; padding: 26px 20px; }.donut { --progress: 0deg; position: relative; display: grid; place-items: center; flex: 0 0 auto; width: 118px; height: 118px; border-radius: 50%; background: conic-gradient(var(--accent) var(--progress), var(--surface-muted) 0); }.donut::after { content:""; position:absolute; width:82px; height:82px; border-radius:50%; background:var(--surface); }.donut span { position:relative; z-index:1; font-size:20px; font-weight:800; }.legend-list { display:grid; gap:12px; width:100%; }.legend-list div { display:grid; grid-template-columns: 10px 1fr auto; gap:7px; align-items:center; color:var(--muted); font-size:12px; }.legend-list strong { color:var(--ink); }.legend-dot { width:8px; height:8px; border-radius:50%; }.legend-dot.assigned { background:var(--accent); }.legend-dot.free { background:#94a3b8; }.legend-dot.total { background:#6366f1; }
.insight-panel { padding: 22px 20px; }.insight-panel h2 { margin:0 0 17px; font-size:16px; }.insight-list { display:grid; gap:10px; }.insight-item { display:flex; align-items:flex-start; gap:9px; padding:10px 11px; border:1px solid var(--line); border-radius:9px; color:var(--muted); font-size:12px; line-height:1.35; }.insight-item b { display:grid; place-items:center; flex:0 0 auto; width:17px; height:17px; border-radius:50%; color:#fff; font-size:11px; }.insight-item.ok b { background:var(--good); }.insight-item.warning b { background:var(--warn); }.insight-item.danger b { background:var(--danger); }
.server-renewal-grid { grid-template-columns: minmax(320px, .9fr) minmax(420px, 1.1fr); }
.panel { overflow: hidden; }
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 17px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.panel-header h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.panel-header span { color: var(--muted); font-size: 12px; }
.panel-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }

.button { min-height: 36px; padding: 8px 13px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; cursor: pointer; transition: background .15s, transform .15s; }
.button:hover { background: var(--accent-strong); }
.button:active { transform: translateY(1px); }
.button:disabled { cursor: not-allowed; opacity: .6; }
.button.secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.button.secondary:hover { background: var(--surface-subtle); }
.button.danger { background: #fff6f5; border-color: #efb8b2; color: var(--danger); }
.button.danger:hover { background: #ffebe9; }

.subscription-actions, .promo-code-actions { display: flex; justify-content: flex-end; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--surface-subtle); }
.add-subscription, .add-promo-code { display: none; gap: 10px; align-items: start; padding: 16px 20px; border-bottom: 1px solid var(--line); background: var(--surface-subtle); }
.add-subscription { grid-template-columns: minmax(240px,1fr) auto auto; }
.add-promo-code { grid-template-columns: minmax(180px,1fr) 140px 170px auto auto; }
.add-subscription.active, .add-promo-code.active { display: grid; }
.form-message { grid-column: 1 / -1; min-height: 18px; color: var(--muted); font-size: 12px; }
.form-message.error { color: var(--danger); } .form-message.success { color: var(--good); }

/* Inline balance editor stays collapsed until the row action is triggered. */
.balance-form-row { display: none; }
.balance-form-row.active { display: table-row; }
.balance-form { display: grid; grid-template-columns: minmax(120px, 180px) minmax(180px, 1fr) auto auto; gap: 10px; align-items: start; padding: 12px 0; }
.balance-form .field { min-height: 38px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 720px; border-collapse: collapse; }
th, td { padding: 13px 18px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; line-height: 1.4; }
th { color: #748293; background: var(--surface-subtle); font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
tbody tr { transition: background .12s; } tbody tr:hover { background: var(--surface-subtle); }
.row-action { width: 1%; white-space: nowrap; }
.empty { padding: 26px 18px; color: var(--muted); text-align: center; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.balance { font-weight: 750; } .positive { color: var(--good); } .negative { color: var(--danger); }
.badge { display: inline-flex; align-items: center; min-height: 23px; padding: 3px 8px; border-radius: 999px; border: 1px solid transparent; font-size: 11px; font-weight: 750; white-space: nowrap; }
.badge.good { color: var(--good); background: #e9f7ef; border-color: #bde6cc; } .badge.warn { color: var(--warn); background: #fff5e3; border-color: #f0d29b; } .badge.danger { color: var(--danger); background: #fff0ee; border-color: #f1bab4; }

.list { display: grid; gap: 0; padding: 8px 20px; }
.list-row { display: grid; grid-template-columns: 125px minmax(0,1fr); gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; } .list-row span { color: var(--muted); font-size: 12px; } .list-row strong { min-width: 0; overflow-wrap: anywhere; }
.server-metrics { grid-template-columns: repeat(5, minmax(0,1fr)); }
.renewal-timeline { min-height: 244px; padding: 20px; }
.timeline-item { position: relative; display: grid; grid-template-columns: 98px minmax(0,1fr); gap: 14px; padding: 0 0 18px; }
.timeline-item::before { content: ""; position: absolute; top: 8px; bottom: -8px; left: 104px; width: 1px; background: var(--line); } .timeline-item:last-child::before { display: none; }
.timeline-date { color: var(--muted); font-size: 12px; text-align: right; } .timeline-content { position: relative; padding-left: 18px; } .timeline-content::before { content: ""; position: absolute; top: 4px; left: -4px; width: 10px; height: 10px; border: 2px solid var(--surface); border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1px var(--accent); } .timeline-item.overdue .timeline-content::before { background: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.timeline-item h3 { margin: 0; font-size: 14px; } .timeline-item p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.server-renewal-form { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; padding: 20px; } .server-renewal-form .field { display: grid; align-items: center; min-height: 44px; padding: 7px 12px; } .server-renewal-form .field span { font-size: 11px; } .server-renewal-form-wide { grid-column: 1 / -1; }
.check-field { display: flex; align-items: center; gap: 9px; min-height: 30px; color: var(--muted); font-size: 12px; } .check-field input { width: 16px; height: 16px; accent-color: var(--accent); }
.server-renewal-form-actions, .dialog-actions, .subscription-detail-actions { display: flex; flex-wrap: wrap; gap: 9px; } .server-renewals-panel { margin-top: 18px; } .server-renewals-table { min-width: 960px; }
.payment-link { display: inline-flex; align-items: center; min-height: 32px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--accent); font-size: 12px; font-weight: 700; text-decoration: none; } .payment-link:hover { background: var(--accent-soft); }
.payment-dialog { width: min(100% - 32px, 440px); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-md); } .payment-dialog::backdrop { background: rgba(18,32,45,.46); } .server-payment-form { display: grid; gap: 14px; padding: 22px; } .server-payment-form h2 { margin: 0; font-size: 18px; } .server-payment-form p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

@media (max-width: 1240px) { .analytics-grid { grid-template-columns: minmax(380px,1.2fr) minmax(270px,.8fr); }.insight-panel { grid-column: 1 / -1; min-height: auto; }.insight-list { grid-template-columns: repeat(3,1fr); } }
@media (max-width: 1120px) { .app { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; padding: 18px 20px; gap: 18px; } .nav { grid-template-columns: repeat(3,minmax(0,1fr)); } .nav button { justify-content: center; } .sidebar-note { display: none; } .metrics { grid-template-columns: repeat(2,minmax(0,1fr)); } .server-metrics { grid-template-columns: repeat(3,minmax(0,1fr)); } .overview-grid, .server-renewal-grid, .analytics-grid { grid-template-columns: 1fr; }.insight-panel { grid-column:auto; }.insight-list { grid-template-columns: 1fr; } }
@media (max-width: 720px) { main { padding: 22px 16px 36px; } .topbar { display: grid; gap: 14px; } .topbar-actions { flex-wrap:wrap; }.status-pill { justify-self: start; white-space: normal; } .metrics, .server-metrics, .toolbar, .nav, .add-subscription, .add-promo-code, .server-renewal-form { grid-template-columns: 1fr; } .nav button { justify-content: flex-start; } .metric { min-height: 108px; } .metric strong { font-size: 26px; } .panel-header { padding: 15px 16px; } th, td { padding: 12px 14px; } .list { padding: 8px 16px; } .list-row { grid-template-columns: 1fr; gap: 3px; } .timeline-item { grid-template-columns: 74px minmax(0,1fr); } .timeline-item::before { left: 80px; }.distribution-content { justify-content:center; }.chart-wrap { padding-inline:14px; } }
