:root {
  --bg: #0e1014;
  --surface: #15181f;
  --surface2: #1c2029;
  --border: #2a2f3a;
  --text: #e8ecef;
  --text2: #8b95a5;
  --accent: #f97316;
  --accent2: #fb923c;
  --green: #22c55e;
  --red: #ef4444;
  --shadow: 0 4px 16px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent2); }

button { font-family: inherit; }

/* ── Header ──────────────────────────────────────────────────────────── */
.adb-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 10;
}
.header-left { display: flex; gap: 18px; align-items: center; }
.header-right { display: flex; gap: 8px; align-items: center; }
.logo { font-weight: 700; font-size: 18px; color: var(--text); }
.logo span { color: var(--accent); }
.back-link { font-size: 13px; color: var(--text2); }
.role-badge {
  padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.5px;
}
.role-badge.admin { background: var(--accent); color: #000; }

.btn-secondary {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 6px; font-size: 12px; cursor: pointer;
  transition: all 120ms ease;
}
.btn-secondary:hover { background: var(--border); }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Controls bar ────────────────────────────────────────────────────── */
.adb-controls {
  display: flex; gap: 12px; align-items: flex-end;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.control-group { display: flex; flex-direction: column; gap: 4px; }
.control-group.grow { flex: 1; max-width: 480px; }
.control-group label {
  font-size: 11px; color: var(--text2); text-transform: uppercase;
  letter-spacing: 0.5px;
}
.control-group input,
.control-group select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font-size: 13px; min-width: 140px;
}
.control-group input:focus,
.control-group select:focus { outline: none; border-color: var(--accent); }
.control-group.grow input { width: 100%; }

/* ── Status line ─────────────────────────────────────────────────────── */
.adb-status {
  padding: 8px 20px; font-size: 12px; color: var(--text2);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.adb-status.error { color: var(--red); }

/* ── Table ───────────────────────────────────────────────────────────── */
.adb-table-wrap {
  overflow-x: auto; overflow-y: visible;
  padding: 0; max-height: calc(100vh - 220px);
}
.adb-table {
  width: max-content; min-width: 100%;
  border-collapse: collapse; font-size: 12px;
}
.adb-table th,
.adb-table td {
  padding: 6px 10px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis;
}
.adb-table th {
  background: var(--surface);
  position: sticky; top: 0;
  font-weight: 600; text-align: left; color: var(--text2);
  text-transform: lowercase;
  z-index: 1;
}
.adb-table tr:nth-child(even) td { background: rgba(255,255,255,0.018); }
.adb-table tbody tr { cursor: pointer; transition: background 80ms ease; }
.adb-table tbody tr:hover td { background: var(--surface2); }
.adb-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.adb-table td.bool-true { color: var(--green); }
.adb-table td.bool-false { color: var(--text2); }
.adb-table td.null { color: var(--text2); font-style: italic; }
.cell-monospace { font-family: ui-monospace, 'JetBrains Mono', monospace; font-size: 11px; }

/* ── Footer / pagination ─────────────────────────────────────────────── */
.adb-footer {
  display: flex; gap: 12px; align-items: center; justify-content: center;
  padding: 12px; border-top: 1px solid var(--border); background: var(--surface);
  position: sticky; bottom: 0;
}
.adb-footer #pageInfo { font-size: 12px; color: var(--text2); min-width: 120px; text-align: center; }

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
  max-width: 920px; width: 100%; max-height: 90vh;
  overflow-y: auto; padding: 24px; position: relative;
}
.modal h2 { margin: 0 0 16px; font-size: 18px; color: var(--accent); }
.modal h3 { margin: 16px 0 8px; font-size: 13px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.modal-close {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; color: var(--text2);
  font-size: 22px; line-height: 1; border-radius: 8px; cursor: pointer; padding: 0;
  transition: all 150ms ease;
}
.modal-close:hover { color: var(--text); border-color: var(--border); background: var(--surface2); }

.detail-section { margin-bottom: 18px; }
.detail-section .hint { color: var(--text2); font-size: 12px; margin: 6px 0 0; }

.kv-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.kv-table td {
  padding: 5px 10px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.kv-table td.k {
  color: var(--text2); width: 35%;
  font-family: ui-monospace, 'JetBrains Mono', monospace;
  font-size: 11px;
}
.kv-table td.v {
  word-break: break-word;
  font-family: ui-monospace, 'JetBrains Mono', monospace;
  font-size: 11px;
}
.kv-table td.v.null { color: var(--text2); font-style: italic; }

/* ── Toasts ──────────────────────────────────────────────────────────── */
#toastContainer {
  position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px;
  z-index: 1000; pointer-events: none;
}
.toast {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 6px; font-size: 13px;
  box-shadow: var(--shadow); animation: toast-in 200ms ease;
}
.toast.error { border-left-color: var(--red); }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@media (max-width: 720px) {
  .adb-controls { flex-direction: column; align-items: stretch; }
  .control-group.grow { max-width: none; }
  .adb-table-wrap { max-height: calc(100vh - 280px); }
}
