:root {
  --bg: #0a0e17;
  --panel: #111827;
  --panel-2: #161f31;
  --hover: #1d283f;
  --border: #243047;
  --text: #eef2f8;
  --muted: #8b9bb4;
  --green: #34d399;
  --green-bg: rgba(16, 185, 129, 0.14);
  --blue: #60a5fa;
  --blue-bg: rgba(59, 130, 246, 0.15);
  --amber: #fbbf24;
  --amber-bg: rgba(245, 158, 11, 0.15);
  --red: #f87171;
  --red-bg: rgba(239, 68, 68, 0.15);
  --violet: #c084fc;
  --violet-bg: rgba(168, 85, 247, 0.15);
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 14px; -webkit-font-smoothing: antialiased; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Layout */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 18px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.brand-logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #3b82f6, #8b5cf6); display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; letter-spacing: .5px; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--muted); font-size: 14px; cursor: pointer; text-align: left; transition: all .15s; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--blue-bg); color: var(--blue); border-color: rgba(96, 165, 250, .25); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; font-size: 14px; }
.nav-badge { margin-left: auto; background: var(--green-bg); color: var(--green); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; font-variant-numeric: tabular-nums; }

.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border); }
.conn-pill { display: flex; align-items: center; gap: 8px; padding: 9px 11px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--border); font-size: 12px; }
.user-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.user-bar span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.dot.ok { background: var(--green); box-shadow: 0 0 8px rgba(52, 211, 153, .6); }
.dot.err { background: var(--red); }

/* Main area */
.main-wrap { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 26px; border-bottom: 1px solid var(--border); background: rgba(17, 24, 39, .85); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20; }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; }
.page-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.content { padding: 22px 26px 60px; max-width: 1400px; width: 100%; margin: 0 auto; }
.view { display: none; flex-direction: column; gap: 18px; }
.view.active { display: flex; }

/* Cards & KPIs */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.kpi-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-val { font-size: 28px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 600; }

