/* ============================================================
   Admin Panel - Modern Design 2026
   ============================================================ */

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;

  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --info: #06b6d4;
  --info-light: #cffafe;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;

  /* Dark sidebar */
  --sidebar-bg: #0f172a;
  --sidebar-bg-soft: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-text-active: #ffffff;
  --sidebar-border: rgba(255, 255, 255, 0.06);

  --radius-sm: 0.5rem;
  --radius: 0.875rem;
  --radius-lg: 1.25rem;
  --radius-pill: 999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 2px 4px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 20px -4px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 16px 40px -8px rgba(15, 23, 42, 0.12);
  --shadow-xl: 0 24px 60px -12px rgba(15, 23, 42, 0.18);
  --shadow-primary: 0 8px 20px -4px color-mix(in srgb, var(--primary, #6366f1) 45%, transparent);

  --t-fast: 120ms cubic-bezier(.4, 0, .2, 1);
  --t-base: 200ms cubic-bezier(.4, 0, .2, 1);
}

* { box-sizing: border-box; }

body {
  font-family: 'Sarabun', 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
html[lang="en"] body { font-family: 'Inter', 'Sarabun', system-ui, sans-serif; }

h1, h2, h3, h4, h5, h6 { font-weight: 700; letter-spacing: -0.01em; }

/* ============================================================
   Layout
   ============================================================ */
.admin-wrapper {
  display: flex;
  min-height: 100vh;
}

/* LIGHT SIDEBAR (default = light/auto) */
.admin-sidebar {
  width: 252px;
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--primary) 10%, var(--surface)) 0%,
      var(--surface) 45%,
      var(--surface) 100%);
  color: var(--text);
  display: flex; flex-direction: column;
  position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
  border-right: 1px solid var(--border);
  transition: transform var(--t-base), background var(--t-slow, 300ms), color var(--t-base);
  z-index: 1040;
}
.admin-sidebar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--theme-grad, linear-gradient(90deg, var(--primary), var(--primary-dark)));
  z-index: 1;
}
@supports not (background: color-mix(in srgb, red, blue)) {
  .admin-sidebar { background: var(--surface); }
}

