:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --text: #1e2333;
  --text-muted: #6b7280;
  --border: #e7e9f0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #0891b2;
  --info-soft: #cffafe;
  --sidebar-bg: #171a2b;
  --sidebar-text: #b6bad3;
  --sidebar-active: #4f46e5;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.10);
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #0f1220;
  --surface: #171a2b;
  --surface-2: #1d2137;
  --text: #e6e8f0;
  --text-muted: #949bbd;
  --border: #2a2f47;
  --primary: #6366f1;
  --primary-hover: #7c7ff1;
  --primary-soft: #262c4d;
  --success: #22c55e;
  --success-soft: #113322;
  --warning: #f59e0b;
  --warning-soft: #3a2b0e;
  --danger: #f87171;
  --danger-soft: #3a1d1d;
  --info: #22d3ee;
  --info-soft: #0e2f36;
  --sidebar-bg: #0b0d18;
  --sidebar-text: #9aa0c3;
  --sidebar-active: #6366f1;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  transition: background .2s ease, color .2s ease;
}

a { text-decoration: none; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 1030;
  transition: transform .25s ease;
}
.sidebar-brand {
  padding: 22px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: #fff;
  font-size: 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand .logo-badge {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #fff;
}
.sidebar-section-title {
  padding: 16px 20px 6px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6a7099;
  font-weight: 700;
}
.sidebar-nav { padding: 6px 12px 24px; }
.sidebar-nav .nav-link {
  color: var(--sidebar-text);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .92rem;
  font-weight: 500;
  transition: all .15s ease;
}
.sidebar-nav .nav-link i { width: 18px; text-align: center; font-size: 1rem; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav .nav-link.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79,70,229,.35);
}

.main-content { margin-left: 260px; flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 1020;
}

.page-body { padding: 24px; flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
}
.card-header { background: transparent; border-bottom: 1px solid var(--border); font-weight: 600; }

.stat-card {
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 16px;
}
.stat-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--text-muted); font-size: .82rem; margin-top: 2px; }

/* ---------- Tables ---------- */
.table { color: var(--text); }
.table > :not(caption) > * > * { background: transparent; color: var(--text); border-color: var(--border); }
.table thead th {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); border-bottom-width: 1px; font-weight: 700;
}
.table-hover > tbody > tr:hover > * { background: var(--surface-2); }

.badge-soft-primary { background: var(--primary-soft); color: var(--primary); }
.badge-soft-success { background: var(--success-soft); color: var(--success); }
.badge-soft-warning { background: var(--warning-soft); color: var(--warning); }
.badge-soft-danger { background: var(--danger-soft); color: var(--danger); }
.badge-soft-info { background: var(--info-soft); color: var(--info); }
.badge { font-weight: 600; padding: 5px 10px; border-radius: 8px; }

/* ---------- Forms ---------- */
.form-control, .form-select {
  background: var(--surface); color: var(--text); border-color: var(--border);
  border-radius: 10px;
}
.form-control:focus, .form-select:focus {
  background: var(--surface); color: var(--text);
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-label { font-weight: 600; font-size: .85rem; color: var(--text-muted); }
.input-group-text { background: var(--surface-2); border-color: var(--border); color: var(--text-muted); }

.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-light { background: var(--surface-2); border-color: var(--border); color: var(--text); }

.modal-content { background: var(--surface); color: var(--text); border-radius: var(--radius); border: 1px solid var(--border); }
.modal-header, .modal-footer { border-color: var(--border); }

.dropdown-menu { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-lg); }
.dropdown-item { color: var(--text); }
.dropdown-item:hover { background: var(--surface-2); color: var(--text); }

.theme-toggle-btn {
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; color: var(--text);
}

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 10% 10%, rgba(99,102,241,.18), transparent),
              radial-gradient(1200px 600px at 90% 90%, rgba(139,92,246,.15), transparent),
              var(--bg);
}
.login-card { width: 100%; max-width: 420px; }

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

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .sidebar-overlay.show { display: block; }
}

.scroll-x { overflow-x: auto; }
.avatar-circle {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700;
}

.brand-logo-img { max-height: 34px; width: auto; object-fit: contain; }
.login-logo-img { max-height: 64px; width: auto; object-fit: contain; }

/* ---------- DataTables (theme-aware) ---------- */
.dataTables_wrapper { color: var(--text); }
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_processing,
.dataTables_wrapper .dataTables_paginate { color: var(--text); }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  background: var(--surface); color: var(--text); border-color: var(--border);
  border-radius: 8px; border-width: 1px; border-style: solid;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  border-radius: 8px;
  margin-left: 2px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--surface-2) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
  background: var(--surface) !important;
  color: var(--text-muted) !important;
  border-color: var(--border) !important;
}
table.dataTable thead th, table.dataTable thead td {
  color: var(--text-muted);
  border-bottom: 1px solid var(--border) !important;
}
table.dataTable tbody th, table.dataTable tbody td {
  color: var(--text);
}
table.dataTable.order-column tbody tr > .sorting_1,
table.dataTable tbody tr.odd, table.dataTable tbody tr.even {
  background: var(--surface) !important;
}
table.dataTable tbody tr:hover > * { background: var(--surface-2) !important; }
table.dataTable th.dt-orderable-asc:hover, table.dataTable th.dt-orderable-desc:hover { color: var(--text); }
.dt-container .dt-search input:focus, .dt-container .dt-length select:focus {
  outline: none; border-color: var(--primary) !important; box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ---------- Animated deadline ticker ---------- */
.deadline-ticker {
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  color: #fff;
  border-radius: 12px;
  padding: 10px 0;
  overflow: hidden;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.deadline-ticker-inner {
  display: inline-block;
  padding-left: 100%;
  font-weight: 600;
  font-size: .92rem;
  animation: ticker-scroll 16s linear infinite;
}
@keyframes ticker-scroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-100%); }
}
@media (prefers-reduced-motion: reduce) {
  .deadline-ticker-inner { animation: none; padding-left: 16px; white-space: normal; }
}

/* ---------- Responsive pass ---------- */
@media (max-width: 767.98px) {
  .page-body { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .card-header { flex-direction: column; align-items: stretch !important; gap: 8px; }
  .card-header .d-flex { flex-wrap: wrap; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 1.25rem; }
  .modal-dialog { margin: 10px; max-width: calc(100% - 20px); }
  .modal-dialog.modal-lg, .modal-dialog.modal-xl { max-width: calc(100% - 20px); }
  table.dataTable { font-size: .82rem; }
  .btn-group { flex-wrap: wrap; }
  .row.g-2 > [class^="col-"], .row.g-3 > [class^="col-"] { margin-bottom: 4px; }
  .deadline-ticker-inner { font-size: .82rem; }
  .login-card { margin: 0 10px; }
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter { text-align: left !important; float: none !important; width: 100%; margin-bottom: 8px; }
  .dataTables_wrapper .dataTables_filter input { width: 100%; margin-left: 0 !important; }
  .dataTables_wrapper .dataTables_paginate { text-align: center !important; float: none !important; }
  .dataTables_wrapper .dataTables_info { text-align: center !important; float: none !important; }
}

@media (max-width: 575.98px) {
  .sidebar-brand .brand-logo-img { max-height: 28px; }
  .avatar-circle { width: 30px; height: 30px; font-size: .75rem; }
  h5 { font-size: 1rem; }
  .stat-icon { width: 42px; height: 42px; font-size: 1.05rem; }
}
