/* ==========================================================
   EDUNEX Admin — styles
   Light + dark themes via CSS variables on :root / [data-theme="dark"]
   ========================================================== */

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

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --border: #e4e8f0;
  --text: #182033;
  --text-muted: #687389;
  --hover: rgba(37, 99, 235, 0.05);

  --primary: #2563eb;
  --primary-soft: #e8efff;
  --on-primary: #ffffff;
  --success: #15803d;
  --success-soft: #e5f6eb;
  --warning: #b45309;
  --warning-soft: #fdf2e1;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --info: #0369a1;
  --info-soft: #e3f2fb;

  --chart-1: #2563eb;
  --chart-2: #14b8a6;
  --chart-3: #f59e0b;
  --chart-4: #ec4899;
  --chart-5: #94a3b8;

  --sidebar: #0f172a;
  --sidebar-text: #94a3b8;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);
  --sidebar-w: 252px;
}

[data-theme="dark"] {
  --bg: #0a0f1d;
  --surface: #111829;
  --surface-2: #172036;
  --border: #243049;
  --text: #e5e9f2;
  --text-muted: #8a95ad;
  --hover: rgba(96, 165, 250, 0.06);

  --primary: #60a5fa;
  --primary-soft: rgba(96, 165, 250, 0.14);
  --on-primary: #0a0f1d;
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.13);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.12);

  --chart-1: #60a5fa;
  --chart-2: #2dd4bf;
  --chart-3: #fbbf24;
  --chart-4: #f472b6;
  --chart-5: #64748b;

  --sidebar: #060a14;
  --shadow: none;
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h2 { font-size: 16px; margin: 0; }
h3 { margin: 0; }
p { margin: 0; }
svg { width: 18px; height: 18px; flex-shrink: 0; }
i[data-icon] { display: inline-flex; }

.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.right { text-align: right; }
.text-danger { color: var(--danger); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  z-index: 40;
  transition: transform 0.25s ease;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 18px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #14b8a6);
  color: #fff; font-weight: 800; font-size: 18px;
}
.brand-name { color: #fff; font-weight: 800; letter-spacing: 0.06em; }
.brand-sub { font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  padding: 14px 12px 6px; color: #64748b;
}
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: inherit; text-decoration: none; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-link.active { background: rgba(37, 99, 235, 0.22); color: #fff; }
.nav-link.active svg { color: #93c5fd; }
.nav-count {
  margin-left: auto; font-size: 11.5px; font-weight: 600;
  background: rgba(255, 255, 255, 0.08); padding: 1px 8px; border-radius: 999px;
}
.nav-count.warn { background: rgba(251, 191, 36, 0.18); color: #fcd34d; }
.nav-count.danger { background: rgba(248, 113, 113, 0.2); color: #fca5a5; }
.nav-count.hidden { display: none; }
.sidebar-footer {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 6px 0; border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-user { flex: 1; min-width: 0; }
.sidebar-user .strong { color: #fff; }
.sidebar-user .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .icon-btn.ghost { color: var(--sidebar-text); }
.sidebar .icon-btn.ghost:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }

/* ---------- Main / top bar ---------- */
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 28px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 20px; margin: 0 auto 0 0; font-weight: 700; }
.menu-btn { display: none; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.search {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 12px; width: min(320px, 100%);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text-muted);
}
.search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search input { border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; width: 100%; }
.search.inline { flex: 1; max-width: 340px; width: auto; }

.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 8px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.dot {
  position: absolute; top: 8px; right: 9px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--danger); border: 2px solid var(--surface);
}
.dot.hidden { display: none; }

/* ---------- Dropdown ---------- */
.dropdown-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); width: 330px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); z-index: 50;
  opacity: 0; visibility: hidden; transform: translateY(-4px); transition: 0.15s;
}
.dropdown.open { opacity: 1; visibility: visible; transform: none; }
.dropdown-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.notif-list { list-style: none; margin: 0; padding: 6px; }
.notif-list a { display: flex; gap: 10px; padding: 10px; border-radius: 8px; color: inherit; text-decoration: none; }
.notif-list a:hover { background: var(--surface-2); }
.notif-list .unread { background: var(--primary-soft); }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex-shrink: 0; }

