:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #1e293b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }

/* ---------- LOGIN ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #2563eb 100%);
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-logo { font-size: 44px; text-align: center; }
.login-card h1 { text-align: center; font-size: 22px; margin-top: 8px; }
.login-sub { text-align: center; color: var(--text-muted); margin: 4px 0 20px; font-size: 13px; }
.login-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab-btn {
  flex: 1; padding: 9px; border: 1px solid var(--border); background: var(--bg);
  border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--text-muted); font-size: 13px;
}
.tab-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.login-card label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 12px 0 4px; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.login-card input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- APP LAYOUT ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 20;
}
.sidebar-brand { padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.06); display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 22px; }
.brand-text { color: #fff; font-weight: 700; font-size: 16px; }
.brand-text small { display: block; font-size: 10px; color: var(--primary); letter-spacing: 2px; font-weight: 600; }
.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  cursor: pointer; font-size: 13.5px; font-weight: 500; margin-bottom: 2px; user-select: none;
  transition: background .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item .nav-ico { width: 20px; text-align: center; }
.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.06); }
.user-chip { font-size: 12px; color: #cbd5e1; padding: 0 4px 10px; word-break: break-all; }
.user-chip strong { color: #fff; display: block; }

.main { flex: 1; margin-left: 230px; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 16px 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.topbar h2 { font-size: 18px; }
.topbar-actions { display: flex; gap: 8px; }
.page-content { padding: 24px 28px; flex: 1; }

/* ---------- CARDS ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.stat-card .stat-num { font-size: 28px; font-weight: 700; }
.stat-card .stat-label { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.stat-card.primary .stat-num { color: var(--primary); }

/* ---------- TABLE ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; white-space: nowrap; }
th { background: #f8fafc; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
tr:hover td { background: #f8fafc; }
td .muted { color: var(--text-muted); }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 600;
}
.badge.ok { background: #dcfce7; color: #166534; }
.badge.off { background: #fee2e2; color: #991b1b; }
.badge.info { background: #dbeafe; color: #1e40af; }
.empty-state { padding: 40px; text-align: center; color: var(--text-muted); }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
  border: 1px solid transparent; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s; background: var(--bg); color: var(--text);
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-success { background: #dcfce7; color: #166534; }
.btn-ghost { background: transparent; color: var(--sidebar-text); border-color: rgba(255,255,255,.15); }
.btn-ghost:hover { color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; margin-top: 16px; }
.btn-icon { padding: 4px 8px; background: transparent; }
select.btn, input.btn {
  appearance: none; -webkit-appearance: none; background: var(--surface);
  border: 1px solid var(--border); color: var(--text); padding: 7px 10px;
  border-radius: 8px; font-size: 12.5px; font-family: inherit; cursor: pointer;
  height: 34px;
}
select.btn:focus, input.btn:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px;
  max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 24px 70px rgba(0,0,0,.35);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 16px; }
.modal-close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 12px 0 4px; }
.modal label:first-child { margin-top: 0; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px; font-family: inherit;
}
.modal input:focus, .modal select:focus, .modal textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.field-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }

/* token reveal */
.token-box {
  background: #0f172a; color: #7dd3fc; font-family: ui-monospace, monospace;
  padding: 14px; border-radius: 8px; font-size: 13px; word-break: break-all; user-select: all;
  margin: 10px 0;
}
.token-warn { background: #fef3c7; border: 1px solid #fde68a; color: #92400e; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.3);
  font-size: 13.5px; z-index: 200; max-width: 380px;
}
.toast.success { background: #166534; }
.toast.error { background: #991b1b; }

/* ---------- AUDIT ---------- */
.audit-detail { font-family: ui-monospace, monospace; font-size: 11.5px; color: var(--text-muted); max-width: 320px; white-space: normal; }

/* ---------- DETAILS / MISC ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 24px; }
.detail-item .k { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.detail-item .v { font-size: 14px; font-weight: 600; margin-top: 2px; }
.actions-cell { display: flex; gap: 4px; }
.section-actions { display: flex; gap: 8px; margin-bottom: 14px; justify-content: flex-end; }

@media (max-width: 800px) {
  .sidebar { width: 62px; }
  .sidebar .brand-text, .sidebar .nav-item span:not(.nav-ico), .user-chip { display: none; }
  .main { margin-left: 62px; }
  .page-content { padding: 16px; }
}
