/* ─── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  --sidebar-bg: #0f172a;
  --sidebar-width: 260px;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --surface: #ffffff;
  --bg: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-sidebar: #94a3b8;
  --text-sidebar-active: #ffffff;
  --nav-active-bg: rgba(255, 255, 255, 0.1);
  --nav-hover-bg: rgba(255, 255, 255, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.10);
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, 0.14);
}

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

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Bootstrap overrides ─────────────────────────────────────────────────── */
.btn {
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  letter-spacing: 0.01em;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.btn-outline-primary {
  color: var(--accent);
  border-color: var(--accent);
}

.btn-outline-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.form-control,
.form-select {
  font-size: 13.5px;
  border-radius: var(--radius-sm);
  border-color: var(--border);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.form-text {
  font-size: 12px;
  color: var(--text-muted);
}

.modal-content {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.modal-header {
  border-bottom: 1px solid var(--border);
  padding: 20px 24px 16px;
}

.modal-body { padding: 20px 24px; }

.modal-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
}

.table {
  font-size: 13.5px;
}

.table thead th {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

.table td {
  padding: 13px 16px;
  vertical-align: middle;
  border-color: var(--border);
}

.table tbody tr {
  transition: background 0.1s;
}

.table tbody tr:last-child td { border-bottom: none; }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  letter-spacing: 0.03em;
}

.badge.text-bg-success {
  background: #dcfce7 !important;
  color: #166534 !important;
}

.badge.text-bg-secondary {
  background: #f1f5f9 !important;
  color: #64748b !important;
}

.alert {
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  border: none;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
}

.alert-danger {
  background: #fee2e2;
  color: #991b1b;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-body { padding: 20px; }

/* ─── Login ───────────────────────────────────────────────────────────────── */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(99, 102, 241, 0.05) 0%, transparent 50%),
    linear-gradient(160deg, #f8fafc 0%, #eef2ff 100%);
}

.login-panel {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-logo-mark {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-logo-mark svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-logo-text {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.login-panel h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
  color: var(--text);
}

.login-panel .login-sub {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* ─── Navbar ──────────────────────────────────────────────────────────────── */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.top-bar {
  height: 57px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 100;
}

.top-bar-brand {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 9px;
}

.top-bar-brand:hover { color: var(--text); }

.top-bar-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.top-bar-logo svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.top-bar-user {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ─── Sidebar toggle (3-dot button) ──────────────────────────────────────── */
.sidebar-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4.5px;
  width: 34px;
  height: 34px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s;
  align-items: center;
}

.sidebar-toggle:hover { background: var(--bg); }

.sidebar-toggle span {
  display: block;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: var(--text-muted);
  transition: width 0.2s, opacity 0.2s, transform 0.2s;
  transform-origin: center;
}

/* Animate into X when open (sidebar visible) — subtle feedback */
.sidebar-open .sidebar-toggle span:nth-child(1) { width: 18px; }
.sidebar-open .sidebar-toggle span:nth-child(2) { width: 13px; }
.sidebar-open .sidebar-toggle span:nth-child(3) { width: 18px; }

/* ─── Layout ──────────────────────────────────────────────────────────────── */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  overflow: hidden;
  height: calc(100vh - 57px);
  transition: grid-template-columns 0.25s ease;
}

.layout.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  padding: 20px 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: padding 0.25s ease;
  min-width: 0;
}

.layout.sidebar-collapsed .sidebar {
  padding: 0;
}

.sidebar-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #475569;
  padding: 0 8px;
  margin: 0 0 6px;
}

.sidebar-section { margin-bottom: 24px; }

#pageList .nav-link,
#adminMenu .nav-link {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-sidebar);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}

#pageList .nav-link:hover,
#adminMenu .nav-link:hover {
  background: var(--nav-hover-bg);
  color: #cbd5e1;
}

#pageList .nav-link.active,
#adminMenu .nav-link.active {
  background: var(--nav-active-bg);
  color: var(--text-sidebar-active);
}

/* ─── Content area ────────────────────────────────────────────────────────── */
.content-area {
  min-width: 0;
  height: 100%;
  overflow: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

#dashboardPanel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#dashboardFrame {
  width: 100%;
  flex: 1;
  border: 0;
  background: #fff;
  display: block;
  min-height: 0;
}