/* DARK SIDEBAR (explicit dark mode) */
:root[data-mode="dark"] .admin-sidebar {
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--primary) 30%, #050816) 0%,
      #050816 35%,
      #050816 100%);
  color: rgba(255, 255, 255, 0.85);
  border-right-color: rgba(255, 255, 255, 0.06);
}
@supports not (background: color-mix(in srgb, red, blue)) {
  :root[data-mode="dark"] .admin-sidebar { background: #050816; }
}

/* AUTO + OS dark */
@media (prefers-color-scheme: dark) {
  :root[data-mode="auto"] .admin-sidebar {
    background:
      linear-gradient(180deg,
        color-mix(in srgb, var(--primary) 30%, #050816) 0%,
        #050816 35%,
        #050816 100%);
    color: rgba(255, 255, 255, 0.85);
    border-right-color: rgba(255, 255, 255, 0.06);
  }
}
.sidebar-brand {
  padding: 1rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  border-bottom: 1px solid var(--border);
  min-height: 70px;
}
:root[data-mode="dark"] .sidebar-brand { border-bottom-color: rgba(255,255,255,0.06); }
@media (prefers-color-scheme: dark) {
  :root[data-mode="auto"] .sidebar-brand { border-bottom-color: rgba(255,255,255,0.06); }
}
.sb-brand-link {
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 1.05rem; font-weight: 800;
  color: var(--text);
  text-decoration: none;
  flex: 1; min-width: 0;
  padding: 0.25rem 0.4rem;
  margin: -0.25rem -0.4rem;
  border-radius: 10px;
  transition: background var(--t-fast);
}
.sb-brand-link:hover { background: color-mix(in srgb, var(--primary) 6%, transparent); color: var(--text); }
:root[data-mode="dark"] .sb-brand-link { color: #fff; }
:root[data-mode="dark"] .sb-brand-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
@media (prefers-color-scheme: dark) {
  :root[data-mode="auto"] .sb-brand-link { color: #fff; }
  :root[data-mode="auto"] .sb-brand-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
}
.sb-brand-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-brand-logo {
  max-width: 100%;
  max-height: 48px;
  height: auto;
  width: auto;
  object-fit: contain;
  display: block;
}
.sidebar-brand-icon {
  width: 36px; height: 36px;
  background: var(--theme-grad, linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.05rem;
  box-shadow: var(--shadow-primary);
  flex-shrink: 0;
}
.sidebar-section {
  padding: 0.875rem 1rem 0.4rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 700;
}
:root[data-mode="dark"] .sidebar-section { color: rgba(255,255,255,0.45); }
@media (prefers-color-scheme: dark) {
  :root[data-mode="auto"] .sidebar-section { color: rgba(255,255,255,0.45); }
}

.sidebar-nav { padding: 0.5rem 0.75rem; flex: 1; overflow-y: auto; }

/* Base link (used for both top-level and child links) */
.sidebar-nav .sb-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 0.875rem;
  margin-bottom: 0.15rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 500;
  transition: all var(--t-fast);
}
.sidebar-nav .sb-link:hover {
  background: color-mix(in srgb, var(--primary) 8%, var(--surface-soft));
  color: var(--text);
}
.sidebar-nav .sb-link i { width: 18px; font-size: 1rem; text-align: center; flex-shrink: 0; }
.sidebar-nav .sb-link.active {
  background: var(--theme-grad, linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%));
  color: #fff;
  box-shadow: var(--shadow-primary);
  font-weight: 600;
  position: relative;
}
.sidebar-nav .sb-link.active::after {
  content: '';
  position: absolute;
  right: -0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 4px; height: 24px;
  background: var(--primary);
  border-radius: 4px 0 0 4px;
}

/* Dark-mode overrides for sidebar links */
:root[data-mode="dark"] .sidebar-nav .sb-link { color: rgba(255,255,255,0.7); }
:root[data-mode="dark"] .sidebar-nav .sb-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
@media (prefers-color-scheme: dark) {
  :root[data-mode="auto"] .sidebar-nav .sb-link { color: rgba(255,255,255,0.7); }
  :root[data-mode="auto"] .sidebar-nav .sb-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
}
.sidebar-close {
  display: none;
  background: transparent; border: 0; color: var(--sidebar-text);
  font-size: 1.5rem; cursor: pointer;
  margin-left: auto;
}

.admin-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.admin-header {
  background: var(--surface);
  padding: 0.875rem 1.5rem;
  display: flex; align-items: center; gap: 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  z-index: 1030;
  backdrop-filter: blur(8px);
}
.admin-header h1 { font-size: 1.05rem; margin: 0; font-weight: 600; }
.btn-burger {
  display: none;
  background: transparent; border: 1px solid var(--border);
  width: 40px; height: 40px;
  border-radius: 10px;
  align-items: center; justify-content: center;
  cursor: pointer;
}
.header-help-btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  background: var(--surface);
  font-size: 0.85rem; font-weight: 600;
  text-decoration: none;
  transition: all var(--t-fast);
  white-space: nowrap;
}
.header-help-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
}
.header-help-btn i { font-size: 1rem; }

.admin-content { padding: 1.5rem; flex: 1; }

@media (max-width: 991px) {
  .admin-sidebar {
    position: fixed; left: 0; top: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }
  .admin-sidebar.show { transform: translateX(0); }
  .sidebar-close { display: flex; }
  .btn-burger { display: inline-flex; }
  .admin-content { padding: 1rem; }
}

/* Backdrop for mobile sidebar */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1035;
}
.sidebar-backdrop.show { display: block; }

/* ============================================================
   Header user pill + Megamenu
   ============================================================ */
.user-menu-wrap { position: relative; }

.user-menu-trigger {
  display: inline-flex; align-items: center; gap: 0.6rem;
  padding: 0.35rem 0.85rem 0.35rem 0.4rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--t-fast);
  font-family: inherit;
}
.user-menu-trigger:hover { border-color: var(--primary); background: var(--surface-soft); }
.user-menu-trigger .um-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--theme-grad, linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.95rem;
  flex-shrink: 0;
}
.user-menu-trigger .um-info {
  display: flex; flex-direction: column; text-align: left; line-height: 1.15;
}
.user-menu-trigger .um-info .um-name { font-weight: 600; font-size: 0.85rem; color: var(--text); }
.user-menu-trigger .um-info .um-role { font-size: 0.7rem; color: var(--text-muted); }
.user-menu-trigger .um-chev { color: var(--text-muted); transition: transform var(--t-fast); font-size: 0.8rem; }
.user-menu-trigger[aria-expanded="true"] .um-chev { transform: rotate(180deg); }
@media (max-width: 575px) {
  .user-menu-trigger .um-info { display: none; }
  .user-menu-trigger { padding: 0.25rem; }
}

