/* ============================================================
   TKA Admin Panel — Design System
   © 2026 Ekwan Nugroho · Wonogiri
   ============================================================ */

:root {
  --navy: #003580;
  --navy-dark: #002654;
  --navy-darker: #001a3d;
  --navy-light: #dbeafe;
  --navy-lighter: #eff6ff;

  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --success: #15803d;
  --success-bg: #dcfce7;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --purple: #6d28d9;
  --purple-bg: #ede9fe;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 20px 40px rgba(0,0,0,.12);

  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 260px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* ============ LOGIN ============ */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--navy-darker);
}
.login-card {
  background: #fff; border-radius: var(--radius-lg); max-width: 420px; width: 100%;
  padding: 36px 30px; box-shadow: var(--shadow-lg);
}
.login-brand {
  width: 56px; height: 56px; margin: 0 auto 20px; background: var(--navy);
  color: #fff; border-radius: 12px; display: flex; align-items: center;
  justify-content: center; font-weight: 800; font-size: 16px; letter-spacing: -.5px;
}
.login-card h1 { font-size: 20px; text-align: center; margin-bottom: 6px; }
.login-card .sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 26px; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #374151; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius); font-size: 15px; margin-bottom: 14px;
  transition: all .15s;
}
.login-card input:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px var(--navy-light); }
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 22px; background: var(--navy); color: #fff;
  border-radius: var(--radius); font-weight: 600; font-size: 14px;
  transition: background .15s;
}
.btn-primary:hover:not(:disabled) { background: var(--navy-dark); }
.btn-primary:disabled { background: #94a3b8; cursor: not-allowed; }
.btn-block { width: 100%; padding: 13px; font-size: 15px; }
.login-card .err { color: var(--danger); font-size: 13px; text-align: center; margin-top: 12px; min-height: 18px; }
.login-card .help { text-align: center; font-size: 13px; color: var(--text-muted); margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ============ LAYOUT ============ */
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); position: fixed; top: 0; bottom: 0; left: 0;
  background: var(--navy-darker); color: #fff;
  display: flex; flex-direction: column; z-index: 50;
  transition: transform .25s ease;
}
.sidebar-brand {
  padding: 20px 20px 16px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-logo {
  width: 42px; height: 42px; background: #fff; color: var(--navy);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand-title { font-size: 14px; font-weight: 700; line-height: 1.2; }
.brand-sub { font-size: 11px; opacity: .6; line-height: 1.2; }

.sidebar-nav { flex: 1; padding: 16px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 8px; color: rgba(255,255,255,.75);
  font-size: 14px; font-weight: 500; margin-bottom: 2px;
  cursor: pointer; transition: all .12s; text-decoration: none !important;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: rgba(255,255,255,.12); color: #fff; font-weight: 600;
  box-shadow: inset 3px 0 0 #60a5fa;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 16px 20px; border-top: 1px solid rgba(255,255,255,.08);
}
.user-card {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--navy-light);
  color: var(--navy-dark); display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; flex-shrink: 0; text-transform: uppercase;
}
.user-info { min-width: 0; flex: 1; }
.user-email {
  font-size: 12px; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  opacity: .65; margin-top: 1px;
}
.btn-logout {
  width: 100%; padding: 9px; background: rgba(255,255,255,.08);
  color: #fff; border-radius: 6px; font-size: 13px; font-weight: 600;
  transition: background .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.16); }

/* Main */
.main {
  margin-left: var(--sidebar-w); flex: 1;
  display: flex; flex-direction: column; min-height: 100vh; min-width: 0;
}
.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 14px 28px; display: flex; align-items: center;
  justify-content: space-between; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-title { font-size: 18px; font-weight: 700; line-height: 1.2; }
.topbar-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.btn-menu {
  display: none; width: 36px; height: 36px;
  border-radius: 8px; background: var(--navy-lighter); color: var(--navy);
  align-items: center; justify-content: center;
}

.content {
  flex: 1; padding: 28px; max-width: 1400px; width: 100%; margin: 0 auto;
}

