/* Master Panel — same night-violet palette as the Master Player app. */
:root {
  --bg: #1B1030;
  --bg2: #140B26;
  --panel: #26183F;
  --raised: #36245A;
  --line: rgba(181, 124, 255, 0.16);
  --ink: #F3EEFB;
  --muted: #B3A6CF;
  --faint: #8C7FAA;
  --accent: #B57CFF;
  --accent-ink: #1B1030;
  --ok: #5BE3A8;
  --warn: #FFC66B;
  --bad: #FF7A8F;
  --info: #7CC4FF;
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --r: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--sans); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.boot { display: grid; place-items: center; height: 100%; color: var(--muted); }
.mono { font-family: var(--mono); letter-spacing: 0.03em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
  background: radial-gradient(800px 500px at 80% -10%, rgba(181,124,255,.25), transparent 60%), var(--bg); }
.login form { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: grid; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; flex: none; }
.brand .mark svg { width: 20px; height: 20px; fill: #fff; }
.brand b { color: var(--accent); font-weight: 800; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100%; }
.side { background: var(--bg2); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { padding: 4px 8px 16px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 600; }
.nav a svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.nav a:hover { background: var(--panel); color: var(--ink); }
.nav a.on { background: rgba(181,124,255,.16); color: var(--accent); }
.nav .sep { height: 1px; background: var(--line); margin: 10px 6px; }
.side .me { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid var(--line); display: grid; gap: 4px; }
.side .me .email { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.credits-pill { display: inline-flex; gap: 6px; align-items: center; font-family: var(--mono); font-size: 12px; color: var(--accent-ink); background: var(--accent); border-radius: 999px; padding: 2px 10px; width: max-content; }
.main { min-width: 0; padding: 22px max(16px, env(safe-area-inset-right)) 40px 28px; }
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.topbar h1 { font-size: 22px; margin: 0; font-weight: 800; }
.topbar .grow { flex: 1; }
.mobile-bar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; padding-top: max(18px, env(safe-area-inset-top)); }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
  .mobile-bar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20; background: var(--bg2); border-bottom: 1px solid var(--line);
    padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
  .main { padding-left: max(16px, env(safe-area-inset-left)); }
}

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 14px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--raised); }
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: rgba(255,122,143,.35); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { background: transparent; border: 0; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--panel); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }

label.field { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
label.field small { font-weight: 500; color: var(--faint); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.form { display: grid; gap: 14px; }
.err { color: var(--bad); font-weight: 600; }

/* ---------- surfaces ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; min-width: 0; }
.card h2 { margin: 0 0 12px; font-size: 15px; font-weight: 800; }
.stack { display: grid; gap: 16px; }
.cols { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .cols { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 2px; text-decoration: none; color: inherit; }
a.kpi:hover { border-color: var(--accent); }
.kpi .label { font-size: 12px; font-weight: 700; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 12.5px; cursor: pointer; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: rgba(181,124,255,.07); }
td .sub { display: block; color: var(--faint); font-size: 12px; }
.empty { padding: 34px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-active { color: var(--ok); background: rgba(91,227,168,.12); }
.s-trial { color: var(--info); background: rgba(124,196,255,.12); }
.s-expired { color: var(--warn); background: rgba(255,198,107,.12); }
.s-banned { color: var(--bad); background: rgba(255,122,143,.12); }
.s-unused { color: var(--accent); background: rgba(181,124,255,.14); }
.s-used { color: var(--muted); background: rgba(179,166,207,.12); }
.online { color: var(--ok); font-weight: 700; }

/* ---------- chart ---------- */
.chart svg { width: 100%; height: 170px; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar.zero { fill: var(--raised); }
.chart text { fill: var(--faint); font: 11px var(--sans); }
.chart line { stroke: var(--line); }

/* ---------- list ---------- */
.feed { display: grid; gap: 2px; }
.feed div { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.feed div:last-child { border-bottom: 0; }
.feed .when { margin-left: auto; color: var(--faint); font-size: 12px; white-space: nowrap; }

/* ---------- drawer & modal ---------- */
.scrim { position: fixed; inset: 0; background: rgba(8, 4, 16, .6); z-index: 40; display: flex; justify-content: flex-end; }
.drawer { width: min(560px, 100%); height: 100%; background: var(--bg); border-left: 1px solid var(--line); overflow-y: auto;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) 20px; display: grid; gap: 16px; align-content: start; }
.drawer header { display: flex; align-items: center; gap: 10px; }
.drawer header h2 { margin: 0; font-size: 18px; }
.scrim.center { justify-content: center; align-items: center; padding: 16px; }
.modal { width: min(480px, 100%); max-height: 100%; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; display: grid; gap: 16px; }
.modal h2 { margin: 0; font-size: 17px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--faint); font-weight: 600; }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.actions-bar { display: flex; flex-wrap: wrap; gap: 8px; }
.codebox { background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 12px; font-family: var(--mono); font-size: 13px; max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--raised); border: 1px solid var(--line); border-left: 4px solid var(--ok); padding: 10px 14px; border-radius: 10px; max-width: 360px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.bad { border-left-color: var(--bad); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
