:root {
  --sidebar-w: 240px;
  --navy: #0B1120;
  --navy-2: #131B30;
  --indigo: #5B5FEF;
  --indigo-dark: #4548c9;
  --ember: #FF6B4A;
  --bg: #F5F6FB;
  --border: #e5e7eb;
  --text: #1a1f2e;
  --muted: #6b7280;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3, .panel-head h3, .sidebar-brand, .brand-text, .stat-value {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
}

a { color: var(--indigo); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f1f1f4; padding: 2px 6px; border-radius: 4px; font-size: 13px; }

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 100;
  transition: transform .2s ease;
}
.sidebar-brand {
  padding: 22px 20px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .brand-icon-img {
  width: 32px; height: 32px; object-fit: contain; flex-shrink: 0;
}
.sidebar-nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  border-radius: 8px;
  color: #a4acc2;
  font-size: 14.5px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active { background: var(--indigo); color: #fff; box-shadow: 0 4px 14px rgba(91,95,239,.35); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer { padding: 14px 10px; border-top: 1px solid rgba(255,255,255,.08); }
.logout-link { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 8px; color: #f3a3a3; font-size: 14.5px; }
.logout-link:hover { background: rgba(220,38,38,.12); color: #fff; text-decoration: none; }

.overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90;
}

/* ---------- Main ---------- */
.main-wrap { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: 20px; font-weight: 600; margin: 0; flex: 1; letter-spacing: -0.01em; }
.hamburger { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }
.admin-chip { font-size: 13.5px; color: var(--text); background: var(--bg); padding: 7px 14px 7px 8px; border-radius: 20px; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.admin-chip .bi { width: 24px; height: 24px; border-radius: 50%; background: var(--indigo); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; }

.content { padding: 22px 24px 48px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---------- Flash messages ---------- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; }
.flash-success { background: var(--green-bg); color: #166534; }
.flash-error { background: var(--red-bg); color: #991b1b; }

/* ---------- Website subnav (tabs) ---------- */
.subnav { margin-bottom: 20px; }
.subnav-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.subnav-title .muted { font-weight: 400; }
.subnav-tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 2px solid var(--border); }
.subnav-tabs a {
  padding: 9px 16px; font-size: 13.5px; color: var(--muted); text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.subnav-tabs a:hover { color: var(--indigo); }
.subnav-tabs a.active { color: var(--indigo); border-bottom-color: var(--indigo); font-weight: 600; }
.subnav-tabs a.back-link { margin-left: auto; color: var(--muted); }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
  background: #fff; border-radius: var(--radius); padding: 18px;
  box-shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  border: 1px solid #f0f1f6;
  display: flex; align-items: center; gap: 14px;
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(16,24,40,.08); }
.stat-icon {
  font-size: 19px; width: 44px; height: 44px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(91,95,239,.12); color: var(--indigo);
}
.stat-card:nth-child(4n+2) .stat-icon { background: rgba(255,107,74,.12); color: var(--ember); }
.stat-card:nth-child(4n+3) .stat-icon { background: rgba(22,163,74,.12); color: var(--green); }
.stat-card:nth-child(4n+4) .stat-icon { background: rgba(9,132,227,.12); color: #0984e3; }
.stat-value { font-size: 23px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
.stat-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- Panels ---------- */
.panel { background: #fff; border-radius: var(--radius); padding: 22px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04); border: 1px solid #f0f1f6; }
.panel-danger { border: 1px solid #fecaca; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.empty-hint { color: var(--muted); font-size: 14px; }
.muted { color: var(--muted); }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .03em;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafbfe; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; background: #eef0fb; color: var(--indigo-dark); }
.badge-green { background: var(--green-bg); color: #166534; }
.badge-red { background: var(--red-bg); color: #991b1b; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: 6px; font-size: 13.5px;
  border: none; cursor: pointer; text-decoration: none; font-weight: 500;
  transition: background .15s, opacity .15s;
}
.btn:hover { text-decoration: none; opacity: .92; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-primary { background: var(--indigo); color: #fff; }
.btn-primary:hover { background: var(--indigo-dark); }
.btn-secondary { background: #eef0fb; color: var(--indigo-dark); }
.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--red-bg); color: #991b1b; }
.btn-danger:hover { background: #fecaca; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.inline-form { display: inline-block; }

/* ---------- Forms ---------- */
.form-grid { display: flex; flex-direction: column; gap: 4px; max-width: 480px; }
.form-grid label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 10px; }
.form-grid input, .form-grid textarea, .form-grid select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; font-family: inherit; width: 100%;
}
.form-grid input:focus, .form-grid textarea:focus, .form-grid select:focus { outline: none; border-color: var(--indigo); }
.form-grid button { margin-top: 16px; align-self: flex-start; }
.help-text { font-size: 12px; color: var(--muted); margin-top: 3px; }

.search-form input {
  padding: 9px 14px; border: 1px solid var(--border); border-radius: 20px;
  font-size: 13.5px; min-width: 240px;
}
.search-form input:focus { outline: none; border-color: var(--indigo); }
.search-icon-wrap { position: relative; display: inline-block; }
.search-form-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.search-icon-wrap input { padding-left: 34px; }

.code-block {
  background: #111827; color: #86efac; padding: 14px; border-radius: 8px;
  font-size: 12.5px; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 6px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a {
  padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border);
  font-size: 13px; color: var(--text); text-decoration: none;
}
.pagination a.active { background: var(--indigo); color: #fff; border-color: var(--indigo); }
.pagination a:hover { border-color: var(--indigo); text-decoration: none; }

/* ---------- Login page (standalone, no sidebar) ---------- */
.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background:
    radial-gradient(circle at 15% 20%, rgba(91,95,239,.10), transparent 42%),
    radial-gradient(circle at 85% 80%, rgba(255,107,74,.08), transparent 42%),
    var(--bg);
}
.login-box { background: #fff; padding: 36px 34px; border-radius: 16px; box-shadow: 0 12px 40px rgba(16,24,40,.10); border: 1px solid #f0f1f6; width: 360px; text-align: center; }
.login-logo { width: 56px; height: 56px; object-fit: contain; margin-bottom: 10px; }
.login-box h2 { margin: 0 0 2px; font-weight: 700; letter-spacing: -0.01em; font-size: 22px; }
.login-box form { text-align: left; margin-top: 20px; }
.login-box input { width: 100%; padding: 12px; margin: 8px 0; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; box-sizing: border-box; transition: border-color .15s; }
.login-box input:focus { outline: none; border-color: var(--indigo); }
.login-box button { width: 100%; padding: 12px; background: var(--indigo); color: #fff; border: none; border-radius: 8px; cursor: pointer; font-size: 15px; margin-top: 8px; font-weight: 600; transition: background .15s, transform .15s; }
.login-box button:hover { background: var(--indigo-dark); transform: translateY(-1px); }
.login-error { background: var(--red-bg); color: #991b1b; padding: 10px; border-radius: 6px; font-size: 13.5px; margin-bottom: 6px; text-align: left; }

/* ---------- Result / success boxes ---------- */
.result-box { background: var(--green-bg); padding: 16px; border-radius: 8px; margin-top: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .hamburger { display: block; }
  .overlay.open { display: block; }
  .search-form input { min-width: 150px; }
}

/* ---------- Dashboard welcome banner ---------- */
.dash-welcome { margin-bottom: 22px; }
.dash-welcome h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 4px; }
.dash-welcome p { color: var(--muted); font-size: 14.5px; margin: 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(11,17,32,.55);
  z-index: 500; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff; border-radius: 16px; width: 100%; max-width: 520px;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(11,17,32,.28);
  animation: modalPop .18s ease;
}
@keyframes modalPop { from { transform: scale(.96) translateY(6px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1; padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 22px; }
.modal-body .form-grid { max-width: 100%; }