.view { animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ============ CARDS ============ */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 20px;
  display: flex; align-items: flex-start; gap: 14px;
  transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon.blue { background: var(--navy-lighter); color: var(--navy); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.amber { background: var(--warning-bg); color: var(--warning); }
.stat-icon.red { background: var(--danger-bg); color: var(--danger); }
.stat-info { min-width: 0; }
.stat-num { font-size: 26px; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.panel {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); margin-bottom: 24px; overflow: hidden;
}
.panel-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.panel-title { font-size: 15px; font-weight: 700; }
.panel-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.panel-body { padding: 20px; }

/* ============ TABLE ============ */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th, .data-table td {
  padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.data-table th {
  font-weight: 700; color: var(--text-muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .5px; background: #fafbfc;
  position: sticky; top: 0;
}
.data-table tbody tr { transition: background .1s; }
.data-table tbody tr:hover { background: #fafbfc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .email-cell { font-weight: 600; color: var(--text); }
.data-table .empty {
  text-align: center; color: var(--text-light); padding: 40px 20px;
}

.role-badge, .status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: .3px;
  white-space: nowrap;
}
.role-badge.superadmin { background: var(--purple-bg); color: var(--purple); }
.role-badge.admin { background: var(--navy-light); color: var(--navy); }
.role-badge.teacher { background: #f1f5f9; color: #475569; }

.status-badge.active { background: var(--success-bg); color: var(--success); }
.status-badge.pending { background: var(--warning-bg); color: var(--warning); }
.status-badge.suspended { background: var(--danger-bg); color: var(--danger); }
.status-badge.expired { background: #f1f5f9; color: var(--text-muted); }

.actions-cell { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.btn-icon {
  width: 30px; height: 30px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: all .12s;
  border: 1px solid transparent;
}
.btn-icon:hover { background: #f1f5f9; color: var(--text); }
.btn-icon.success:hover { background: var(--success-bg); color: var(--success); }
.btn-icon.warn:hover { background: var(--warning-bg); color: var(--warning); }
.btn-icon.danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn-icon svg { width: 15px; height: 15px; }

/* ============ TABS & SEARCH ============ */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 600;
  color: var(--text-muted); background: transparent;
  transition: all .12s;
}
.tab:hover { background: #f1f5f9; color: var(--text); }
.tab.active { background: var(--navy); color: #fff; }

.search-box {
  position: relative; flex: 1; min-width: 200px; max-width: 320px;
  margin-left: auto;
}
.search-box svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-light); pointer-events: none;
}
.search-input {
  width: 100%; padding: 9px 12px 9px 36px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 13px; background: #fff;
  transition: all .15s;
}
.search-input:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px var(--navy-light); }

/* ============ FORMS ============ */
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 13px; font-weight: 600;
  color: #374151; margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 14px; background: #fff;
  transition: all .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px var(--navy-light);
}
.field textarea { resize: vertical; font-family: 'SF Mono', Monaco, monospace; font-size: 12px; line-height: 1.6; }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; line-height: 1.5; }
.field-hint code { background: #f1f5f9; padding: 1px 5px; border-radius: 3px; font-family: monospace; font-size: 11px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; background: #fff; color: #374151;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-weight: 600; font-size: 13px;
  transition: all .12s;
}
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }

.btn-sm {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 6px;
  font-size: 13px; font-weight: 600;
  background: var(--navy); color: #fff;
  transition: background .12s;
}
.btn-sm:hover:not(:disabled) { background: var(--navy-dark); }
.btn-sm:disabled { background: #94a3b8; cursor: not-allowed; }
.btn-sm.ghost { background: #fff; color: #374151; border: 1.5px solid var(--border); }
.btn-sm.ghost:hover { background: #f8fafc; }

/* ============ QUICK ACTIONS (Overview) ============ */
.quick-actions {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.action-card {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1.5px dashed var(--border); padding: 20px;
  display: flex; align-items: center; gap: 14px;
  cursor: pointer; transition: all .15s;
  text-align: left;
}
.action-card:hover {
  border-color: var(--navy); background: var(--navy-lighter);
  border-style: solid;
}
.action-card-icon {
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--navy-lighter); color: var(--navy);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.action-card:hover .action-card-icon { background: var(--navy); color: #fff; }
.action-card-body { min-width: 0; }
.action-card-title { font-size: 14px; font-weight: 700; color: var(--text); }
.action-card-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 1000;
  animation: fadeIn .15s ease;
  backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: #fff; border-radius: var(--radius-lg);
  max-width: 520px; width: 100%; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to { opacity: 1; transform: none; }
}
.modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 20px; line-height: 1;
  transition: all .12s;
}
.modal-close:hover { background: #f1f5f9; color: var(--text); }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}
.modal-footer .btn-primary, .modal-footer .btn-secondary { padding: 10px 18px; }

/* ============ TOAST ============ */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 10px;
  max-width: 400px;
}
.toast {
  background: #fff; border-radius: var(--radius);
  padding: 14px 18px; box-shadow: var(--shadow-md);
  display: flex; align-items: flex-start; gap: 12px;
  border-left: 4px solid var(--navy);
  animation: toastIn .2s ease;
  min-width: 280px;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: none; }
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast-icon {
  flex-shrink: 0; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
}
.toast-icon svg { width: 20px; height: 20px; }
.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--danger); }
.toast.warning .toast-icon { color: var(--warning); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 13px; font-weight: 700; }
.toast-msg { font-size: 12px; color: var(--text-muted); margin-top: 2px; word-break: break-word; }

/* ============ CSV RESULT ============ */
.result-box {
  margin-top: 16px; padding: 16px; background: #f8fafc;
  border-radius: var(--radius); border: 1px solid var(--border);
  font-size: 13px;
}
.result-header { font-weight: 700; margin-bottom: 10px; }
.result-list { list-style: none; padding: 0; margin: 0; max-height: 240px; overflow-y: auto; }
.result-list li { padding: 5px 0; font-size: 12px; display: flex; gap: 8px; }
.result-list li::before { content: '•'; flex-shrink: 0; }
.result-list li.ok { color: var(--success); }
.result-list li.fail { color: var(--danger); }

/* ============ LOADING ============ */
.loading-screen {
  position: fixed; inset: 0; background: var(--navy-darker);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 15px; z-index: 3000;
}
.spinner {
  width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.2);
  border-top-color: #60a5fa; border-radius: 50%;
  animation: spin 1s linear infinite; margin-right: 12px;
  display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .btn-menu { display: inline-flex; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .content { padding: 20px 16px; }
  .topbar { padding: 12px 16px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .search-box { max-width: 100%; }
  .data-table th, .data-table td { padding: 10px 8px; font-size: 12px; }
}

/* Backdrop mobile */
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 40;
}
.sidebar-backdrop.show { display: block; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
