/* Until the backend confirms an admin (admin.js init), nothing of the page is shown. */
body.admin-body:not(.admin-ok) .adm { display: none; }

/* Atlas admin — the console's tokens (style.css :root) + validated chart series (dark). */
.admin-body {
  height: auto;
  min-height: 100%;
  overflow-y: auto;
  /* Categorical slots 1-4, dark steps, validated on #161922 (scripts/validate_palette.js): all checks pass. */
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --grid: #262b38;
}

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

/* ---------- navigation ---------- */
.adm-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 20px 12px;
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.adm-brand { padding: 0 8px 18px; }
.adm-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
}
.adm-link span { width: 20px; text-align: center; }
.adm-link:hover { background: var(--panel-2); color: var(--text); }
.adm-link.active { background: rgba(124, 92, 255, 0.16); color: var(--text); }
.adm-back { margin-top: auto; }

/* ---------- filter bar ---------- */
.adm-content { min-width: 0; padding: 0 24px 60px; }
.adm-filters {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: opacity 0.2s;
}
.adm-filters.dim { opacity: 0.45; }
.adm-range { display: flex; align-items: center; gap: 6px; }
.adm-range input {
  margin: 0;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  color-scheme: dark;
}
.adm-period-label { font-size: 12.5px; }

.seg { display: inline-flex; gap: 3px; padding: 3px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.seg button { border: none; background: transparent; color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 6px 11px; border-radius: 7px; cursor: pointer; }
.seg button.active { background: var(--panel-2); color: var(--text); }

.admin-gate { padding: 60px; text-align: center; color: var(--muted); }
.admin-gate a { color: var(--accent-2); }

/* ---------- sections ---------- */
.adm-section { padding-top: 18px; transition: opacity 0.2s; }
.adm-section.loading { opacity: 0.5; }
.adm-title { margin: 0 0 14px; font-size: 20px; font-weight: 700; }

.chip-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.chip-label { font-size: 12px; color: var(--muted); margin-left: 4px; }
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chips-inline { margin-bottom: 12px; }
.chips button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.chips button:hover { color: var(--text); border-color: var(--accent); }
.chips button.on { background: rgba(124, 92, 255, 0.2); border-color: var(--accent); color: var(--text); }
.chips button.on::before { content: "✓ "; font-weight: 800; }
.chips-reset { margin: 0; }
.adm-search, .chip-row select {
  max-width: 240px;
  margin: 0;
  padding: 7px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
}
.order-btn { padding: 6px 11px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpis-small .kpi-value { font-size: 22px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 26px; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 16px; color: var(--muted); }
.kpi-sub { font-size: 11.5px; color: var(--muted); }

/* ---------- cards & charts ---------- */
.adm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card-wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 14px; font-weight: 700; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg-key { width: 10px; height: 10px; border-radius: 3px; }

.chart { width: 100%; min-height: 120px; }
.svg-chart { display: block; overflow: visible; }
.svg-chart .grid { stroke: var(--grid); stroke-width: 1; }
.svg-chart .tick { fill: var(--muted); font-size: 10.5px; font-family: inherit; font-variant-numeric: tabular-nums; }
.svg-chart .hit { fill: transparent; cursor: crosshair; }
.svg-chart .hit.on { fill: rgba(255, 255, 255, 0.05); }
.svg-chart .hit-all { fill: transparent; cursor: crosshair; }
.svg-chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.svg-chart .cross-dot { stroke: var(--panel); stroke-width: 2; }
.chart-empty { padding: 30px 0; text-align: center; color: var(--muted); font-size: 13px; }

.chart-tip {
  position: fixed;
  z-index: 2000;
  pointer-events: none;
  min-width: 150px;
  padding: 9px 11px;
  background: #0f1115;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  font-size: 12px;
}
.chart-tip[hidden] { display: none; }
.tip-title { color: var(--muted); margin-bottom: 6px; }
.tip-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.tip-key { width: 12px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.tip-row b { font-variant-numeric: tabular-nums; min-width: 52px; }
.tip-label { color: var(--muted); }
.tip-total { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); font-weight: 700; }

.tbl-toggle { margin-top: 8px; font-size: 12px; }
.tbl-toggle summary { color: var(--accent-2); }
.table-mini { margin-top: 8px; }

/* horizontal bars */
.hbar { display: grid; grid-template-columns: minmax(90px, 36%) 1fr auto; gap: 10px; align-items: center; margin: 8px 0; font-size: 12.5px; }
.hbar:focus { outline: 1px solid var(--accent); border-radius: 6px; }
.hbar-label { display: flex; align-items: center; gap: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.hbar-track { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.hbar-track span { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.hbar-value { color: var(--muted); white-space: nowrap; font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---------- feedback ---------- */
.feedback-list { display: flex; flex-direction: column; gap: 8px; }
.fb { border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--panel-2); }
.fb-r1, .fb-r2 { border-left-color: #d03b3b; }
.fb-r3 { border-left-color: #fab219; }
.fb-r4, .fb-r5 { border-left-color: #0ca30c; }
.fb-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12px; }
.fb-stars { color: #f5b301; letter-spacing: 1px; }
.fb-q, .fb-comment { margin-top: 6px; font-size: 13px; }
.fb-a { margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.fb-a p { margin: 6px 0 0; white-space: pre-line; color: var(--text); }

/* ---------- users ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr[data-user] { cursor: pointer; }
.table tbody tr[data-user]:hover, .table tbody tr[data-user]:focus { background: var(--panel-2); outline: none; }
.role { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.role-admin { background: rgba(124, 92, 255, 0.18); color: #c9bcff; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 10px; font-size: 12px; }
.pager .btn:disabled { opacity: 0.4; cursor: default; }

.empty-card { text-align: center; padding: 40px 18px; }
.empty-icon { font-size: 34px; margin-bottom: 8px; }

/* ---------- user drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 1000; background: rgba(15, 17, 21, 0.7); display: flex; justify-content: flex-end; }
.drawer[hidden] { display: none; }
.drawer-card { position: relative; width: min(460px, 100%); height: 100%; overflow-y: auto; background: var(--panel);
  border-left: 1px solid var(--border); padding: 24px 22px; }
.drawer-close { position: absolute; top: 16px; right: 16px; }
.drawer-title { margin: 0 0 4px; font-size: 20px; }
.drawer-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0; }
.drawer-stats div { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; text-align: center; }
.drawer-stats b { display: block; font-size: 15px; }
.drawer-stats span { font-size: 11px; color: var(--muted); }
.drawer-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.btn-danger { background: rgba(255, 107, 107, 0.12); border: 1px solid rgba(255, 107, 107, 0.4); color: var(--error); }
.drawer-actions .btn:disabled { opacity: 0.4; cursor: default; }
.drawer-card h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.logins { display: flex; flex-direction: column; gap: 8px; }
.login { border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; font-size: 12.5px; background: var(--panel-2); }
.login-fail { border-color: rgba(208, 59, 59, 0.45); }
.tag { margin-left: 6px; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  background: rgba(250, 178, 25, 0.15); color: #fab219; }
.tag::before { content: "⚠ "; }

@media (max-width: 900px) {
  .adm { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .adm-nav { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; flex-wrap: nowrap;
    overflow-x: auto; gap: 4px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    border-right: none; border-bottom: 1px solid var(--border); scrollbar-width: none; }
  .adm-nav::-webkit-scrollbar { display: none; }
  .adm-link { flex: 0 0 auto; white-space: nowrap; }
  .adm-brand { display: none; }
  .adm-back { margin-top: 0; }
  .adm-content { padding: 0 16px 40px; }
  .adm-grid { grid-template-columns: 1fr; }
  .drawer-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- credits ---------- */
.price-editor { display: flex; flex-direction: column; gap: 4px; }
.price-edit { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0;
  border-bottom: 1px solid var(--border); font-size: 12.5px; }
.price-edit input { width: 76px; margin: 0; padding: 6px 8px; text-align: right; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); font: inherit; font-weight: 700; }
.price-edit input.saved { border-color: #0ca30c; }
.price-edit input.failed { border-color: #d03b3b; }
.drawer-credits { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; padding: 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; }
.drawer-credits > div { display: flex; justify-content: space-between; align-items: center; }
.drawer-credits b { font-size: 18px; }
.grant-form { display: grid; grid-template-columns: 110px 1fr auto; gap: 6px; }
.grant-form input { margin: 0; padding: 7px 9px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font: inherit; font-size: 12.5px; }
.plus { color: #22c55e; font-weight: 700; }
.minus { color: var(--muted); font-weight: 700; }

.credits-rule { font-size: 12px; margin-bottom: 8px; line-height: 1.45; }

/* Beta test card */
.beta-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; align-items: end; margin-bottom: 10px; }
.beta-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.beta-form input[type=number], .beta-form input[type=datetime-local] { margin: 0; padding: 7px 9px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); font: inherit; }
.beta-form .beta-toggle { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.beta-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.beta-note { font-size: 12px; line-height: 1.45; margin-bottom: 10px; }
.kpis-compact { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); margin-bottom: 10px; }
.budget-line { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; margin: 4px 0 6px; }
.budget-fill { height: 100%; background: var(--s4); border-radius: 999px; }
.budget-text { font-size: 12px; line-height: 1.45; }
.tag-ok { background: rgba(25, 158, 112, 0.18); color: #3ccf98; }
.tag-off { background: rgba(255, 255, 255, 0.08); color: var(--muted); }
@media (max-width: 640px) { .beta-form { grid-template-columns: 1fr; } }

/* ---------- phone: every table row becomes a card (labels from the header, admin.js labelTables) ---------- */
@media (max-width: 600px) {
  .table-wrap { overflow-x: visible; }
  .table:not(.table-mini) thead { display: none; }
  .table:not(.table-mini), .table:not(.table-mini) tbody, .table:not(.table-mini) tr,
  .table:not(.table-mini) td { display: block; width: 100%; }
  .table:not(.table-mini) tr { padding: 10px 12px; margin-bottom: 10px; border: 1px solid var(--border);
    border-radius: 12px; background: var(--panel-2); }
  .table:not(.table-mini) td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    padding: 4px 0; border-bottom: none; text-align: right; font-size: 13.5px; overflow-wrap: anywhere; }
  .table:not(.table-mini) td::before { content: attr(data-label); flex: 0 0 auto; color: var(--muted);
    font-size: 12px; text-align: left; }
  /* The first cell is the card's title (name / place / date) — full width, no label. */
  .table:not(.table-mini) td:first-child { display: block; text-align: left; padding-bottom: 6px; font-size: 14.5px; }
  .table:not(.table-mini) td:first-child::before { content: none; }
  .table:not(.table-mini) td[colspan] { display: block; text-align: center; }
  .table:not(.table-mini) td[colspan]::before { content: none; }
  .table tbody tr[data-user]:active { background: var(--border); }
  .pager button, .seg button, .adm-link { min-height: 40px; }
}

/* ---------- phone: bar lists — the label gets its own line, so emails / model names aren't cut ---------- */
@media (max-width: 600px) {
  .hbar { grid-template-columns: 1fr auto; row-gap: 4px; margin: 10px 0; }
  .hbar-label { grid-column: 1 / -1; white-space: normal; overflow-wrap: anywhere; font-size: 13px; }
  .hbar-track { grid-column: 1; }
  .hbar-value { grid-column: 2; }
  /* the user drawer: amount + comment side by side, the button under them */
  .grant-form { grid-template-columns: 1fr 1fr; }
  .grant-form .btn, .grant-form button { grid-column: 1 / -1; min-height: 40px; }
}

/* ---------- phone / tablet: one sticky bar (the sections). The period bar used to stick at top: 0 too and slid
   under / over the section bar while scrolling — it now scrolls with the page. ---------- */
@media (max-width: 900px) {
  .adm-filters { position: static; z-index: auto; }
}

/* an account blocked by failed logins */
.blocked-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin: 10px 0 4px; padding: 10px 12px; border-radius: 10px; font-size: 13px;
  background: rgba(208, 59, 59, 0.12); border: 1px solid rgba(208, 59, 59, 0.45); }
.role-blocked { background: rgba(208, 59, 59, 0.16); color: #ff8a8a; }
