:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --card: #fff;
  --text: #14253c;
  --muted: #53657e;
  --line: #e2e9f3;
  --accent: #245cce;
  --accent-dark: #1746ad;
  --accent-soft: #ebf2ff;
  --nav: #101f39;
  --danger: #a62434;
  --ok: #146343;
  --radius: 14px;
  --shadow: 0 6px 18px #233f6c08;
  font: 14px/1.5 "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body, h1, h2, h3, p, dl, dd { margin: 0; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: clamp(1.65rem, 3vw, 2.05rem); letter-spacing: -.026em; }
h2 { font-size: 1.14rem; }
h3 { font-size: 1rem; }

button, input, select { font: inherit; color: inherit; }
button {
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button:disabled { opacity: .58; cursor: default; }
:focus-visible { outline: 2px solid #2b6be1; outline-offset: 3px; }
button.ghost { border-color: #c9d9f4; color: var(--accent-dark); background: #fff; }
button.ghost:hover { background: var(--accent-soft); }
button.danger { border-color: #f0ced4; color: var(--danger); background: #fff; }
button.danger:hover { background: #fff0f2; }
button.small { min-height: 32px; padding: 4px 9px; font-size: .88rem; }
input, select {
  min-width: 0;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid #cfd9e8;
  border-radius: 8px;
  background: var(--card);
}
input[type="checkbox"] { min-height: 0; width: 17px; height: 17px; accent-color: var(--accent); }
label { display: grid; gap: 6px; color: var(--muted); font-size: .93rem; font-weight: 650; }
label input, label select { color: var(--text); font-size: 1rem; font-weight: 400; }

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at 18% 10%, #e0edff, transparent 50%), #f4f7fc;
}
.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: clamp(22px, 6vw, 36px);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  box-shadow: 0 22px 52px #263f7420;
}
.login-heading { display: grid; gap: 6px; }
.login-heading h1 { font-size: clamp(1.38rem, 4vw, 1.75rem); }
.login-heading p, .page-heading p, .panel-heading p, .pricing-settings p, .hint { color: var(--muted); }
.login-card button { min-height: 44px; }
.error { color: var(--danger); overflow-wrap: anywhere; }
.error:empty { display: none; }

.dashboard { display: grid; grid-template-columns: 214px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 26px;
  height: 100dvh;
  padding: 24px 14px 18px;
  color: #fff;
  background: var(--nav);
}
.brand { display: flex; align-items: center; gap: 10px; }
.sidebar .brand { padding-inline: 6px; }
.brand strong { display: block; font-size: 1.28rem; font-weight: 750; line-height: 1.2; }
.brand div span { color: #bdcbe0; font-size: .82rem; }
.brand-mark { display: block; flex: 0 0 42px; width: 42px; height: 42px; object-fit: contain; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 44px;
  padding-inline: 9px;
  border-color: transparent;
  color: #d4e0f3;
  background: transparent;
  text-align: left;
}
.sidebar nav button:hover { background: #203453; }
.sidebar nav button.active { color: #fff; background: #254779; border-color: #4771ae; }
.nav-icon { display: grid; place-items: center; flex: 0 0 21px; color: #aacbff; font: 700 1.22rem/1 system-ui, sans-serif; }
.sidebar :focus-visible { outline-color: #9bc2ff; }
.sidebar #logout { margin-top: auto; align-self: start; color: #e6efff; background: transparent; border-color: #496080; }
.sidebar #logout:hover { background: #203453; }

.workspace { width: min(100%, 1600px); margin-inline: auto; padding: clamp(16px, 2.8vw, 40px); min-width: 0; }
.page-heading { display: grid; gap: 6px; margin-bottom: 22px; }
.notice {
  padding: 10px 14px;
  margin-bottom: 16px;
  border: 1px solid #c5e7d8;
  border-radius: 9px;
  color: var(--ok);
  background: #edf9f3;
  overflow-wrap: anywhere;
}
.notice:empty { position: absolute; padding: 0; border: 0; margin: 0; }
.notice.bad { color: var(--danger); border-color: #f3ccd4; background: #fff1f3; }
.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; align-items: center; }
.search { width: min(100%, 318px); flex-wrap: nowrap; }
.search input { width: 100%; }
.search button { flex-shrink: 0; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric {
  display: grid;
  align-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.metric dt { color: var(--muted); font-size: .91rem; font-weight: 650; }
.metric dd { color: #1c4ea9; font-size: clamp(1.18rem, 2.4vw, 1.66rem); line-height: 1.18; font-weight: 750; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.panel {
  min-width: 0;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.panel-heading { padding: 15px 17px; }
.panel-heading p, .pricing-settings p { margin-top: 4px; font-size: .91rem; }
.section-grid { display: grid; grid-template-columns: minmax(0, 1.68fr) minmax(0, 1fr); gap: 16px; }
.pricing-settings { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; padding: 15px 17px; }
.pricing-settings input { width: 114px; }

.scroll { overflow-x: auto; border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
.scroll:focus-visible { outline-offset: -3px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { padding: 11px 11px; text-align: left; white-space: nowrap; vertical-align: middle; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 650; font-size: .89rem; background: #f6f9fe; }
td { font-size: .93rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8faff; }
tfoot td { background: #edf3fd; font-weight: 700; border-top: 1px solid var(--line); border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.balance { color: #1746a3; font-weight: 750; }
td input:not([type="checkbox"]) { width: 78px; }
td input.wide:not([type="checkbox"]) { width: 176px; }
td .actions { display: flex; gap: 5px; }
#prices-table :is(th, td):first-child { position: sticky; left: 0; z-index: 1; background: #f6f9fe; box-shadow: 1px 0 var(--line); }
.account { display: flex; gap: 9px; align-items: center; min-width: 0; }
.account-icon { display: grid; place-items: center; flex: 0 0 32px; height: 32px; color: #2355ae; background: var(--accent-soft); border-radius: 9px; font-weight: 750; }
.account strong, .account small { display: block; white-space: normal; overflow-wrap: anywhere; }
.account small { color: var(--muted); font-size: .84rem; }
.status { display: inline-block; padding: 3px 8px; border-radius: 20px; font-weight: 650; font-size: .83rem; }
.status-active { color: var(--ok); background: #e7f6ed; }
.status-blocked { color: var(--danger); background: #fbe9ed; }
.empty { color: var(--muted); text-align: center; padding: 22px 12px; white-space: normal; }

.trend { display: grid; gap: 8px; padding: 0 17px 16px; margin: 0; list-style: none; }
.trend li:not(.empty) { display: grid; grid-template-columns: 6rem minmax(0, 1fr) minmax(2rem, auto); align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.trend strong { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.trend progress { display: block; width: 100%; height: 8px; border: 0; border-radius: 10px; overflow: hidden; background: var(--accent-soft); accent-color: var(--accent); }
.trend progress::-webkit-progress-bar { background: var(--accent-soft); }
.trend progress::-webkit-progress-value { background: var(--accent); border-radius: 10px; }
.trend progress::-moz-progress-bar { background: var(--accent); border-radius: 10px; }

dialog {
  max-width: calc(100% - 24px);
  max-height: calc(100dvh - 24px);
  padding: clamp(15px, 4vw, 24px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--card);
  box-shadow: 0 22px 55px #0c19364a;
}
dialog::backdrop { background: #0c19366e; }
#topup-dialog { width: 430px; }
#topup-form, .dialog-body { display: grid; gap: 12px; }
#topup-user, #history-title { overflow-wrap: anywhere; }
#topup-user { margin-top: 5px; }
#history-dialog { width: 950px; }
.dialog-body .scroll { border: 1px solid var(--line); border-radius: 9px; }

@media (max-width: 1100px) {
  .section-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
}
@media (max-width: 760px) {
  .dashboard { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 10px 14px;
  }
  .sidebar #logout { grid-column: 2; grid-row: 1; margin: 0; align-self: center; }
  .sidebar nav { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar nav button { padding-inline: 8px; white-space: normal; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .page-heading { margin-bottom: 16px; }
  .search { width: 100%; }
  #users-table, #users-table tbody { display: block; }
  #users-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  #users-table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 10px 13px; column-gap: 8px; border-bottom: 1px solid var(--line); }
  #users-table tr:last-child { border-bottom: 0; }
  #users-table td { padding: 5px 0; border: 0; white-space: normal; overflow-wrap: anywhere; text-align: left; }
  #users-table td[data-label]::before { display: block; content: attr(data-label); color: var(--muted); font-size: .81rem; font-weight: 500; }
  #users-table .account-cell { grid-column: 1 / -1; }
  #users-table .action-cell, #users-table .empty { grid-column: 1 / -1; }
  #users-table .actions { flex-wrap: wrap; }
  #users-table .actions button { min-height: 40px; }
}
@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color 160ms ease, border-color 160ms ease; }
}

label.check { display: flex; align-items: center; gap: 8px; }
#packages-form .scroll { border-radius: 0; }