/* ─── Admin panels ────────────────────────────────────────────────────────── */
.admin-panel {
  padding: 32px;
  flex: 1;
  min-width: 0;
}

.panel-header {
  margin-bottom: 24px;
}

.panel-header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}

.panel-header .panel-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* Users table wrapper */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* Upload cards */
#uploadCards .card {
  transition: box-shadow 0.15s;
}

#uploadCards .card:hover {
  box-shadow: var(--shadow-md);
}

#uploadCards .card .card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

/* ─── Page chips ──────────────────────────────────────────────────────────── */
.page-chip {
  display: inline-block;
  padding: 2px 9px;
  margin: 2px;
  border-radius: 999px;
  background: var(--accent-light);
  color: var(--accent-hover);
  font-size: 11.5px;
  font-weight: 500;
}

.access-grid {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(260px, 1.2fr);
  gap: 16px;
}

.page-access-panels {
  display: grid;
  gap: 12px;
}

.page-access-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 14px;
}

.page-access-card h3 {
  font-size: 13.5px;
  font-weight: 700;
  margin: 0 0 12px;
}

.access-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.access-checks {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  padding: 10px;
  max-height: 210px;
  overflow: auto;
}

.access-checks .form-check {
  margin-bottom: 6px;
}

.access-checks .form-check:last-child {
  margin-bottom: 0;
}

/* ─── Logout button in navbar ─────────────────────────────────────────────── */
.btn-logout {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.btn-logout:hover {
  background: var(--bg);
  color: var(--text);
}

/* ─── Scrollbar (webkit) ──────────────────────────────────────────────────── */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.content-area::-webkit-scrollbar { width: 6px; }
.content-area::-webkit-scrollbar-track { background: transparent; }
.content-area::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ─── Responsive ──────────────────────────────────────────────────────────── */

/* Table card horizontal scroll (all viewports) */
.table-card { overflow-x: auto; }

@media (max-width: 900px) {
  /* Access grid stacks below the label row */
  .access-grid { grid-template-columns: 1fr; }

  /* Modal fills more of the screen */
  .modal-dialog { max-width: calc(100vw - 32px); }
}

@media (max-width: 768px) {
  /* Top bar */
  .top-bar        { padding: 0 14px; gap: 10px; }
  .top-bar-user   { display: none; }

  /* Layout: collapse sidebar out of grid on all states */
  .layout,
  .layout.sidebar-collapsed {
    grid-template-columns: 1fr;
    position: relative;
    height: calc(100vh - 57px);
    overflow: hidden;
  }

  /* Sidebar becomes a left-edge overlay, hidden by default */
  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    height: 100%;
    z-index: 200;
    flex-direction: column;
    padding: 20px 12px;
    gap: 4px;
    transform: translateX(-100%);
    transition: transform 0.25s ease, padding 0.25s ease;
    overflow-y: auto;
  }

  /*
   * On desktop: sidebar-collapsed = sidebar hidden.
   * On mobile (inverted): sidebar-collapsed = toggle was pressed = show overlay.
   */
  .layout.sidebar-collapsed .sidebar {
    transform: translateX(0);
    padding: 20px 12px;
  }

  /* Dim backdrop behind overlay */
  .layout.sidebar-collapsed::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 150;
  }

  /* Content area fills full width */
  .content-area { width: 100%; height: 100%; }

  /* Dashboard iframe fills viewport height on mobile */
  #dashboardPanel { height: calc(100vh - 57px); flex: none; }
  #dashboardFrame { height: 100%; flex: none; }

  /* Admin panels */
  .admin-panel { padding: 20px 16px; max-width: 100%; }

  /* Modal full-width on mobile */
  .modal-dialog { margin: 12px; max-width: calc(100vw - 24px); }
  .modal-body   { padding: 16px 18px; }
}

@media (max-width: 480px) {
  .top-bar-brand    { font-size: 13px; }
  .panel-header h2  { font-size: 17px; }
  .admin-panel      { padding: 14px 12px; }
  .login-panel      { padding: 28px 20px; }
  .login-panel h1   { font-size: 19px; }
}