.megamenu {
  position: absolute;
  top: calc(100% + 8px); right: 0;
  width: 360px; max-width: calc(100vw - 1rem);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px -12px rgba(15, 23, 42, 0.25);
  border: 1px solid var(--border);
  opacity: 0; visibility: hidden;
  transform: translateY(-8px) scale(0.98);
  transition: all 180ms cubic-bezier(.4,0,.2,1);
  z-index: 1050;
  overflow: hidden;
}
.megamenu.open {
  opacity: 1; visibility: visible;
  transform: translateY(0) scale(1);
}

.mm-header {
  padding: 1.5rem 1.5rem;
  background: var(--theme-grad, linear-gradient(135deg, #4f46e5 0%, #7c3aed 60%, #ec4899 100%));
  color: #fff;
  position: relative; overflow: hidden;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.mm-header::after {
  content: ''; position: absolute; top: -30%; right: -10%;
  width: 60%; height: 160%;
  background: rgba(255, 255, 255, 0.08);
  transform: rotate(20deg);
  pointer-events: none;
}
.mm-avatar-lg {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 3px solid rgba(255, 255, 255, 0.3);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.6rem;
  flex-shrink: 0;
  position: relative; z-index: 1;
}
.mm-header-info { position: relative; z-index: 1; min-width: 0; flex: 1; }
.mm-name {
  font-size: 1.05rem; font-weight: 700;
  margin-bottom: 0.4rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mm-role-pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.7rem;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  font-size: 0.72rem; font-weight: 600;
}

.mm-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  padding: 1rem 1rem 0.75rem;
}
.mm-tile {
  display: flex; flex-direction: column; align-items: center;
  padding: 0.875rem 0.4rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: all var(--t-fast);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: inherit;
}
.mm-tile:hover {
  background: var(--surface-soft);
  color: var(--text);
  transform: translateY(-2px);
}
.mm-tile-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
  box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.06);
}
.mm-tile-icon.t-blue   { background: #dbeafe; color: #2563eb; }
.mm-tile-icon.t-amber  { background: #fef3c7; color: #d97706; }
.mm-tile-icon.t-green  { background: #d1fae5; color: #059669; }
.mm-tile-icon.t-pink   { background: #fce7f3; color: #db2777; }
.mm-tile-icon.t-teal   { background: #ccfbf1; color: #0d9488; }
.mm-tile-icon.t-purple { background: #ede9fe; color: #7c3aed; }
.mm-tile-label { font-size: 0.78rem; font-weight: 600; text-align: center; color: var(--text); }

.mm-footer { padding: 0 1rem 1rem; }
.mm-logout {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  width: 100%; padding: 0.75rem;
  background: var(--danger-light);
  color: var(--danger);
  border: 0;
  border-radius: 999px;
  font-weight: 700; font-size: 0.92rem;
  cursor: pointer; text-decoration: none;
  transition: all var(--t-fast);
}
.mm-logout:hover { background: #fecaca; color: #b91c1c; transform: translateY(-1px); }

:root[data-mode="dark"] .mm-tile-icon { box-shadow: none; filter: brightness(0.95); }
:root[data-mode="dark"] .mm-tile:hover { background: var(--surface-soft); }

/* ============================================================
   Stat cards
   ============================================================ */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  transition: all var(--t-base);
  position: relative;
  overflow: hidden;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-card::after {
  content: '';
  position: absolute; top: 0; right: 0;
  width: 100px; height: 100px;
  background: radial-gradient(circle, var(--stat-color, var(--primary)) 0%, transparent 70%);
  opacity: 0.08;
  transform: translate(30%, -30%);
}
.stat-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.75rem;
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: #fff;
  background: var(--stat-color, var(--primary));
}
.stat-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-value {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.stat-trend {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.78rem; font-weight: 600;
  margin-top: 0.4rem;
}
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ============================================================
   Card sections
   ============================================================ */
.card-section {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.section-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.section-header h3, .section-header h5 { margin: 0; }
.section-title {
  font-size: 1.4rem; font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 1.25rem;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  transition: all var(--t-fast);
  border: 1px solid transparent;
  display: inline-flex; align-items: center; gap: 0.4rem;
  justify-content: center;
}
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.8rem; }

.btn-primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background: var(--primary-dark); border-color: var(--primary-dark);
  transform: translateY(-1px); box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--surface); border-color: var(--border); color: var(--text);
}
.btn-secondary:hover { background: var(--surface-soft); border-color: var(--border-strong); }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-info { background: var(--info); border-color: var(--info); color: #fff; }

.btn-outline-primary { color: var(--primary); border-color: var(--border); background: transparent; }
.btn-outline-primary:hover { background: var(--primary-50); border-color: var(--primary); color: var(--primary-dark); }
.btn-outline-secondary { color: var(--text-muted); border-color: var(--border); background: transparent; }
.btn-outline-secondary:hover { background: var(--surface-soft); color: var(--text); }
.btn-outline-danger { color: var(--danger); border-color: var(--border); background: transparent; }
.btn-outline-danger:hover { background: var(--danger-light); border-color: var(--danger); color: var(--danger); }
.btn-outline-info { color: var(--info); border-color: var(--border); background: transparent; }
.btn-outline-info:hover { background: var(--info-light); border-color: var(--info); }
.btn-outline-warning { color: var(--warning); border-color: var(--border); background: transparent; }
.btn-outline-warning:hover { background: var(--warning-light); border-color: var(--warning); }
.btn-link { color: var(--primary); text-decoration: none; padding: 0.4rem 0.6rem; }
.btn-link:hover { color: var(--primary-dark); }

/* ============================================================
   Forms
   ============================================================ */
.form-control, .form-select {
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  padding: 0.55rem 0.85rem;
  font-size: 0.92rem;
  background: var(--surface);
  transition: all var(--t-fast);
  color: var(--text);
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
  outline: 0;
}
.form-control-sm, .form-select-sm { padding: 0.4rem 0.65rem; font-size: 0.85rem; }
.form-label { font-weight: 600; color: var(--text); font-size: 0.825rem; margin-bottom: 0.35rem; }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }

/* ============================================================
   Tables
   ============================================================ */
.table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  background: var(--surface);
}
.table thead th {
  background: var(--surface-soft);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  border-top: 0;
  white-space: nowrap;
}
.table tbody td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 0.9rem;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table-hover tbody tr { transition: background var(--t-fast); }
.table-hover tbody tr:hover { background: var(--surface-soft); }
.table-sm thead th { padding: 0.55rem 0.7rem; font-size: 0.7rem; }
.table-sm tbody td { padding: 0.55rem 0.7rem; font-size: 0.85rem; }
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
  font-weight: 600; padding: 0.3rem 0.6rem;
  border-radius: var(--radius-pill); font-size: 0.72rem;
  letter-spacing: 0.01em;
  display: inline-flex; align-items: center; gap: 0.25rem;
}
.bg-primary { background: var(--primary-100) !important; color: var(--primary-dark) !important; }
.bg-success { background: var(--success-light) !important; color: #065f46 !important; }
.bg-warning { background: var(--warning-light) !important; color: #92400e !important; }
.bg-danger { background: var(--danger-light) !important; color: #991b1b !important; }
.bg-info { background: var(--info-light) !important; color: #0e7490 !important; }
.bg-secondary { background: var(--surface-soft) !important; color: var(--text-muted) !important; }

/* Alerts */
.alert {
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0.875rem 1.125rem;
  font-size: 0.92rem;
}
.alert-success { background: var(--success-light); color: #065f46; border-color: #6ee7b7; }
.alert-warning { background: var(--warning-light); color: #92400e; border-color: #fcd34d; }
.alert-danger { background: var(--danger-light); color: #991b1b; border-color: #fca5a5; }
.alert-info { background: var(--info-light); color: #0e7490; border-color: #67e8f9; }

/* ============================================================
   Login page
   ============================================================ */
.login-bg {
  min-height: 100vh;
  background: var(--theme-grad, linear-gradient(135deg, #1e1b4b 0%, #312e81 100%));
  display: flex; align-items: center; justify-content: center;
  padding: 2rem 1rem;
  position: relative;
  overflow: hidden;
}
.login-bg::before, .login-bg::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
}
.login-bg::before {
  width: 380px; height: 380px;
  background: rgba(255, 255, 255, 0.15);
  top: -10%; left: -10%;
}
.login-bg::after {
  width: 480px; height: 480px;
  background: rgba(255, 255, 255, 0.08);
  bottom: -20%; right: -10%;
}
.login-card { position: relative; z-index: 1; }
.login-card {
  background: var(--surface);
  max-width: 420px;
  width: 100%;
  padding: 2.5rem 2rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
}
.login-logo {
  width: 64px; height: 64px;
  background: var(--theme-grad, linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%));
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 2rem;
  margin: 0 auto 1.25rem;
  box-shadow: var(--shadow-primary);
}

/* ============================================================
   Dropdown
   ============================================================ */
.dropdown-menu {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 0.4rem;
  min-width: 180px;
}
.dropdown-item {
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}
.dropdown-item:hover { background: var(--surface-soft); color: var(--text); }
.dropdown-item.active { background: var(--primary-50); color: var(--primary-dark); }

/* ============================================================
   Thai date picker
   ============================================================ */
.tdp-wrapper { position: relative; }
.tdp-display { cursor: pointer; padding-right: 2rem; }
.tdp-popup {
  position: absolute;
  top: calc(100% + 4px); left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl);
  padding: 1rem;
  min-width: 304px;
  z-index: 1050;
  display: none;
  animation: tdpFade 150ms ease-out;
}
.tdp-popup.open { display: block; }
@keyframes tdpFade { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.tdp-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.tdp-nav { background: transparent; border: 0; width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted); transition: all var(--t-fast); }
.tdp-nav:hover { background: var(--surface-soft); color: var(--text); }
.tdp-title { font-weight: 700; cursor: pointer; padding: 0.4rem 0.75rem; border-radius: 8px; transition: background var(--t-fast); }
.tdp-title:hover { background: var(--surface-soft); }
.tdp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.tdp-dow { text-align: center; font-size: 0.72rem; font-weight: 700; color: var(--text-muted); padding: 0.4rem 0; }
.tdp-day { text-align: center; padding: 0.5rem 0; font-size: 0.9rem; font-weight: 500; cursor: pointer; border-radius: 8px; transition: all var(--t-fast); color: var(--text); }
.tdp-day:hover { background: var(--primary-50); color: var(--primary-dark); }
.tdp-day.muted { color: var(--text-soft); }
.tdp-day.today { color: var(--primary); font-weight: 700; box-shadow: inset 0 0 0 1.5px var(--primary); }
.tdp-day.selected { background: var(--primary); color: #fff; font-weight: 700; }
.tdp-day.disabled { color: var(--text-soft); cursor: not-allowed; opacity: 0.4; }
.tdp-day.disabled:hover { background: transparent; }
.tdp-footer { display: flex; justify-content: space-between; margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.tdp-footer button { background: transparent; border: 0; color: var(--primary); font-weight: 600; font-size: 0.875rem; cursor: pointer; padding: 0.4rem 0.75rem; border-radius: 6px; }
.tdp-footer button:hover { background: var(--primary-50); }
.tdp-months, .tdp-years { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.tdp-mo, .tdp-yr { text-align: center; padding: 0.75rem 0; border-radius: 8px; cursor: pointer; font-size: 0.9rem; font-weight: 500; transition: all var(--t-fast); }
.tdp-mo:hover, .tdp-yr:hover { background: var(--primary-50); color: var(--primary-dark); }
.tdp-mo.selected, .tdp-yr.selected { background: var(--primary); color: #fff; font-weight: 700; }
.tdp-time-bar {
  display: flex; align-items: center; gap: 0.4rem;
  padding-top: 0.75rem; margin-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.tdp-time-label {
  flex: 1; color: var(--text-muted); font-size: 0.82rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 0.3rem;
}
.tdp-time-input {
  width: 56px;
  text-align: center;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.3rem;
  font-size: 1rem;
  font-weight: 700;
  background: var(--surface);
  color: var(--text);
  appearance: textfield;
  -moz-appearance: textfield;
}
.tdp-time-input::-webkit-outer-spin-button,
.tdp-time-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.tdp-time-input:focus {
  border-color: var(--primary); outline: 0;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
}
.tdp-time-colon { font-weight: 800; color: var(--text); padding: 0 0.15rem; }
.tdp-done-btn { background: var(--primary) !important; color: #fff !important; padding: 0.4rem 0.85rem !important; }
.tdp-done-btn:hover { background: var(--primary-dark) !important; }

/* Utilities */
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-muted { color: var(--text-muted) !important; }

/* Bus layout (admin seat map) */
.bus-layout {
  background: linear-gradient(180deg, var(--surface-soft) 0%, var(--bg) 100%);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1rem;
  max-width: 360px;
  margin: 0 auto;
  border: 1px solid var(--border);
}
.bus-driver {
  display: flex; justify-content: flex-end;
  border-bottom: 2px dashed var(--border-strong);
  padding-bottom: 0.6rem; margin-bottom: 1rem;
  color: var(--text-muted);
}
.bus-driver i { font-size: 1.4rem; }
.seat-row { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.4rem; justify-content: center; }
.seat-row .gap { flex: 1; min-width: 0.75rem; }
.seat {
  width: 38px; height: 42px;
  border: 2px solid var(--border-strong);
  border-radius: 8px 8px 4px 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700;
  background: var(--surface); color: var(--text);
  cursor: default;
  transition: all var(--t-fast);
}
.seat.booked { background: #fecaca; color: #991b1b; border-color: #fca5a5; }
.seat-legend {
  display: flex; gap: 1rem; justify-content: center;
  margin-top: 1rem; font-size: 0.85rem; color: var(--text-muted);
}
.seat-legend > div { display: inline-flex; align-items: center; gap: 0.4rem; }

/* ============================================================
   Appearance Settings page
   ============================================================ */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}
.settings-card-header {
  display: flex; align-items: flex-start; gap: 1rem;
  margin-bottom: 1.25rem;
}
.settings-icon {
  width: 56px; height: 56px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  color: #fff;
  flex-shrink: 0;
}
.settings-icon.bg-indigo { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.settings-icon.bg-orange { background: linear-gradient(135deg, #f97316, #ea580c); }
.settings-icon.bg-blue   { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.settings-icon.bg-green  { background: linear-gradient(135deg, #10b981, #059669); }
.settings-icon.bg-red    { background: linear-gradient(135deg, #ef4444, #dc2626); }
.settings-title { font-size: 1.15rem; font-weight: 700; margin: 0; line-height: 1.2; }
.settings-subtitle { color: var(--text-muted); font-size: 0.85rem; margin: 0.25rem 0 0; }

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.875rem;
}
.theme-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--t-base);
  overflow: hidden;
  text-align: center;
  padding: 0;
}
.theme-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.theme-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}
.theme-preview {
  height: 110px;
  position: relative;
  display: flex;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.theme-preview-sidebar {
  width: 28%;
  display: flex; flex-direction: column;
  padding: 0.5rem 0.4rem;
  gap: 0.3rem;
}
.theme-preview-sidebar span {
  display: block; height: 6px;
  background: rgba(255,255,255,0.35);
  border-radius: 3px;
}
.theme-preview-sidebar span:first-child { width: 80%; height: 8px; background: rgba(255,255,255,0.6); }
.theme-preview-main {
  flex: 1;
  display: flex; flex-direction: column;
  gap: 0.35rem; padding: 0.55rem 0.5rem;
}
.theme-preview-main .bar { height: 5px; background: rgba(120,120,120,0.18); border-radius: 3px; }
.theme-preview-main .bar.long { width: 70%; }
.theme-preview-main .bar.short { width: 40%; }
.theme-preview-main .block {
  flex: 1; background: rgba(120,120,120,0.08);
  border-radius: 4px;
}
.theme-preview-badge {
  position: absolute; top: 4px; left: 6px;
  background: rgba(255,255,255,0.85);
  color: #1e293b;
  font-size: 0.55rem; font-weight: 800;
  padding: 0.15rem 0.4rem; border-radius: 4px;
  letter-spacing: 0.05em;
}
.theme-preview-dot {
  position: absolute; top: 8px; right: 8px;
  width: 7px; height: 7px;
  border-radius: 50%;
}
.theme-card-label { padding: 0.7rem 0.5rem; font-weight: 600; font-size: 0.88rem; color: var(--text); }
.theme-card-check {
  position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px;
  background: var(--primary); color: #fff;
  border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  font-size: 0.7rem; box-shadow: var(--shadow-md);
}
.theme-card.active .theme-card-check { display: inline-flex; }
.theme-card { position: relative; }

/* Mode toggle */
.mode-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem;
}
.mode-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--t-base);
  background: var(--surface);
}
.mode-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.mode-card.active { border-color: var(--primary); background: var(--primary-50); }
.mode-card i { font-size: 1.75rem; color: var(--primary); margin-bottom: 0.5rem; }
.mode-card .label { font-weight: 700; font-size: 0.95rem; }
.mode-card .sub { color: var(--text-muted); font-size: 0.78rem; }

/* Font size selector */
.size-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.75rem;
}
.size-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 0.5rem;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
  transition: all var(--t-base);
}
.size-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.size-card.active { border-color: var(--primary); background: var(--primary-50); box-shadow: 0 0 0 4px rgba(99,102,241,0.12); }
.size-card .glyph { color: var(--primary); font-weight: 700; line-height: 1; margin-bottom: 0.4rem; }
.size-card .px { font-weight: 700; font-size: 0.92rem; }
.size-card .desc { color: var(--text-muted); font-size: 0.72rem; }

/* Font family selector */
.font-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem;
}
.font-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  cursor: pointer; background: var(--surface);
  transition: all var(--t-base);
}
.font-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.font-card.active { border-color: var(--primary); background: var(--primary-50); box-shadow: 0 0 0 4px rgba(99,102,241,0.12); }
.font-card .preview { font-size: 1.4rem; font-weight: 700; line-height: 1.15; margin-bottom: 0.5rem; color: var(--text); }
.font-card .preview small { font-weight: 400; font-size: 0.85rem; color: var(--text-muted); margin-left: 0.4rem; }
.font-card .name { font-family: 'Inter', sans-serif; font-size: 0.92rem; font-weight: 600; }
.font-card .badge-mini {
  display: inline-block; margin-top: 0.4rem;
  background: var(--surface-soft); padding: 0.15rem 0.5rem;
  border-radius: 999px; font-size: 0.72rem; color: var(--text-muted);
}

/* Lang select cards */
.lang-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem;
}
.lang-card {
  display: flex; align-items: center; gap: 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer; background: var(--surface);
  position: relative;
  transition: all var(--t-base);
  text-decoration: none; color: var(--text);
}
.lang-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); color: var(--text); }
.lang-card.active { border-color: var(--primary); background: var(--primary-50); box-shadow: 0 0 0 4px rgba(99,102,241,0.12); }
.lang-card .flag { font-size: 2rem; line-height: 1; }
.lang-card .label { font-weight: 700; font-size: 0.95rem; }
.lang-card .sub { color: var(--text-muted); font-size: 0.78rem; }
.lang-card .check {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px;
  background: var(--primary); color: #fff;
  border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  font-size: 0.7rem;
}
.lang-card.active .check { display: inline-flex; }

/* File uploader (logo / favicon) */
.uploader {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  transition: all var(--t-fast);
  background: var(--surface-soft);
}
.uploader.dragover { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }
.uploader-preview {
  width: 88px; height: 88px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  color: var(--text-soft);
  font-size: 2rem;
  position: relative;
}
.uploader-preview img {
  width: 100%; height: 100%;
  object-fit: contain;
}
.uploader.favicon .uploader-preview { width: 64px; height: 64px; font-size: 1.4rem; border-radius: 12px; }
.uploader-info { flex: 1; min-width: 0; }
.uploader-info .name { font-weight: 600; color: var(--text); margin-bottom: 0.15rem; }
.uploader-info .hint { color: var(--text-muted); font-size: 0.8rem; }
.uploader-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }
.uploader input[type=file] { display: none; }


.app-toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: #0f172a; color: #fff;
  padding: 0.8rem 1.2rem;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 600; font-size: 0.9rem;
  opacity: 0; transform: translateY(20px);
  transition: all 250ms ease;
  z-index: 2000;
  pointer-events: none;
}
.app-toast.show { opacity: 1; transform: translateY(0); }
.app-toast i { color: #10b981; font-size: 1.1rem; }

@media print {
  .admin-sidebar, .admin-header, .no-print { display: none !important; }
  .admin-main { display: block !important; }
  .admin-content { padding: 0 !important; }
}

/* ── Dashboard alerts (payments needing attention) ── */
.dash-alerts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem; }
.dash-alert {
  display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; border-radius: var(--radius-lg, 1rem);
  text-decoration: none; font-size: .92rem; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.dash-alert:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); color: var(--text); }
.dash-alert > i:first-child { width: 38px; height: 38px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.05rem; }
.dash-alert.tone-warning > i:first-child { background: color-mix(in srgb, #f59e0b 16%, transparent); color: #d97706; }
.dash-alert.tone-info > i:first-child    { background: color-mix(in srgb, #06b6d4 16%, transparent); color: #0891b2; }
.dash-alert.tone-danger > i:first-child  { background: color-mix(in srgb, #ef4444 16%, transparent); color: #dc2626; }

/* ── Brand (Waypoint default artwork) ─────────────────────── */
.sidebar-brand-mark { height: 38px; width: auto; flex-shrink: 0; display: block; }
.brand-on-dark { display: none !important; }
:root[data-mode="dark"] .brand-on-light { display: none !important; }
:root[data-mode="dark"] .brand-on-dark { display: block !important; }
@media (prefers-color-scheme: dark) {
  :root[data-mode="auto"] .brand-on-light { display: none !important; }
  :root[data-mode="auto"] .brand-on-dark { display: block !important; }
}
.login-brand { display: block; max-width: 260px; margin: 0 auto 1.25rem; }
.login-brand img { width: 100%; height: auto; display: block; }