/* Pool cards */
.pool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.pool-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; transition: border-color .15s; }
.pool-card:hover { border-color: #344767; }
.pool-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pool-name { font-size: 16px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; display: flex; align-items: center; gap: 8px; }
.pool-total { font-size: 12px; color: var(--muted); font-weight: 400; text-transform: none; }

.meter-row { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.meter-big { font-size: 24px; font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }
.meter-bar { height: 7px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.meter-fill { height: 100%; background: linear-gradient(90deg, #10b981, #34d399); border-radius: 99px; transition: width .3s ease; }
.meter-fill.low { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.meter-fill.empty { background: var(--red); }

.chip-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat-chip { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); transition: all .15s; }
.stat-chip:hover { border-color: var(--blue); color: var(--text); }
.stat-chip b { color: var(--text); font-variant-numeric: tabular-nums; }

.checkin-box { background: rgba(59, 130, 246, 0.07); border: 1px solid rgba(59, 130, 246, 0.22); border-radius: 9px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.checkin-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.checkin-progress { height: 5px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.checkin-progress-fill { height: 100%; background: var(--blue); transition: width .3s; }

.pool-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 6px; border-top: 1px solid var(--border); }

/* Controls */
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 7px 13px; cursor: pointer; font-size: 13px; font-weight: 500; transition: all .15s; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover:not(:disabled) { border-color: var(--blue); background: var(--hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: var(--red-bg); border-color: rgba(248, 113, 113, .35); color: var(--red); }
.btn.danger:hover:not(:disabled) { background: rgba(239, 68, 68, .25); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--blue); }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }

.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; gap: 2px; }
.seg button { background: transparent; border: none; color: var(--muted); padding: 5px 11px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 500; }
.seg button.active { background: var(--primary); color: #fff; }

input, select, textarea { background: #0b101b; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px; font-size: 13px; outline: none; font-family: inherit; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
textarea { resize: vertical; line-height: 1.5; }

/* Toggle Switch */
.toggle-chip { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; padding: 5px 10px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--border); }
.toggle-chip input, .switch-wrap input { display: none; }
.switch-wrap { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 12px; }
.switch { width: 38px; height: 22px; background: #293548; border-radius: 99px; position: relative; transition: background .2s; display: inline-block; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
input:checked + .switch { background: #10b981; }
input:checked + .switch::after { transform: translateX(16px); }
.switch.sm { width: 30px; height: 17px; }
.switch.sm::after { width: 13px; height: 13px; top: 2px; left: 2px; }
input:checked + .switch.sm::after { transform: translateX(13px); }

/* Tables */
.filter-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar input[type="search"] { flex: 1; min-width: 200px; }
.table-meta { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: rgba(255, 255, 255, .025); }
tbody tr.clickable { cursor: pointer; }

.pill { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--green-bg); color: var(--green); }
.pill.info { background: var(--blue-bg); color: var(--blue); }
.pill.warn { background: var(--amber-bg); color: var(--amber); }
.pill.bad { background: var(--red-bg); color: var(--red); }
.pill.violet { background: var(--violet-bg); color: var(--violet); }

/* Forms & Grids */
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 14px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--border); }
.setting-title { font-weight: 600; margin-bottom: 2px; }
.info-box { background: #0b101b; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; color: var(--muted); line-height: 1.7; }
.secret-banner { margin-top: 12px; padding: 10px 14px; border-radius: 9px; background: var(--green-bg); border: 1px solid rgba(52, 211, 153, .35); color: var(--green); display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* Playground */
.play-grid { display: grid; grid-template-columns: 420px 1fr; gap: 16px; align-items: start; }
.pg-stage { min-height: 320px; border-radius: 10px; background: #0b101b; border: 1px dashed var(--border); display: grid; place-items: center; padding: 16px; text-align: center; }
.pg-stage img { max-width: 100%; max-height: 520px; border-radius: 8px; box-shadow: 0 12px 32px rgba(0, 0, 0, .5); }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 10px; }
.attempt-item { background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--blue); border-radius: 8px; padding: 10px 12px; }
.attempt-item.ok { border-left-color: var(--green); }
.attempt-item.fail { border-left-color: var(--red); }
.attempt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.attempt-detail { font-size: 12px; color: var(--muted); word-break: break-all; margin-top: 4px; }

/* Slide-over Drawer */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.backdrop.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; width: 540px; max-width: 94vw; height: 100vh; background: var(--panel); border-left: 1px solid var(--border); transform: translateX(100%); transition: transform .22s ease; z-index: 50; display: flex; flex-direction: column; }
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.drawer-title { font-weight: 700; font-size: 15px; }
.drawer-body { padding: 18px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.kv-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.kv { background: var(--panel-2); border-radius: 8px; padding: 9px 11px; }
.kv-k { font-size: 11px; color: var(--muted); }
.kv-v { font-size: 13px; font-weight: 600; margin-top: 2px; word-break: break-all; }

/* Login */
.login-screen { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 24px; background: radial-gradient(1000px 520px at 50% -10%, rgba(59, 130, 246, .2), transparent 55%), var(--bg); }
.login-screen.hidden { display: none; }
.login-card { width: 400px; max-width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px 26px 22px; box-shadow: 0 24px 60px rgba(0, 0, 0, .45); display: flex; flex-direction: column; gap: 12px; }
.login-card .brand { border: none; margin: 0; padding: 0 0 4px; }
.login-card h2 { margin: 0; font-size: 20px; }
.login-card input { width: 100%; }
.login-card .btn.primary { width: 100%; justify-content: center; padding: 10px 14px; }
.login-error { color: var(--red); font-size: 12px; min-height: 18px; }
.login-hint { margin: 0; line-height: 1.5; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); display: none; place-items: center; z-index: 60; }
.modal-backdrop.open { display: grid; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; width: 420px; max-width: 92vw; }
.modal h3 { margin: 0 0 8px; font-size: 16px; }

/* Toast */
.toast-stack { position: fixed; top: 18px; right: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast { background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--blue); border-radius: 9px; padding: 10px 14px; font-size: 13px; box-shadow: 0 10px 28px rgba(0, 0, 0, .45); animation: fadeIn .18s ease; }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .play-grid, .settings-grid { grid-template-columns: 1fr; }
}
