/* ============================================================
   Admin Panel — Design System
   ============================================================ */

:root {
  --primary:     #6366f1;
  --primary-dk:  #4f46e5;
  --success:     #22c55e;
  --danger:      #ef4444;
  --warning:     #f59e0b;
  --bg:          #f8f9fb;
  --bg-card:     #ffffff;
  --border:      #e5e7eb;
  --text:        #111827;
  --text-2:      #6b7280;
  --text-3:      #9ca3af;
  --sidebar-w:   240px;
  --header-h:    60px;
  --radius:      10px;
  --shadow:      0 1px 4px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --transition:  .16s ease;
}

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

body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: #1e1b4b;
  color: #c7d2fe;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand-icon {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.sidebar-brand-name { font-weight: 700; font-size: 15px; color: #fff; }
.sidebar-brand-tag  { font-size: 10px; color: #818cf8; margin-top: 1px; }

.sidebar-nav { flex: 1; padding: 12px 12px; overflow-y: auto; }
.nav-section { margin-bottom: 6px; }
.nav-label   { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: #6d6f8a; padding: 12px 8px 6px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #a5b4fc;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  font-size: 13.5px;
  text-decoration: none;
  margin-bottom: 1px;
}
.nav-item:hover  { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .icon  { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
  color: #6d6f8a;
}

/* Main */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* Prevents wide children (e.g. tables) from stretching the whole page
     horizontally — without this, a flex item defaults to a minimum width
     equal to its content's intrinsic width, so anything wider than the
     viewport (like a table with many columns) pushes the entire layout
     sideways instead of scrolling locally within .table-wrap. */
  min-width: 0;
}

/* Header */
.topbar {
  height: var(--header-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 17px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

/* Content */
.content { padding: 28px; flex: 1; max-width: 1280px; width: 100%; min-width: 0; box-sizing: border-box; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-title { font-weight: 600; font-size: 15px; flex: 1; }
.card-body  { padding: 22px; min-width: 0; }

/* ── Stat cards ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label  { font-size: 12px; color: var(--text-2); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.stat-value  { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-delta  { font-size: 12px; color: var(--text-3); }
.stat-delta.up   { color: var(--success); }
.stat-delta.down { color: var(--danger); }
.stat-icon   { font-size: 24px; margin-bottom: 4px; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}
/* Thin, unobtrusive horizontal scrollbar for the table container specifically */
.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 13.5px;
}
thead th {
  text-align: left;
  padding: 11px 16px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: #fafafe; }
tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }

/* Constrain a cell's text so long values (domains, usernames) truncate
   with an ellipsis instead of forcing the whole table wider than needed */
.cell-truncate {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Row action dropdown (kebab menu) ───────────────────── */
/* Replaces a row of many buttons with a single compact trigger, keeping
   table rows short and readable regardless of how many actions exist. */
.action-menu { position: relative; display: inline-block; }
.action-menu-trigger {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-2);
  transition: all var(--transition);
  line-height: 1;
}
.action-menu-trigger:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.action-menu-list {
  /* BUG FIX: was position:absolute, which gets clipped by .table-wrap's
     overflow (needed for horizontal scroll) — any dropdown opened from a
     row near the bottom of the table was invisible/cut off. position:fixed
     escapes all ancestor overflow/scroll clipping; exact top/left are
     computed in JS (toggleActionMenu) from the trigger button's position,
     since fixed positioning is relative to the viewport, not this element's
     normal offset parent. */
  position: fixed;
  min-width: 190px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.12);
  padding: 6px;
  z-index: 1000;
  display: none;
  flex-direction: column;
  gap: 1px;
}
.action-menu.open .action-menu-list { display: flex; }
.action-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: 7px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}
.action-menu-item:hover { background: var(--bg); }
.action-menu-item.danger { color: var(--danger); }
.action-menu-item.danger:hover { background: #fee2e2; }
.action-menu-divider { height: 1px; background: var(--border); margin: 4px 2px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}
.btn-primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover  { background: var(--primary-dk); border-color: var(--primary-dk); text-decoration: none; color: #fff; }
.btn-outline  { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover  { background: var(--bg); text-decoration: none; color: var(--text); }
.btn-danger   { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover   { background: #dc2626; text-decoration: none; color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-gray   { background: #f3f4f6; color: #4b5563; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }

/* ── Forms ─────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.form-label span { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.form-control::placeholder { color: var(--text-3); }
textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control { cursor: pointer; }

.form-hint { font-size: 12px; color: var(--text-2); margin-top: 5px; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 5px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }
@media (max-width: 640px) {
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* ── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-card);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 560px;
  max-width: calc(100vw - 32px);
  max-height: 90vh;
  display: flex; flex-direction: column;
  transform: translateY(12px) scale(.97);
  transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: none; }

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.modal-title { font-weight: 600; font-size: 16px; flex: 1; }
.modal-close {
  background: none; border: none; cursor: pointer; font-size: 20px;
  color: var(--text-2); line-height: 1; padding: 2px;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }
.modal-body   { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── Misc utils ─────────────────────────────────────────── */
.flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }
.mb-3 { margin-bottom: 18px; }
.text-sm { font-size: 12.5px; }
.text-muted { color: var(--text-2); }
.font-mono { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 12.5px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-2);
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-state-desc { font-size: 13px; }

.copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-2);
  padding: 2px 6px;
  border-radius: 4px;
  transition: all var(--transition);
}
.copy-btn:hover { background: var(--bg); color: var(--primary); }

/* Toast */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 99999;
}
.toast {
  background: #1e293b;
  color: #f8fafc;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  display: flex; align-items: center; gap: 10px;
  animation: toast-in .22s ease;
  max-width: 340px;
}
.toast.success .toast-icon { color: var(--success); }
.toast.error   .toast-icon { color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Color input preview */
.color-preview {
  display: flex; align-items: center; gap: 10px;
}
.color-preview input[type=color] {
  width: 40px; height: 36px;
  padding: 2px; border-radius: 6px;
  border: 1px solid var(--border); cursor: pointer;
}

/* Pagination */
.pagination {
  display: flex; align-items: center; gap: 4px;
  justify-content: center; margin-top: 20px;
}
.page-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: all var(--transition);
}
.page-btn:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Loader */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page-loader {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px; gap: 14px; color: var(--text-2);
}

/* Code block */
.code-block {
  background: #1e293b;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 14px 18px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 13px;
  overflow-x: auto;
  white-space: pre;
  position: relative;
}
.code-copy {
  position: absolute;
  top: 10px; right: 10px;
  background: rgba(255,255,255,.1);
  border: none;
  color: #94a3b8;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition);
}
.code-copy:hover { background: rgba(255,255,255,.2); color: #fff; }
