:root {
  --bg: #0f1116; --bg-2: #161921; --bg-3: #1d212b; --bg-4: #262b37; --line: #2a2f3b;
  --text: #e6e9ef; --muted: #8f98aa; --faint: #626b7d;
  --accent: #3ee0b0; --accent-ink: #052419; --danger: #ff6b7f; --warn: #f6c66d; --info: #62a8ff; --plum: #2b1530;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13.5px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(62,224,176,.08), transparent 60%), radial-gradient(900px 500px at 110% 110%, rgba(232,103,46,.08), transparent 60%), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: 0 30px 80px rgba(0,0,0,.45); }
.login-card .logo { width: 72px; height: 72px; margin: 0 auto 10px; display: block; }
.login-card h1 { text-align: center; font-size: 18px; margin: 0 0 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 20px; font-size: 13px; }

/* ---------- layout */
.app { display: flex; min-height: 100vh; }
.side { width: 224px; flex: none; background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 10px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; }
.brand img { width: 34px; height: 34px; }
.brand b { display: block; font-size: 14px; }
.brand span { display: block; font-size: 11px; color: var(--muted); }
.nav button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; color: var(--muted); padding: 9px 10px; border-radius: 8px; cursor: pointer; text-align: left; font-size: 13.5px; }
.nav button svg { width: 17px; height: 17px; flex: none; }
.nav button:hover { background: var(--bg-3); color: var(--text); }
.nav button.on { background: var(--bg-4); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav button.on svg { color: var(--accent); }
.side .foot { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 8px 0; font-size: 12px; color: var(--muted); display: grid; gap: 8px; }
.side .foot .who { display: flex; align-items: center; gap: 8px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--plum); color: #f3d9ec; display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.main { flex: 1; min-width: 0; padding: 26px 32px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; font-weight: 700; }
.page-head .sub { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- controls */
.btn { height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-3); cursor: pointer; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.btn:hover { background: var(--bg-4); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 650; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: transparent; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.ghost { background: none; border-color: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; justify-content: center; height: 38px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field .hint { font-size: 11.5px; color: var(--faint); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); padding: 0 11px; outline: none; width: 100%; }
textarea { height: 76px; padding: 8px 11px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=date] { color-scheme: dark; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: inline-flex; gap: 8px; align-items: center; color: var(--muted); cursor: pointer; font-size: 13px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; color: var(--muted); height: 28px; padding: 0 12px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--bg-4); color: var(--text); font-weight: 600; }
.err { color: var(--danger); background: rgba(255,107,127,.1); border-radius: 8px; padding: 8px 11px; font-size: 12.5px; margin-bottom: 12px; }
.note { color: var(--muted); background: var(--bg-3); border-radius: 8px; padding: 9px 12px; font-size: 12.5px; }
.note.warn { color: #f4dfae; background: rgba(246,198,109,.1); }

/* ---------- cards & stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat .v { font-size: 26px; font-weight: 750; margin-top: 4px; letter-spacing: -.01em; }
.stat .s { color: var(--faint); font-size: 12px; margin-top: 2px; }
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 14px; margin: 0 0 12px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-left: auto; font-weight: 400; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.chart { width: 100%; height: 180px; }
.bar-mini { height: 6px; background: var(--bg-4); border-radius: 4px; overflow: hidden; width: 70px; }
.bar-mini span { display: block; height: 100%; background: var(--accent); }
.bar-mini.full span { background: var(--warn); }

/* ---------- tables */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=search] { width: 280px; }
table.t { width: 100%; border-collapse: collapse; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
table.t th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 650; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
table.t td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover td { background: var(--bg-3); }
.who-cell b { display: block; font-weight: 600; }
.who-cell span { color: var(--muted); font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 650; padding: 2px 9px; border-radius: 20px; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.active { color: var(--accent); background: rgba(62,224,176,.12); }
.badge.revoked { color: var(--danger); background: rgba(255,107,127,.12); }
.badge.expired { color: var(--warn); background: rgba(246,198,109,.12); }
.badge.running { color: var(--info); background: rgba(98,168,255,.12); }
.badge.ended { color: var(--muted); background: var(--bg-3); }
.badge.converted { color: var(--accent); background: rgba(62,224,176,.12); }
.tag { font-size: 11px; font-weight: 650; padding: 2px 7px; border-radius: 5px; background: var(--bg-4); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tag.offline { color: #f0a347; background: rgba(240,163,71,.12); }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; background: var(--bg-2); border: 1px dashed var(--line); border-radius: 12px; }

/* ---------- activity list */
.feed { display: grid; gap: 2px; }
.feed .ev { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: start; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.feed .ev:last-child { border-bottom: 0; }
.feed .ev .dot { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; background: var(--bg-4); color: var(--muted); }
.feed .ev .dot svg { width: 13px; height: 13px; }
.feed .ev .dot.good { color: var(--accent); background: rgba(62,224,176,.12); }
.feed .ev .dot.bad { color: var(--danger); background: rgba(255,107,127,.12); }
.feed .ev .dot.info { color: var(--info); background: rgba(98,168,255,.12); }
.feed .ev .txt { min-width: 0; }
.feed .ev .txt .sub { color: var(--faint); font-size: 12px; }
.feed .ev time { color: var(--faint); font-size: 12px; white-space: nowrap; }

/* ---------- drawer & modal */
.scrim { position: fixed; inset: 0; background: rgba(4,6,10,.55); z-index: 40; animation: fade .12s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); background: var(--bg-2); border-left: 1px solid var(--line); z-index: 41; display: flex; flex-direction: column; animation: slide .16s ease-out; box-shadow: -20px 0 60px rgba(0,0,0,.4); }
.drawer header { padding: 18px 20px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.drawer header h2 { margin: 0; font-size: 17px; }
.drawer .body { padding: 18px 20px 40px; overflow: auto; }
.drawer section { margin-bottom: 22px; }
.drawer section > h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); margin: 0 0 10px; font-weight: 700; }
.facts { display: grid; grid-template-columns: 130px 1fr; gap: 7px 12px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.keybox { font-family: var(--mono); font-size: 11.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; word-break: break-all; max-height: 92px; overflow: auto; color: var(--muted); user-select: all; }
.keybox-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; z-index: 42; box-shadow: 0 30px 80px rgba(0,0,0,.5); animation: pop .14s ease-out; }
.modal header { padding: 18px 20px 6px; font-size: 16px; font-weight: 700; }
.modal .body { padding: 10px 20px 4px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; }
.modal footer .left { margin-right: auto; }
.x { width: 30px; height: 30px; border: 0; background: none; color: var(--muted); border-radius: 8px; cursor: pointer; display: grid; place-items: center; margin-left: auto; flex: none; }
.x:hover { background: var(--bg-4); color: var(--text); }
.x svg { width: 16px; height: 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%) scale(.98); } }

#toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--bg-3); border: 1px solid var(--line); padding: 10px 14px; border-radius: 10px; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.35); animation: fade .15s; }
.toast.error { border-color: rgba(255,107,127,.5); }

@media (max-width: 900px) {
  .side { display: none; }
  .main { padding: 18px; }
  .grid2 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
.grid2 { align-items: start; }
[hidden] { display: none !important; }
.table-wrap { overflow-x: auto; border-radius: 12px; }
.mnav { display: none; }
@media (max-width: 900px) {
  .mnav { display: flex; align-items: center; gap: 4px; overflow-x: auto; padding: 10px 12px; background: var(--bg-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .mnav img { width: 26px; height: 26px; margin-right: 6px; flex: none; }
  .mnav button { border: 0; background: none; color: var(--muted); height: 32px; padding: 0 11px; border-radius: 8px; white-space: nowrap; cursor: pointer; }
  .mnav button.on { background: var(--bg-4); color: var(--text); }
  .app { flex-direction: column; }
}
