:root {
  --ad-primary: #1d4ed8;
  --ad-primary-dark: #1e3a8a;
  --ad-primary-50: #eff4ff;
  --ad-sidebar-bg: #111C32;
  --ad-sidebar-bg-2: #111C32;
  --ad-sidebar-link: #E2E8F0;
  --ad-sidebar-link-active: #ffffff;
  --ad-bg: #f1f5f9;
  --ad-surface: #ffffff;
  --ad-border: #e2e8f0;
  --ad-text: #0f172a;
  --ad-muted: #64748b;
  --ad-success: #16a34a;
  --ad-danger: #dc2626;
  --ad-warning: #d97706;
  --ad-radius: 12px;
  --ad-shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --ad-shadow-lg: 0 10px 30px rgba(15,23,42,.12);
  --ad-sidebar-w: 256px;
  --ad-topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--ad-bg);
  color: var(--ad-text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

.ad-sidebar {
  width: var(--ad-sidebar-w);
  background: linear-gradient(180deg, var(--ad-sidebar-bg), var(--ad-sidebar-bg-2));
  color: #e2e8f0;
  position: fixed; top: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column;
  z-index: 1040;
  transition: transform .25s ease;
}
.ad-brand {
  height: var(--ad-topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.ad-brand .logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: #2563EB;
  display: grid; place-items: center;
  font-weight: 800; color: #fff; letter-spacing: .5px;
  box-shadow: 0 4px 12px rgba(29,78,216,.45);
}
.ad-brand .name { font-weight: 700; font-size: 16px; color: #fff; line-height: 1; }
.ad-brand .sub { font-size: 11px; color: #A8B8D0; letter-spacing: 1.5px; }

.ad-nav { padding: 16px 12px; overflow-y: auto; flex: 1; }
.ad-nav .section { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #A8B8D0; padding: 14px 12px 6px; }
.ad-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 2px;
  color: var(--ad-sidebar-link); text-decoration: none;
  border-radius: 10px; font-weight: 500;
  transition: all .15s ease;
}
.ad-nav a i { font-size: 18px; width: 20px; text-align: center; color: #B8C7DD; }
.ad-nav a:hover { background: #1E2B45; color: #FFFFFF; }
.ad-nav a.active {
  background: #2563EB;
  color: var(--ad-sidebar-link-active);
  box-shadow: 0 4px 14px rgba(37,99,235,.45);
}
.ad-nav a:hover i, .ad-nav a.active i { color: #FFFFFF; }
.ad-nav a:focus-visible { outline: 2px solid #60A5FA; outline-offset: 2px; }

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

.ad-topbar {
  height: var(--ad-topbar-h);
  background: var(--ad-surface);
  border-bottom: 1px solid var(--ad-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 1030;
}
.ad-topbar .left { display: flex; align-items: center; gap: 16px; }
.ad-hamburger { display: none; background: none; border: none; font-size: 22px; color: var(--ad-text); cursor: pointer; }
.ad-page-title { font-size: 18px; font-weight: 700; margin: 0; }

.ad-user { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.ad-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--ad-primary), var(--ad-primary-dark));
  color: #fff; display: grid; place-items: center; font-weight: 700;
}

.ad-content { padding: 24px; flex: 1; }

.ad-breadcrumb { font-size: 13px; color: var(--ad-muted); margin-bottom: 18px; }
.ad-breadcrumb a { color: var(--ad-primary); text-decoration: none; }
.ad-breadcrumb .sep { margin: 0 8px; color: #cbd5e1; }

/* ---------------- Cards ---------------- */
.ad-card {
  background: var(--ad-surface);
  border: 1px solid var(--ad-border);
  border-radius: var(--ad-radius);
  box-shadow: var(--ad-shadow);
}
.ad-card .ad-card-head {
  padding: 18px 20px; border-bottom: 1px solid var(--ad-border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.ad-card .ad-card-head h2 { font-size: 16px; font-weight: 700; margin: 0; }
.ad-card .ad-card-body { padding: 20px; }

/* ---------------- KPI cards ---------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.kpi {
  background: var(--ad-surface); border: 1px solid var(--ad-border);
  border-radius: var(--ad-radius); padding: 20px; box-shadow: var(--ad-shadow);
  display: flex; align-items: flex-start; justify-content: space-between;
  transition: transform .15s ease, box-shadow .15s ease;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--ad-shadow-lg); }
.kpi .label { color: var(--ad-muted); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 800; margin-top: 6px; letter-spacing: -.5px; }
.kpi .ico { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; }
.kpi .ico.blue { background: #dbeafe; color: #1d4ed8; }
.kpi .ico.green { background: #dcfce7; color: #16a34a; }
.kpi .ico.amber { background: #fef3c7; color: #d97706; }
.kpi .ico.rose { background: #ffe4e6; color: #e11d48; }
.mini-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 20px; margin-top: 20px; }

/* ---------------- Buttons / forms ---------------- */
.btn-ad { background: var(--ad-primary); border-color: var(--ad-primary); color: #fff; font-weight: 600; }
.btn-ad:hover { background: var(--ad-primary-dark); border-color: var(--ad-primary-dark); color: #fff; }
.form-label { font-weight: 600; font-size: 13px; color: #334155; }
.required::after { content: " *"; color: var(--ad-danger); }
table.dataTable tbody td { vertical-align: middle; }
.badge-soft-success { background: #dcfce7; color: #166534; }
.badge-soft-danger { background: #fee2e2; color: #991b1b; }
.badge-soft-blue { background: #dbeafe; color: #1e40af; }
.table-actions .btn { padding: 4px 9px; }

/* ---------------- Login ---------------- */
.login-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr;
  background: #F3F6FC;
}
.login-hero {
  background: linear-gradient(150deg, #0c1322 0%, #111C32 58%, #16233f 100%);
  color: #fff; padding: 60px 56px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.login-hero::after {
  content: ""; position: absolute; right: -130px; top: -120px; width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(37,99,235,.28), transparent 70%); border-radius: 50%;
}
.login-hero::before {
  content: ""; position: absolute; left: -90px; bottom: -110px; width: 320px; height: 320px;
  background: radial-gradient(circle, rgba(37,99,235,.14), transparent 70%); border-radius: 50%;
}
.login-hero .logo-lg { width: 56px; height: 56px; border-radius: 15px; background: #2563EB; display: grid; place-items: center; font-weight: 800; font-size: 20px; box-shadow: 0 8px 24px rgba(37,99,235,.4); position: relative; z-index: 1; }
.login-hero h1 { font-size: 34px; font-weight: 800; line-height: 1.15; margin: 28px 0 14px; position: relative; z-index: 1; }
.login-hero p { color: #cbd5e1; font-size: 15px; max-width: 420px; position: relative; z-index: 1; }
.login-hero .feat { display: flex; align-items: center; gap: 12px; color: #e2e8f0; margin: 14px 0; position: relative; z-index: 1; }
.login-hero .feat i { color: #60a5fa; }
.login-form-side { display: grid; place-items: center; padding: 40px; background: #F3F6FC; }
.login-card {
  width: 100%; max-width: 410px;
  background: #fff; border: 1px solid #E5E7EB; border-radius: 16px;
  padding: 38px 34px; box-shadow: 0 10px 30px rgba(17,24,39,.06);
}
.login-card h2 { font-weight: 800; font-size: 24px; color: #111827; }
.login-card .muted { color: #64748B; margin-bottom: 26px; }
.input-icon { position: relative; }
.input-icon i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: #94a3b8; }
.input-icon .form-control { padding-left: 42px; height: 46px; }
.login-card .form-label { color: #111827; font-weight: 600; }
.login-card .form-control { background: #fff; border: 1px solid #D1D5DB; color: #111827; }
.login-card .form-control::placeholder { color: #9CA3AF; }
.login-card .form-control:focus { border-color: #2563EB; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.login-card .form-control.has-toggle { padding-right: 46px; }
.login-card .btn-ad { background: #2563EB; border-color: #2563EB; }
.login-card .btn-ad:hover { background: #1D4ED8; border-color: #1D4ED8; }
.login-card .form-check-label { color: #64748B; }
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; color: #64748B;
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; display: grid; place-items: center;
  transition: all .15s ease;
}
.pw-toggle:hover { color: #111827; background: #F1F5F9; }
.pw-toggle:focus-visible { outline: 2px solid #2563EB; outline-offset: 2px; }

/* ---------------- Toast ---------------- */
.ad-toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }

/* ---------------- Responsive ---------------- */
.ad-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 1035; }
@media (max-width: 1100px) { .kpi-grid, .mini-grid { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 992px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .login-form-side { padding: 28px 18px; }
  .login-card { max-width: 440px; }
}
@media (max-width: 768px) {
  .ad-sidebar { transform: translateX(-100%); }
  .ad-sidebar.open { transform: translateX(0); }
  .ad-main { margin-left: 0; }
  .ad-hamburger { display: block; }
  .ad-backdrop.show { display: block; }
  .ad-content { padding: 16px; }
  .kpi-grid, .mini-grid { grid-template-columns: 1fr; }
}

/* ======================================================
   Collapsible sidebar + topbar icon buttons (added v3)
   ====================================================== */
.ad-sidebar, .ad-main { transition: all .22s ease; }

.ad-collapse-btn, .ad-icon-btn {
  background: transparent; border: 1px solid var(--ad-border);
  color: #475569; width: 40px; height: 40px; border-radius: 10px;
  display: inline-grid; place-items: center; font-size: 18px; cursor: pointer;
  transition: all .15s ease;
}
.ad-collapse-btn:hover, .ad-icon-btn:hover { background: var(--ad-primary-50); color: var(--ad-primary); border-color: #c7d2fe; }
@media (max-width: 768px) { .ad-collapse-btn { display: none; } }

/* Collapsed state (desktop only) */
@media (min-width: 769px) {
  .ad-shell.collapsed .ad-sidebar { width: 76px; }
  .ad-shell.collapsed .ad-main { margin-left: 76px; }
  .ad-shell.collapsed .ad-brand { justify-content: center; padding: 0 10px; }
  .ad-shell.collapsed .brand-text { display: none; }
  .ad-shell.collapsed .ad-nav { padding: 16px 10px; }
  .ad-shell.collapsed .ad-nav .section { text-align: center; padding: 14px 0 6px; font-size: 0; }
  .ad-shell.collapsed .ad-nav .section::before { content: "•••"; font-size: 11px; letter-spacing: 1px; }
  .ad-shell.collapsed .ad-nav a { justify-content: center; padding: 12px 0; gap: 0; }
  .ad-shell.collapsed .ad-nav a .txt { display: none; }
  .ad-shell.collapsed .ad-nav a i { width: auto; font-size: 19px; }
}

/* Full-height app shell (fills the whole screen) */
html, body { min-height: 100%; }
.ad-shell { min-height: 100vh; }
.ad-main { min-height: 100vh; }

/* Six-card KPI grid (dashboard) */
.kpi-grid.six { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) { .kpi-grid.six { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px)  { .kpi-grid.six { grid-template-columns: 1fr; } }

/* ======================================================
   v4: typography, live/upcoming dashboard, feedback
   ====================================================== */
body { font-size: 15px; }                 /* regular UI text 14-16px */
.ad-page-title { font-size: 22px; }        /* page title 22-24px */

.section-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  font-weight: 700; color: var(--ad-muted); margin: 0 0 12px 2px;
}

/* Clickable live KPI cards */
.kpi-link { text-decoration: none; color: inherit; }
.kpi-link .kpi-cta {
  margin-top: 8px; font-size: 12px; font-weight: 600; color: var(--ad-primary);
  opacity: 0; transform: translateX(-4px); transition: all .15s ease;
}
.kpi-link:hover .kpi-cta { opacity: 1; transform: translateX(0); }

/* "Soon" pill */
.soon-pill {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .3px;
  padding: 2px 8px; border-radius: 999px; background: #FDE68A; color: #78350F;
  text-transform: uppercase; vertical-align: middle;
}

/* Upcoming module tiles (no live numbers) */
.upcoming-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 1100px) { .upcoming-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px)  { .upcoming-grid { grid-template-columns: 1fr; } }
.upcoming-tile {
  background: var(--ad-surface); border: 1px dashed #cbd5e1; border-radius: var(--ad-radius);
  padding: 18px 20px; box-shadow: none; opacity: .85;
}
.upcoming-tile .ut-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.upcoming-tile .ico { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 19px; }
.upcoming-tile .ut-title { font-weight: 700; font-size: 15px; }
.upcoming-tile .ut-desc { color: var(--ad-muted); font-size: 12.5px; margin-top: 4px; }

/* Disabled sidebar items (modules not built yet) */
.ad-nav .nav-soon {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 2px; border-radius: 10px;
  color: #A8B8D0; font-weight: 500; cursor: default; opacity: .85; user-select: none;
}
.ad-nav .nav-soon i { font-size: 18px; width: 20px; text-align: center; color: #B8C7DD; }
.ad-nav .nav-soon .soon-pill { margin-left: 6px; }
@media (min-width: 769px) {
  .ad-shell.collapsed .ad-nav .nav-soon { justify-content: center; padding: 12px 0; gap: 0; }
  .ad-shell.collapsed .ad-nav .nav-soon .txt { display: none; }
  .ad-shell.collapsed .ad-nav .nav-soon i { width: auto; }
}

/* Global AJAX loading bar */
.ad-loadbar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--ad-primary), #60a5fa);
  z-index: 3000; opacity: 0; transition: width .25s ease, opacity .3s ease;
}
.ad-loadbar.active { opacity: 1; }

/* DataTables processing indicator spacing */
div.dataTables_processing { border-radius: 10px; box-shadow: var(--ad-shadow-lg); }

/* ======================================================
   v5: collapsible sidebar submenu groups
   ====================================================== */
.ad-nav { overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: transparent transparent; }
.ad-nav:hover { scrollbar-color: #334155 transparent; }
.ad-nav::-webkit-scrollbar { width: 6px; }
.ad-nav::-webkit-scrollbar-track { background: transparent; }
.ad-nav::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
.ad-nav:hover::-webkit-scrollbar-thumb { background: #334155; }

/* Section group toggle button */
.ad-group-toggle {
  width: 100%; background: transparent; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 8px; margin-top: 6px;
  color: #A8B8D0; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  transition: color .15s ease;
}
.ad-group-toggle:hover { color: #E2E8F0; }
.ad-group-toggle:focus-visible { outline: 2px solid var(--ad-primary); outline-offset: 2px; border-radius: 8px; }
.ad-group-toggle .chev { font-size: 12px; color: #94A3B8; transition: transform .22s ease; }
.ad-group-toggle.collapsed .chev { transform: rotate(-90deg); }

/* Submenu items (indented, with a guide line) */
.ad-group { position: relative; }
.ad-group::before {
  content: ""; position: absolute; left: 20px; top: 2px; bottom: 6px;
  width: 1px; background: rgba(255,255,255,.07);
}
.ad-group a, .ad-group .nav-soon { padding-left: 30px; }

/* Collapsed (icon-rail) mode: hide toggles, flatten groups to icon list */
@media (min-width: 769px) {
  .ad-shell.collapsed .ad-nav .ad-group-toggle { display: none; }
  .ad-shell.collapsed .ad-nav .ad-group { display: block !important; height: auto !important; visibility: visible !important; }
  .ad-shell.collapsed .ad-nav .ad-group::before { display: none; }
  .ad-shell.collapsed .ad-group a, .ad-shell.collapsed .ad-group .nav-soon { padding-left: 0; }
}