/* ---------- Content & cards ---------- */
.content { padding: 24px 28px 48px; flex: 1; }
.page { display: none; }
.page.active { display: block; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat { display: flex; gap: 14px; align-items: flex-start; }
.stat-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; }
.stat-icon.primary { background: var(--primary-soft); color: var(--primary); }
.stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-value { font-size: 24px; font-weight: 700; margin: 2px 0; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12.5px; color: var(--text-muted); }
.stat-sub b { font-weight: 600; }
.up { color: var(--success); }
.down { color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

/* ---------- Charts ---------- */
.chart-wrap { position: relative; height: 280px; }
.donut-wrap { height: 190px; }
canvas { display: block; width: 100%; height: 100%; }
.chart-tooltip {
  position: absolute; top: 6px; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; white-space: nowrap;
  opacity: 0; transition: opacity 0.1s;
}
.chart-tooltip.show { opacity: 1; }
.legend { display: flex; gap: 16px; margin-top: 12px; font-size: 12.5px; color: var(--text-muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.legend-list li { display: flex; align-items: center; gap: 6px; }
.legend-list .val { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.segmented button {
  border: 0; background: transparent; color: var(--text-muted);
  font: inherit; font-weight: 500; padding: 5px 12px; border-radius: 6px; cursor: pointer;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Mini lists (dashboard) ---------- */
.mini-list, .activity { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.mini-list li, .activity li { display: flex; align-items: center; gap: 10px; }
.mini-list .grow, .activity .grow { flex: 1; min-width: 0; }
.mini-list .grow > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity li { align-items: flex-start; }
.activity .time { white-space: nowrap; }
.empty-note { color: var(--text-muted); font-size: 13px; padding: 12px 0; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, filter 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn.sm { height: 32px; padding: 0 12px; border-radius: 8px; font-size: 13px; }
.btn.sm svg { width: 15px; height: 15px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.btn.danger-outline { color: var(--danger); border-color: var(--danger-soft); }
.btn.danger-outline:hover { background: var(--danger-soft); }
.btn-group { display: flex; gap: 10px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }

.select, .field input, .field select {
  height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; outline: 0; width: 100%;
}
.select { width: auto; }
.select:focus, .field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .push { margin-left: auto; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  border: 0; background: transparent; color: var(--text-muted);
  font: inherit; font-weight: 600; padding: 8px 12px; border-radius: 8px; cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--primary-soft); color: var(--primary); }
.tab-count { font-size: 11px; background: var(--surface-2); padding: 1px 7px; border-radius: 999px; margin-left: 4px; }
.tab.active .tab-count { background: var(--surface); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; }
.table { width: 100%; border-collapse: collapse; min-width: 720px; }
.table th, .table td { padding: 12px 20px; text-align: left; white-space: nowrap; }
.table th {
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.table td { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--hover); }
.table .right, .table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .row-muted td { opacity: 0.65; }
.table .row-muted td:nth-last-child(-n+2) { opacity: 1; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: "↕"; margin-left: 6px; opacity: 0.35; }
th[data-dir="asc"]::after { content: "↑"; opacity: 1; }
th[data-dir="desc"]::after { content: "↓"; opacity: 1; }
.actions { text-align: right; }
.actions > * + * { margin-left: 4px; }
.empty { text-align: center !important; padding: 40px !important; color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.user-cell { display: flex; align-items: center; gap: 10px; }
.avatar {
  --hue: 220;
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: inline-grid; place-items: center; font-size: 12px; font-weight: 700;
  background: hsl(var(--hue) 70% 92%); color: hsl(var(--hue) 55% 32%);
}
[data-theme="dark"] .avatar { background: hsl(var(--hue) 35% 22%); color: hsl(var(--hue) 80% 80%); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.neutral { background: var(--surface-2); color: var(--text-muted); }

.chip {
  --hue: 220;
  display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: hsl(var(--hue) 75% 94%); color: hsl(var(--hue) 55% 32%);
}
[data-theme="dark"] .chip { background: hsl(var(--hue) 35% 20%); color: hsl(var(--hue) 75% 78%); }
.chip + .chip { margin-left: 4px; }
.chip.off { text-decoration: line-through; opacity: 0.55; }
.tag {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 6px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  background: linear-gradient(135deg, #2563eb, #14b8a6); color: #fff; vertical-align: 1px;
}
.account-cell { display: flex; align-items: center; gap: 10px; }

.score { display: flex; align-items: center; gap: 8px; }
.score-bar { width: 70px; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.score-bar span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }

.table-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 4px; padding-top: 16px; border-top: 1px solid var(--border);
}
.pagination { display: flex; gap: 4px; align-items: center; }
.page-btn {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer;
}
.page-btn:hover:not(:disabled) { background: var(--surface-2); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ellipsis { padding: 0 4px; color: var(--text-muted); }

/* ---------- Payments ---------- */
.note {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; margin-bottom: 16px; border-radius: var(--radius);
  background: var(--info-soft); color: var(--text);
}
.note svg { color: var(--info); margin-top: 1px; }
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.summary .card { padding: 16px 20px; }
.summary .stat-value { font-size: 22px; }

/* ---------- Settings & forms ---------- */
.settings { max-width: 780px; display: grid; gap: 16px; }
.settings .card { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 500; }
.field .error { color: var(--danger); font-size: 12px; }
.field .error:empty { display: none; }
.field.invalid input { border-color: var(--danger); }
.toggle-row {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.preview { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: 0.2s; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: 0.2s;
}
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--primary-soft); }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100; padding: 16px;
  display: grid; place-items: center;
  background: rgba(8, 12, 24, 0.55); backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden; transition: 0.2s;
}
.modal.open { opacity: 1; visibility: visible; }
.modal-card {
  width: min(480px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  display: grid; gap: 16px; padding: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-lg); transform: translateY(8px) scale(0.98); transition: 0.2s;
}
.modal.open .modal-card { transform: none; }
.modal-card.small { width: min(420px, 100%); }
.modal-card.wide { width: min(760px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.modal-actions.spread { justify-content: space-between; align-items: center; flex-wrap: wrap; }
.id-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.id-cards figure { margin: 0; }
.id-cards img { width: 100%; display: block; border-radius: 12px; border: 1px solid var(--border); }
.id-cards figcaption { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; text-align: center; }

/* ---------- Toasts & overlay ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: grid; gap: 8px; }
.toast {
  max-width: 360px; padding: 12px 16px; border-radius: 10px;
  background: var(--text); color: var(--surface); font-weight: 500;
  border-left: 4px solid var(--success); box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(10px); transition: 0.25s;
}
.toast.show { opacity: 1; transform: none; }
.toast.info { border-left-color: var(--info); }
.toast.error { border-left-color: var(--danger); }
.overlay {
  position: fixed; inset: 0; z-index: 35; background: rgba(8, 12, 24, 0.55);
  opacity: 0; visibility: hidden; transition: 0.2s;
}
.overlay.show { opacity: 1; visibility: visible; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-3 > :last-child { grid-column: 1 / -1; }
}
@media (max-width: 980px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .topbar { padding: 12px 16px; gap: 10px; }
  .topbar .search { display: none; }
  .page-title { font-size: 18px; }
  .content { padding: 16px; }
  .stats, .summary, .grid-3, .form-grid, .id-cards { grid-template-columns: 1fr; }
  .grid-3 > :last-child { grid-column: auto; }
  .toolbar .push { margin-left: 0; }
  .search.inline { max-width: none; flex-basis: 100%; }
  .dropdown { width: min(330px, calc(100vw - 32px)); right: -48px; }
}
