/* ============================================================================
 * Official Travel & Student Field Trip Management System (CMTC Travel)
 * Executive Thai E-Government Design System (PC & Mobile Responsive)
 * ============================================================================ */

:root {
  /* Tier 1 & 2: Brand & Semantic Tokens */
  --app-primary: #0f3d75;
  --app-primary-hover: #0a2d59;
  --app-primary-dark: #08203e;
  --app-primary-mid: #164e91;
  --app-accent: #d4a33b;
  --app-accent-soft: #fef7e6;

  --app-bg: #f3f6fb;
  --app-surface: #ffffff;
  --app-surface-subtle: #f8fafd;
  --app-border: #e2e8f0;
  --app-border-strong: #cbd5e1;
  --app-text: #0f172a;
  --app-text-secondary: #475569;
  --app-muted: #64748b;

  /* Soft Semantic Tints */
  --tint-blue-bg: #eff6ff;
  --tint-blue-fg: #1d4ed8;
  --tint-emerald-bg: #ecfdf5;
  --tint-emerald-fg: #047857;
  --tint-amber-bg: #fffbeb;
  --tint-amber-fg: #b45309;
  --tint-rose-bg: #fff1f2;
  --tint-rose-fg: #be123c;
  --tint-cyan-bg: #ecfeff;
  --tint-cyan-fg: #0e7490;

  /* Layout & Touch Ergonomics */
  --sidebar-width: 17.25rem;
  --sidebar-collapsed-width: 4.85rem;
  --navbar-height: 4.25rem;
  --bottom-nav-height: 4.5rem;
  --target-size: 24px;
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -14px rgba(15, 23, 42, 0.12);
  --shadow-card-hover: 0 4px 12px rgba(15, 23, 42, 0.06), 0 14px 30px -12px rgba(15, 23, 42, 0.16);

  /* Align Bootstrap 5.3 Variables with Brand Tokens */
  --bs-primary: #0f3d75;
  --bs-primary-rgb: 15, 61, 117;
  --bs-link-color: #0f3d75;
  --bs-link-hover-color: #0a2d59;
  --bs-body-font-family: 'Noto Sans Thai', 'Sarabun', system-ui, -apple-system, sans-serif;
  --bs-body-color: var(--app-text);
  --bs-body-bg: var(--app-bg);
  --bs-border-color: var(--app-border);
  --bs-border-radius: 0.625rem;
  --bs-border-radius-lg: 1rem;
}

@media (pointer: coarse) {
  :root {
    --target-size: 44px;
  }
}

html {
  min-block-size: 100dvh;
  scroll-padding-top: calc(var(--navbar-height) + 1rem);
  scroll-padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 1rem);
}

body {
  margin: 0;
  min-block-size: 100dvh;
  background-color: var(--app-bg);
  color: var(--app-text);
  font-family: var(--bs-body-font-family);
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

img,
video {
  max-inline-size: 100%;
  block-size: auto;
}

:where(a, code) {
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  text-wrap: balance;
}

p,
li {
  text-wrap: pretty;
}

.tabular-nums,
table td.text-end,
.kpi-value {
  font-variant-numeric: tabular-nums;
}

/* Minimum touch target ergonomics */
:where(button, select, textarea, input:not([type="checkbox"], [type="radio"]), [role="button"], nav a) {
  min-block-size: var(--target-size);
}

/* Responsive fluid typography (max <= 2.5x min for WCAG 1.4.4) */
.app-page-title {
  font-size: clamp(1.125rem, 0.95rem + 0.85vw, 1.55rem);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--app-text);
  margin: 0;
}

/* Skip link for keyboard accessibility */
.skip-link {
  position: fixed;
  inset-block-start: -100%;
  inset-inline-start: 1rem;
  z-index: 2000;
  padding: 0.625rem 1rem;
  background: var(--app-primary);
  color: #fff;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus-visible {
  inset-block-start: 1rem;
}

/* ============================================================================
 * App Shell (Desktop: Collapsible Sidebar + Main | Mobile: Sticky Top + Bottom Nav)
 * ============================================================================ */
.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  min-block-size: 100dvh;
}

/* Frosted Glass Top Navbar */
.app-navbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 1020;
  min-block-size: var(--navbar-height);
  padding-block: 0.5rem;
  padding-inline: max(1rem, env(safe-area-inset-left, 0px)) max(1rem, env(safe-area-inset-right, 0px));
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-block-end: 1px solid var(--app-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.app-brand-mark {
  inline-size: 2.4rem;
  block-size: 2.4rem;
  border-radius: 0.7rem;
  background: linear-gradient(135deg, var(--app-accent) 0%, #b5821f 100%);
  color: #08203e;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 12px rgba(212, 163, 59, 0.3);
  flex-shrink: 0;
}

.user-avatar-chip {
  inline-size: 2rem;
  block-size: 2rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--app-primary) 0%, var(--app-primary-mid) 100%);
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.navbar-icon-btn {
  inline-size: 2.5rem;
  block-size: 2.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--app-border);
  background: var(--app-surface);
  color: var(--app-text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.navbar-icon-btn:hover:not(:disabled) {
  background: var(--tint-blue-bg);
  color: var(--app-primary);
  border-color: #bfdbfe;
}

/* Desktop Collapsible Sidebar */
.app-sidebar {
  display: none;
}

@media (min-width: 992px) {
  .app-shell {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    transition: grid-template-columns 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .app-shell.is-sidebar-collapsed {
    grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
  }

  .app-sidebar {
    position: sticky;
    inset-block-start: 0;
    block-size: 100dvh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--app-primary-dark) 0%, var(--app-primary) 65%, var(--app-primary-mid) 100%);
    color: #e2e8f0;
    border-inline-end: 1px solid rgba(255, 255, 255, 0.08);
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  }

  .app-shell.is-sidebar-collapsed .sidebar-label,
  .app-shell.is-sidebar-collapsed .nav-count-badge,
  .app-shell.is-sidebar-collapsed .sidebar-section-title,
  .app-shell.is-sidebar-collapsed .sidebar-brand-text,
  .app-shell.is-sidebar-collapsed .sidebar-user-card {
    display: none;
  }

  .app-shell.is-sidebar-collapsed .nav-link-item {
    justify-content: center;
    padding-inline: 0.75rem;
  }

  .app-navbar {
    padding-inline: 1.75rem;
  }
}

.sidebar-header {
  min-block-size: var(--navbar-height);
  padding-inline: 1.125rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-block-end: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.85);
  padding: 1.15rem 1.25rem 0.35rem;
}

.nav-menu-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.nav-link-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-md);
  color: #cbd5e1;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border-inline-start: 3px solid transparent;
  transition: background-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.nav-link-item i {
  font-size: 1.125rem;
  opacity: 0.88;
  flex-shrink: 0;
}

.nav-count-badge {
  margin-inline-start: auto;
  min-inline-size: 1.4rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(226, 232, 240, 0.8);
  flex-shrink: 0;
}

.nav-count-badge.is-active {
  background: #f59e0b;
  color: #0f172a;
}

/* Executive Budget Breakdown Bars & Sticky Report Table */
.budget-bar-track {
  inline-size: 100%;
  block-size: 0.42rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.budget-bar-fill {
  block-size: 100%;
  border-radius: 999px;
  transition: inline-size 0.3s ease;
}

/* Executive SVG Donut Chart */
.donut-chart-wrap {
  inline-size: 100%;
  max-inline-size: 220px;
  aspect-ratio: 1;
}

.donut-chart-svg {
  inline-size: 100%;
  block-size: 100%;
  filter: drop-shadow(0 6px 14px rgba(15, 23, 42, 0.08));
}

.donut-slice {
  transition: stroke-width 0.18s ease, opacity 0.18s ease;
  cursor: pointer;
}

.donut-slice:hover {
  stroke-width: 30;
  opacity: 0.92;
}

.donut-center-value {
  font-size: 2rem;
  font-weight: 800;
  fill: #0f172a;
  font-variant-numeric: tabular-nums;
}

.donut-center-label {
  font-size: 0.76rem;
  font-weight: 600;
  fill: #64748b;
}

.donut-legend-item {
  background: #ffffff;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.donut-legend-item:hover {
  background: #f8fafc;
  border-color: #cbd5e1 !important;
}

.donut-legend-dot {
  inline-size: 0.75rem;
  block-size: 0.75rem;
  border-radius: 999px;
}

/* Executive Vertical Bar Chart (Travel Purpose Types) */
.vbar-chart-scroll {
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.vbar-chart-stage {
  position: relative;
  min-inline-size: 34rem;
  padding-inline-start: 2.6rem;
  padding-block-start: 0.75rem;
}

.vbar-gridlines {
  position: absolute;
  inset-block-start: 0.75rem;
  inset-inline: 0;
  block-size: 13rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}

.vbar-gridline {
  position: relative;
  border-block-start: 1px dashed rgba(148, 163, 184, 0.35);
}

.vbar-gridline.is-base {
  border-block-start: 1.5px solid #cbd5e1;
}

.vbar-gridline span {
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: -0.6rem;
  inline-size: 2.1rem;
  text-align: end;
  font-size: 0.72rem;
  font-weight: 600;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}

.vbar-columns {
  position: relative;
  z-index: 1;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(6.5rem, 1fr);
  gap: 0.9rem;
  align-items: end;
}

.vbar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.25rem 0.35rem 0.45rem;
  border-radius: var(--radius-md);
  transition: background-color 0.16s ease, transform 0.16s ease;
}

.vbar-col:hover,
.vbar-col.is-selected {
  background: rgba(37, 99, 235, 0.05);
}

.vbar-col.is-selected {
  outline: 1.5px solid rgba(37, 99, 235, 0.35);
}

.vbar-plot-area {
  inline-size: 100%;
  block-size: 13rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
}

.vbar-value-pill {
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.vbar-pillar {
  inline-size: min(3.2rem, 68%);
  border-radius: 0.55rem 0.55rem 0.15rem 0.15rem;
  background: linear-gradient(180deg, var(--bar-color) 0%, color-mix(in srgb, var(--bar-color) 72%, #0f172a) 100%);
  box-shadow: 0 6px 14px -4px color-mix(in srgb, var(--bar-color) 45%, transparent);
  transition: transform 0.18s ease, filter 0.18s ease;
}

.vbar-pillar.is-zero {
  block-size: 4px !important;
  background: #e2e8f0;
  box-shadow: none;
}

.vbar-col:hover .vbar-pillar:not(.is-zero) {
  transform: translateY(-3px);
  filter: brightness(1.06);
}

.vbar-label {
  margin-block-start: 0.65rem;
  text-align: center;
  inline-size: 100%;
}

.vbar-label-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: #0f172a;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.vbar-label-sub {
  font-size: 0.7rem;
  color: #64748b;
  margin-block-start: 0.15rem;
}

.dashboard-report-table-wrap {
  max-block-size: min(560px, 75vh);
}

.dashboard-report-table {
  border-collapse: separate;
  border-spacing: 0;
}

.dashboard-report-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
}

@media (min-width: 768px) {
  .dashboard-report-table tbody th {
    position: sticky;
    inset-inline-start: 0;
    z-index: 1;
    background: var(--app-surface, #ffffff);
  }
}

@media print {
  .app-sidebar,
  .app-navbar,
  .mobile-bottom-nav {
    display: none !important;
  }

  .app-shell {
    display: block !important;
  }

  .app-content {
    padding: 0 !important;
  }
}

.nav-link-item:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
}

/* Current page indicator: gradient fill + gold border + bold (WCAG 1.4.1) */
.nav-link-item[aria-current="page"] {
  background: linear-gradient(90deg, rgba(212, 163, 59, 0.22) 0%, rgba(255, 255, 255, 0.08) 100%);
  color: #ffffff;
  font-weight: 700;
  border-inline-start-color: var(--app-accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.nav-link-item[aria-current="page"] i {
  color: var(--app-accent);
  opacity: 1;
}

.sidebar-user-card {
  margin: 0.75rem;
  padding: 0.85rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-link-item:focus-visible,
.mobile-bottom-nav-item:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--app-accent);
  outline-offset: 2px;
}

/* Main Content Area */
.app-main-column {
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
}

.app-content {
  flex: 1 1 auto;
  padding: 1rem;
  padding-block-end: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 1.5rem);
  container: main-content / inline-size;
  max-inline-size: 1600px;
  inline-size: 100%;
  margin-inline: auto;
}

@media (min-width: 992px) {
  .app-content {
    padding: 1.75rem 2rem 2.5rem;
  }
}

/* ============================================================================
 * Executive Hero Banner & Container-Driven KPI Cards
 * ============================================================================ */
.hero-banner {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  background: linear-gradient(125deg, var(--app-primary-dark) 0%, var(--app-primary) 55%, var(--app-primary-mid) 100%);
  color: #ffffff;
  box-shadow: 0 12px 32px -12px rgba(var(--bs-primary-rgb), 0.45);
}

.hero-banner::after {
  content: "";
  position: absolute;
  inset-block-start: -40%;
  inset-inline-end: -10%;
  inline-size: 20rem;
  block-size: 20rem;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(212, 163, 59, 0.25) 0%, transparent 70%);
  pointer-events: none;
}

@container main-content (min-width: 720px) {
  .hero-banner {
    padding: 1.75rem 2rem;
  }
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@container main-content (min-width: 520px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container main-content (min-width: 980px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.kpi-card {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

@media (hover: hover) {
  .kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-card-hover);
  }
}

.kpi-icon-tile {
  inline-size: 3rem;
  block-size: 3rem;
  border-radius: 0.875rem;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.kpi-icon-tile.is-blue { background: var(--tint-blue-bg); color: var(--tint-blue-fg); }
.kpi-icon-tile.is-amber { background: var(--tint-amber-bg); color: var(--tint-amber-fg); }
.kpi-icon-tile.is-rose { background: var(--tint-rose-bg); color: var(--tint-rose-fg); }
.kpi-icon-tile.is-emerald { background: var(--tint-emerald-bg); color: var(--tint-emerald-fg); }

.kpi-value {
  font-size: clamp(1.4rem, 1.2rem + 0.8vw, 1.85rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

/* ============================================================================
 * Modern Card, Button, Badge & Alert Refinements
 * ============================================================================ */
.card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--app-border) !important;
  box-shadow: var(--shadow-card) !important;
  overflow: hidden;
}

.card-header {
  background-color: var(--app-surface) !important;
  border-block-end: 1px solid var(--app-border);
  padding: 1rem 1.25rem;
}

.btn {
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.btn-primary {
  --bs-btn-bg: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary-hover);
  --bs-btn-hover-border-color: var(--app-primary-hover);
  --bs-btn-active-bg: var(--app-primary-dark);
  --bs-btn-active-border-color: var(--app-primary-dark);
  background-color: var(--app-primary);
  border-color: var(--app-primary);
  box-shadow: 0 2px 6px rgba(var(--bs-primary-rgb), 0.22);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--app-primary-hover);
  border-color: var(--app-primary-hover);
  box-shadow: 0 4px 12px rgba(var(--bs-primary-rgb), 0.28);
}

.btn-outline-primary {
  --bs-btn-color: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary);
  --bs-btn-hover-border-color: var(--app-primary);
  --bs-btn-active-bg: var(--app-primary-dark);
  --bs-btn-active-border-color: var(--app-primary-dark);
}

.badge {
  font-weight: 600;
  padding: 0.38em 0.7em;
  border-radius: 999px;
  letter-spacing: 0.01em;
}

.alert {
  border-radius: var(--radius-md);
  border-width: 1px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

/* Radio Option Cards powered natively by :has(:checked) */
.form-check.border.rounded {
  border-radius: var(--radius-md) !important;
  border: 1.5px solid var(--app-border) !important;
  background: var(--app-surface);
  transition: border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease;
  cursor: pointer;
}

.form-check.border.rounded:has(:checked) {
  border-color: var(--app-primary) !important;
  background: var(--tint-blue-bg);
  box-shadow: 0 0 0 3px rgba(15, 61, 117, 0.1);
}

/* ============================================================================
 * Accessible Form Controls & Validation (:user-invalid, iOS 16px zoom guard)
 * ============================================================================ */
input.form-control,
select.form-select,
textarea.form-control {
  font-size: max(1rem, 1em);
  min-block-size: 44px;
  border-color: var(--app-border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--app-surface);
}

input.form-control-sm,
select.form-select-sm {
  font-size: 0.9rem;
  min-block-size: 38px;
}

input.form-control:focus,
select.form-select:focus,
textarea.form-control:focus {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 3px rgba(15, 61, 117, 0.14);
}

.form-control:is(:user-invalid, .user-invalid-fallback),
.form-select:is(:user-invalid, .user-invalid-fallback) {
  border-color: #dc2626;
  background-color: #fef2f2;
}

.field-error-msg {
  display: none;
  color: #b91c1c;
  font-size: 0.82rem;
  font-weight: 500;
  margin-block-start: 0.3rem;
}

:is(:user-invalid, .user-invalid-fallback) + .field-error-msg {
  display: block;
}

.field-hint {
  display: block;
  color: var(--app-muted);
  font-size: 0.8rem;
  margin-block-end: 0.3rem;
}

/* ============================================================================
 * 4-Step Official Travel Workflow Progress Stepper
 * ============================================================================ */
.workflow-stepper-card {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow-card);
}

.workflow-stepper {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

@media (max-width: 767.98px) {
  .workflow-stepper {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.workflow-step {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--app-border);
  background: var(--app-surface-subtle);
  color: var(--app-muted);
  transition: border-color 0.16s ease, background-color 0.16s ease;
}

.workflow-step-badge {
  inline-size: 1.85rem;
  block-size: 1.85rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
  background: #e2e8f0;
  color: #475569;
}

.workflow-step-title {
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--app-text-secondary);
}

.workflow-step-desc {
  font-size: 0.75rem;
  line-height: 1.3;
  margin-block-start: 0.15rem;
}

.workflow-step.is-done {
  border-color: #86efac;
  background: #f0fdf4;
  color: #166534;
}

.workflow-step.is-done .workflow-step-badge {
  background: #16a34a;
  color: #fff;
}

.workflow-step.is-done .workflow-step-title {
  color: #14532d;
}

.workflow-step.is-active {
  border-color: var(--app-primary);
  background: var(--tint-blue-bg);
  color: var(--app-primary);
  box-shadow: 0 0 0 3px rgba(15, 61, 117, 0.1);
}

.workflow-step.is-active .workflow-step-badge {
  background: var(--app-primary);
  color: #fff;
}

.workflow-step.is-active .workflow-step-title {
  color: var(--app-primary);
}

.form-check-input {
  accent-color: var(--app-primary);
}

/* ============================================================================
 * Login Split-Screen Layout
 * ============================================================================ */
.auth-page {
  min-block-size: 100dvh;
  background: radial-gradient(circle at 15% 20%, var(--app-primary-mid) 0%, var(--app-primary) 48%, var(--app-primary-dark) 100%);
  display: grid;
  place-items: center;
  padding: max(0.85rem, env(safe-area-inset-top)) 0.85rem max(1.25rem, env(safe-area-inset-bottom));
}

@media (max-width: 899.98px) {
  .auth-page {
    align-content: start;
  }
}

.auth-shell {
  inline-size: min(60rem, 100%);
  background: var(--app-surface);
  border-radius: 1.35rem;
  overflow: hidden;
  box-shadow: 0 28px 60px -16px rgba(2, 6, 23, 0.55);
  display: grid;
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  .auth-shell {
    grid-template-columns: 1.05fr 1fr;
  }
}

.auth-showcase {
  background: linear-gradient(155deg, var(--app-primary-dark) 0%, var(--app-primary) 58%, var(--app-primary-mid) 100%);
  color: #f8fafc;
  padding: 1.35rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.auth-showcase::before {
  content: "";
  position: absolute;
  inset-block-end: -25%;
  inset-inline-end: -20%;
  inline-size: 22rem;
  block-size: 22rem;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(212, 163, 59, 0.24) 0%, transparent 70%);
}

.auth-features-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

@media (min-width: 480px) and (max-width: 899.98px) {
  .auth-features-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .auth-showcase {
    padding: 2.5rem;
  }
  .auth-features-grid {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }
}

.auth-feature-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.65rem 0.8rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.13);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

a.auth-feature-item:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.26);
}

.auth-form-pane {
  padding: 1.5rem 1.25rem 1.5rem;
}

@media (max-width: 899.98px) {
  .auth-form-pane .form-control {
    min-block-size: 2.75rem;
    font-size: 1rem;
  }
  .auth-form-pane .btn[type="submit"] {
    min-block-size: 2.85rem;
  }
}

@media (min-width: 576px) {
  .auth-form-pane {
    padding: 2.75rem;
  }
}

/* ============================================================================
 * Mobile Swipeable Navigation Drawer (Native <dialog> + Scroll-Snap)
 * ============================================================================ */
.Drawer {
  --drawer-width: min(20rem, 84dvw, 100dvw - 24px);
  --drawer-backdrop: 0;

  inset: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  overflow: visible;
}

.Drawer::backdrop {
  background: #020617;
  opacity: calc(var(--drawer-backdrop) * 0.6);
}

.Drawer-scroller {
  position: relative;
  display: grid;
  grid-template-columns: var(--drawer-width) 100%;
  overflow-x: scroll;
  overscroll-behavior: none;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
}

@media (prefers-reduced-motion: no-preference) {
  .Drawer-scroller {
    scroll-behavior: smooth;
  }
}

.Drawer-scroller::after {
  content: '';
  scroll-snap-align: end;
  scroll-initial-target: nearest;
}

.Drawer-sheet {
  display: flex;
  flex-direction: column;
  height: 100svh;
  background: linear-gradient(180deg, var(--app-primary-dark) 0%, var(--app-primary) 100%);
  color: #f8fafc;
  overflow-y: auto;
  scroll-snap-align: start;
  scrollbar-width: none;
}

@supports (animation-timeline: scroll()) {
  .Drawer {
    timeline-scope: --drawer-fade;
    animation: fade-drawer-backdrop linear both;
    animation-timeline: --drawer-fade;
  }

  .Drawer-scroller {
    scroll-timeline: --drawer-fade x;
  }

  @property --drawer-backdrop {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
  }

  @keyframes fade-drawer-backdrop {
    0% { --drawer-backdrop: 1; }
    100% { --drawer-backdrop: 0; }
  }
}

/* ============================================================================
 * Mobile Bottom Navigation Bar (< 992px)
 * ============================================================================ */
.mobile-bottom-nav {
  position: fixed;
  inset-block-end: 0;
  inset-inline: 0;
  z-index: 1030;
  min-block-size: var(--bottom-nav-height);
  padding-block-end: max(0.35rem, env(safe-area-inset-bottom, 0px));
  padding-inline: max(0.5rem, env(safe-area-inset-left, 0px)) max(0.5rem, env(safe-area-inset-right, 0px));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-block-start: 1px solid var(--app-border);
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

@media (min-width: 992px) {
  .mobile-bottom-nav {
    display: none;
  }
}

.mobile-bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding-block: 0.45rem;
  color: var(--app-muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
  background: transparent;
  border: 0;
  border-block-start: 2.5px solid transparent;
  transition: color 0.15s ease;
}

.mobile-bottom-nav-item[aria-current="page"] {
  color: var(--app-primary);
  font-weight: 700;
  border-block-start-color: var(--app-primary);
}

/* ============================================================================
 * Responsive Container-Driven Table (.table-wrapper + Sticky Headers)
 * ============================================================================ */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  container-type: inline-size;
}

.table > thead > tr > th {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--app-text-secondary);
  background-color: var(--app-surface-subtle);
  border-block-end: 1px solid var(--app-border);
  padding-block: 0.85rem;
  white-space: nowrap;
}

.table > tbody > tr > td,
.table > tbody > tr > th {
  padding-block: 0.8rem;
  border-color: #eef2f7;
}

.responsive-stacked-table {
  border-collapse: separate;
  border-spacing: 0;
}

.responsive-stacked-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
}

.responsive-stacked-table tbody th {
  position: sticky;
  inset-inline-start: 0;
  background: var(--app-surface);
}

@container (width < 620px) {
  .responsive-stacked-table,
  .responsive-stacked-table thead,
  .responsive-stacked-table tbody,
  .responsive-stacked-table tr,
  .responsive-stacked-table th,
  .responsive-stacked-table td {
    display: block;
    inline-size: 100%;
  }

  .responsive-stacked-table thead {
    display: none;
  }

  .responsive-stacked-table tr {
    margin: 0.75rem;
    inline-size: auto;
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--app-surface);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  }

  .responsive-stacked-table tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: var(--app-surface-subtle);
    border-block-end: 1px solid var(--app-border);
    padding: 0.75rem 0.9rem;
  }

  .responsive-stacked-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    text-align: end !important;
    padding: 0.6rem 0.9rem;
    border-block-end: 1px solid #f1f5f9;
  }

  .responsive-stacked-table td:last-child {
    border-block-end: 0;
  }

  .responsive-stacked-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--app-muted);
    text-align: start;
    flex-shrink: 0;
  }
}

/* ============================================================================
 * Native Modal Dialogs (.app-modal)
 * ============================================================================ */
dialog.app-modal {
  inline-size: min(42rem, 94dvw);
  max-block-size: 90dvh;
  padding: 0;
  border: 1px solid var(--app-border);
  border-radius: var(--radius-lg);
  background: var(--app-surface);
  color: var(--app-text);
  box-shadow: 0 24px 56px -12px rgba(15, 23, 42, 0.32);
  overflow: auto;
}

dialog.app-modal.app-modal-sm {
  inline-size: min(28rem, 92dvw);
}

dialog.app-modal:modal {
  overscroll-behavior: contain;
}

dialog.app-modal::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  overflow: hidden;
  overscroll-behavior: contain;
}

@media (forced-colors: active) {
  .nav-link-item[aria-current="page"],
  .mobile-bottom-nav-item[aria-current="page"] {
    outline: 2px solid Highlight;
  }
}

/* ============================================================================
 * Thai Buddhist Calendar Date-Time Picker (Popover API + Anchor Positioning)
 * ============================================================================ */
.thai-dt-field {
  position: relative;
}

.thai-dt-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  inline-size: 100%;
  min-block-size: 44px;
  padding: 0.5rem 0.85rem;
  font: inherit;
  font-size: max(1rem, 1em);
  color: var(--app-text);
  background-color: var(--app-surface);
  border: 1px solid var(--app-border-strong);
  border-radius: var(--radius-sm);
  text-align: start;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.thai-dt-trigger.form-control-sm {
  min-block-size: 31px;
  padding: 0.25rem 0.55rem;
  font-size: 0.875rem;
  line-height: 1.5;
}

@media (pointer: coarse) {
  .thai-dt-trigger {
    min-block-size: 48px;
  }
}

.thai-dt-trigger:hover {
  border-color: var(--app-primary);
  background-color: #fafcff;
}

.thai-dt-trigger:focus-visible {
  outline: 2px solid var(--app-primary);
  outline-offset: 2px;
  border-color: var(--app-primary);
}

.thai-dt-trigger-main {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-inline-size: 0;
  flex: 1;
}

.thai-dt-trigger-date {
  font-weight: 600;
  color: var(--app-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thai-dt-trigger-time {
  flex-shrink: 0;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  background: var(--tint-blue-bg);
  color: var(--app-primary);
  font-variant-numeric: tabular-nums;
}

[popover].thai-cal-popover:is(:popover-open, .\:popover-open) {
  display: block;
}

[popover].thai-cal-popover.is-fallback-open {
  display: block;
  position: absolute;
  inset-block-start: calc(100% + 0.35rem);
  inset-inline-start: 0;
  z-index: 1080;
}

[popover].thai-cal-popover {
  inline-size: min(21.5rem, 94dvw);
  padding: 0.9rem;
  border: 1px solid var(--app-border-strong);
  border-radius: var(--radius-lg);
  background: var(--app-surface);
  color: var(--app-text);
  box-shadow: 0 20px 44px -12px rgba(15, 23, 42, 0.28), 0 4px 12px rgba(15, 23, 42, 0.08);
  overflow: visible;
}

@supports (position-area: block-end) {
  [popover].thai-cal-popover {
    inset: auto;
    margin: 0.35rem 0 0 0;
    position-area: block-end span-inline-end;
    position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
  }
}

.thai-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin-block-end: 0.65rem;
}

.thai-cal-nav-btn {
  inline-size: 2.15rem;
  block-size: 2.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--app-border);
  border-radius: var(--radius-sm);
  background: var(--app-surface-subtle);
  color: var(--app-text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.14s ease, border-color 0.14s ease;
}

.thai-cal-nav-btn:hover {
  background: var(--tint-blue-bg);
  border-color: var(--app-primary);
  color: var(--app-primary);
}

.thai-cal-selects {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 1;
  min-inline-size: 0;
}

.thai-cal-select {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.3rem 0.45rem;
  min-block-size: 2.15rem;
  border: 1px solid var(--app-border-strong);
  border-radius: var(--radius-sm);
  background: var(--app-surface);
  color: var(--app-text);
  cursor: pointer;
}

.thai-cal-select.is-month {
  flex: 1.25;
  min-inline-size: 0;
}

.thai-cal-select.is-year {
  flex: 1;
  min-inline-size: 0;
}

.thai-cal-weekdays,
.thai-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.2rem;
}

.thai-cal-weekdays {
  margin-block-end: 0.3rem;
}

.thai-cal-weekday {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--app-muted);
  padding-block: 0.2rem;
}

.thai-cal-weekday.is-sun {
  color: #dc2626;
}

.thai-cal-weekday.is-sat {
  color: #4f46e5;
}

.thai-cal-day {
  block-size: 2.3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--app-text);
  font-size: 0.9rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.thai-cal-day.is-sun {
  color: #b91c1c;
}

.thai-cal-day.is-sat {
  color: #4338ca;
}

.thai-cal-day:hover {
  background: var(--tint-blue-bg);
  color: var(--app-primary);
}

.thai-cal-day:focus-visible {
  outline: 2px solid var(--app-primary);
  outline-offset: 1px;
}

.thai-cal-day.is-today {
  border-color: var(--app-gold, #d4a33b);
  font-weight: 700;
}

.thai-cal-day.is-selected {
  background: var(--app-primary);
  border-color: var(--app-primary);
  color: #fff;
  font-weight: 700;
}

.thai-cal-time-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-block-start: 0.75rem;
  padding-block-start: 0.65rem;
  border-block-start: 1px solid var(--app-border);
}

.thai-cal-time-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.thai-cal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-block-start: 0.65rem;
  padding-block-start: 0.55rem;
  border-block-start: 1px solid var(--app-border);
}

/* ============================================================================
 * Travel Request Detail Page (views/travel/show.php)
 * ============================================================================ */
.detail-hero-card {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-top: 3px solid var(--app-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.25rem 1.5rem;
}

.detail-hero-title {
  font-size: clamp(1.05rem, 0.96rem + 0.45vw, 1.3rem);
  font-weight: 700;
  line-height: 1.45;
  color: var(--app-text);
  margin: 0.5rem 0 0.75rem;
  text-wrap: balance;
}

.detail-meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  font-size: 0.875rem;
  color: var(--app-text-secondary);
}

.detail-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.detail-meta-item i {
  color: var(--app-primary);
  font-size: 0.95rem;
}

.detail-action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--app-border);
}

.detail-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 0.875rem;
}

.detail-kpi-card {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--radius-md);
  padding: 0.95rem 1.1rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.detail-kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--app-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.detail-kpi-value {
  font-size: clamp(1.05rem, 0.95rem + 0.4vw, 1.32rem);
  font-weight: 700;
  color: var(--app-text);
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.detail-kpi-sub {
  font-size: 0.78rem;
  color: var(--app-muted);
}

.detail-section-card {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.detail-section-header {
  padding: 0.95rem 1.25rem;
  background: var(--app-surface-subtle);
  border-bottom: 1px solid var(--app-border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.detail-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--app-text);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.detail-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem 1.5rem;
}

.detail-info-item.is-full {
  grid-column: 1 / -1;
}

.detail-info-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--app-muted);
  margin-bottom: 0.2rem;
}

.detail-info-value {
  font-size: 0.9375rem;
  color: var(--app-text);
  line-height: 1.5;
}

.detail-doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.5rem 1rem;
  margin-top: 1.1rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-md);
  background: var(--app-surface-subtle);
  border: 1px solid var(--app-border);
}

.detail-doc-item {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--app-text-secondary);
}

.detail-seq-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.65rem;
  height: 1.65rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--tint-blue-bg);
  color: var(--tint-blue-fg);
  font-variant-numeric: tabular-nums;
}

.detail-seq-badge.is-student {
  background: var(--tint-cyan-bg);
  color: var(--tint-cyan-fg);
}

.detail-table {
  font-size: 0.9rem;
}

.detail-table thead th {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--app-muted);
  background: var(--app-surface-subtle);
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--app-border);
  white-space: nowrap;
}

.detail-table tbody th,
.detail-table tbody td {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--app-border);
}

.detail-table tfoot td {
  padding: 0.75rem 0.9rem;
  background: var(--app-surface-subtle);
  font-size: 0.9rem;
}

.detail-timeline {
  list-style: none;
  padding: 0;
  margin: 0;
  position: relative;
}

.detail-timeline::before {
  content: "";
  position: absolute;
  inset-inline-start: 0.45rem;
  inset-block-start: 0.35rem;
  inset-block-end: 0.35rem;
  width: 2px;
  background: var(--app-border);
}

.detail-timeline-item {
  position: relative;
  padding-inline-start: 1.65rem;
  padding-block-end: 1rem;
}

.detail-timeline-item:last-child {
  padding-block-end: 0;
}

.detail-timeline-dot {
  position: absolute;
  inset-inline-start: 0.14rem;
  inset-block-start: 0.3rem;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--app-primary);
  border: 2px solid var(--app-surface);
  box-shadow: 0 0 0 2px var(--tint-blue-bg);
}

.detail-file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--app-surface-subtle);
  border: 1px solid var(--app-border);
  font-size: 0.85rem;
}

/* ============================================================================
 * Multi-Theme Palette Overrides (Admin Theme Settings)
 * ============================================================================ */
html[data-theme="emerald-gov"] {
  --app-primary: #065f46;
  --app-primary-hover: #044e39;
  --app-primary-dark: #022c22;
  --app-primary-mid: #047857;
  --app-accent: #d97706;
  --app-accent-soft: #fffbeb;
  --app-bg: #f2f8f5;
  --bs-primary: #065f46;
  --bs-primary-rgb: 6, 95, 70;
  --bs-link-color: #065f46;
  --bs-link-hover-color: #044e39;
}

html[data-theme="royal-indigo"] {
  --app-primary: #3730a3;
  --app-primary-hover: #2e288a;
  --app-primary-dark: #1e1b4b;
  --app-primary-mid: #4338ca;
  --app-accent: #0ea5e9;
  --app-accent-soft: #f0f9ff;
  --app-bg: #f4f5fc;
  --bs-primary: #3730a3;
  --bs-primary-rgb: 55, 48, 163;
  --bs-link-color: #3730a3;
  --bs-link-hover-color: #2e288a;
}

html[data-theme="crimson-classic"] {
  --app-primary: #881337;
  --app-primary-hover: #70102d;
  --app-primary-dark: #4c0519;
  --app-primary-mid: #9f1239;
  --app-accent: #ca8a04;
  --app-accent-soft: #fefce8;
  --app-bg: #faf5f6;
  --bs-primary: #881337;
  --bs-primary-rgb: 136, 19, 55;
  --bs-link-color: #881337;
  --bs-link-hover-color: #70102d;
}

html[data-theme="ocean-teal"] {
  --app-primary: #0f766e;
  --app-primary-hover: #115e59;
  --app-primary-dark: #042f2e;
  --app-primary-mid: #0d9488;
  --app-accent: #f59e0b;
  --app-accent-soft: #fffbeb;
  --app-bg: #f2f9f8;
  --bs-primary: #0f766e;
  --bs-primary-rgb: 15, 118, 110;
  --bs-link-color: #0f766e;
  --bs-link-hover-color: #115e59;
}

html[data-theme="obsidian-pro"] {
  --app-primary: #1e293b;
  --app-primary-hover: #0f172a;
  --app-primary-dark: #0f172a;
  --app-primary-mid: #334155;
  --app-accent: #3b82f6;
  --app-accent-soft: #eff6ff;
  --app-bg: #f4f6f8;
  --bs-primary: #1e293b;
  --bs-primary-rgb: 30, 41, 59;
  --bs-link-color: #1e293b;
  --bs-link-hover-color: #0f172a;
}

/* Theme Picker Cards */
.theme-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.theme-choice-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--app-border);
  border-radius: var(--radius-md);
  background: var(--app-surface);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.theme-choice-card:hover {
  border-color: var(--app-border-strong);
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
}

.theme-choice-card.is-selected {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 4px rgba(var(--bs-primary-rgb), 0.18), 0 14px 28px -12px rgba(var(--bs-primary-rgb), 0.36);
  transform: translateY(-2px);
}

.theme-choice-card:focus-within {
  outline: 2px solid var(--app-primary);
  outline-offset: 2px;
}

.theme-choice-radio {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-preview-check {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 2;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 999px;
  background: var(--app-primary);
  color: #ffffff;
  border: 2.5px solid #ffffff;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  opacity: 0;
  transform: scale(0.65);
  transition: opacity 0.18s ease, transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.theme-choice-card.is-selected .theme-preview-check {
  opacity: 1;
  transform: scale(1);
}

.theme-selected-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  background: var(--app-primary);
  color: #ffffff;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.16s ease, transform 0.16s ease, background-color 0.16s ease;
}

.theme-choice-card.is-selected .theme-selected-indicator {
  opacity: 1;
  transform: translateY(0);
}

.theme-live-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  color: var(--app-text-secondary);
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.theme-live-status.is-unsaved {
  background: var(--tint-amber-bg);
  border-color: #fcd34d;
  color: var(--tint-amber-fg);
}

.theme-live-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

/* Native Modal Dialog Scroll Containment */
dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

/* Sidebar Logout Button */
.nav-link-item.is-logout {
  background: transparent;
  color: #fecdd3;
}

.nav-link-item.is-logout:hover {
  background: rgba(244, 63, 94, 0.2);
  color: #ffffff;
}

.theme-preview-frame {
  display: flex;
  height: 92px;
  border-bottom: 1px solid var(--app-border);
  overflow: hidden;
}

.theme-preview-sidebar {
  width: 30%;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.theme-preview-dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: block;
}

.theme-preview-line {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  width: 85%;
}

.theme-preview-line.is-short {
  width: 55%;
}

.theme-preview-body {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.theme-preview-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.theme-preview-pill {
  height: 9px;
  width: 48%;
  border-radius: 999px;
  display: inline-block;
}

.theme-preview-pill.is-accent {
  width: 24%;
}

.theme-preview-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  flex: 1;
}

.theme-preview-cards > span {
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 6px;
}

.theme-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.15);
  display: inline-block;
}

/* =====================================================================
   Dashboard Official Travel Calendar & Gantt Timeline (.tcal-*)
   ===================================================================== */
.tcal-card {
  overflow: hidden;
  border-radius: var(--app-radius, 1rem);
}

.tcal-header {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  padding: 1rem 1.25rem;
}

.tcal-heading-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.6rem;
  background: color-mix(in srgb, var(--app-primary, #0b294f) 11%, transparent);
  color: var(--app-primary, #0b294f);
  font-size: 1rem;
}

.tcal-nav-group {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.tcal-month-select {
  inline-size: auto;
  min-inline-size: 10.5rem;
  font-weight: 600;
}

.tcal-filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.28rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.tcal-filter-pill:hover {
  border-color: var(--app-primary, #0b294f);
  color: var(--app-primary, #0b294f);
}

.tcal-filter-pill.is-active {
  background: var(--app-primary, #0b294f);
  border-color: var(--app-primary, #0b294f);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.14);
}

.tcal-filter-pill.is-active .tcal-dot {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.65);
}

.tcal-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.tcal-dot.is-step-1 { background: #2563eb; }
.tcal-dot.is-step-2 { background: #059669; }
.tcal-dot.is-step-3 { background: #d97706; }
.tcal-dot.is-step-4 { background: #0f766e; }

/* Month Calendar Grid */
.tcal-month-view {
  overflow-x: auto;
  background: #ffffff;
}

.tcal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.tcal-weekday {
  padding: 0.55rem 0.65rem;
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
  color: #475569;
  letter-spacing: 0.01em;
}

.tcal-weekday.is-weekend {
  color: #dc2626;
}

.tcal-week-row {
  position: relative;
  border-bottom: 1px solid #e2e8f0;
}

.tcal-week-row:last-child {
  border-bottom: 0;
}

.tcal-week-cells {
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  min-height: 7.4rem;
}

.tcal-day-cell {
  border-right: 1px solid #f1f5f9;
  padding: 0.4rem 0.45rem 0.45rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #ffffff;
  transition: background-color 0.15s ease;
}

.tcal-day-cell:last-child {
  border-right: 0;
}

.tcal-day-cell.is-weekend {
  background: #fafbfe;
}

.tcal-day-cell.is-outside {
  background: #f8fafc;
}

.tcal-day-cell.is-outside .tcal-day-num {
  color: #94a3b8;
  font-weight: 500;
}

.tcal-day-cell.is-today {
  background: color-mix(in srgb, var(--app-primary, #0b294f) 5%, #ffffff);
}

.tcal-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.tcal-day-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.65rem;
  height: 1.65rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #1e293b;
  font-variant-numeric: tabular-nums;
}

.tcal-day-cell.is-today .tcal-day-num {
  background: var(--app-primary, #0b294f);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.22);
}

.tcal-more-btn {
  align-self: flex-start;
  margin-top: auto;
  padding: 0.1rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--app-primary, #0b294f);
  background: color-mix(in srgb, var(--app-primary, #0b294f) 10%, #ffffff);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  position: relative;
  z-index: 3;
}

.tcal-more-btn:hover {
  background: var(--app-primary, #0b294f);
  color: #ffffff;
}

/* Multi-day spanning bars overlay inside each week row */
.tcal-week-events {
  position: absolute;
  inset: 2.15rem 0 0.3rem 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  grid-auto-rows: 1.5rem;
  row-gap: 0.22rem;
  pointer-events: none;
  z-index: 2;
}

.tcal-event-bar {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0.22rem;
  padding: 0 0.5rem;
  height: 1.48rem;
  border: 1px solid transparent;
  border-left-width: 3px;
  border-radius: 0.38rem;
  font-size: 0.74rem;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.tcal-event-bar:hover,
.tcal-event-bar:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.14);
  z-index: 5;
  outline: 2px solid var(--app-primary, #0b294f);
  outline-offset: 1px;
}

.tcal-event-bar.is-cont-left {
  margin-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left-width: 1px;
}

.tcal-event-bar.is-cont-right {
  margin-right: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.tcal-event-bar.is-step-1,
.tcal-gantt-bar.is-step-1 {
  background: #eff6ff;
  border-color: #bfdbfe;
  border-left-color: #2563eb;
  color: #1e40af;
}

.tcal-event-bar.is-step-2,
.tcal-gantt-bar.is-step-2 {
  background: #ecfdf5;
  border-color: #a7f3d0;
  border-left-color: #059669;
  color: #065f46;
}

.tcal-event-bar.is-step-3,
.tcal-gantt-bar.is-step-3 {
  background: #fffbeb;
  border-color: #fde68a;
  border-left-color: #d97706;
  color: #92400e;
}

.tcal-event-bar.is-step-4,
.tcal-gantt-bar.is-step-4 {
  background: #f0fdfa;
  border-color: #99f6e4;
  border-left-color: #0f766e;
  color: #115e59;
}

.tcal-event-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tcal-event-meta {
  font-weight: 500;
  opacity: 0.78;
  flex-shrink: 0;
  font-size: 0.7rem;
}

/* Gantt Timeline View */
.tcal-timeline-view {
  overflow-x: auto;
  background: #ffffff;
}

.tcal-gantt-grid {
  min-width: 920px;
}

.tcal-gantt-head,
.tcal-gantt-row {
  display: grid;
  grid-template-columns: 240px repeat(var(--tcal-days, 30), minmax(26px, 1fr));
  align-items: stretch;
  border-bottom: 1px solid #e2e8f0;
}

.tcal-gantt-head {
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 4;
}

.tcal-gantt-label-col {
  position: sticky;
  left: 0;
  z-index: 3;
  background: inherit;
  border-right: 1px solid #e2e8f0;
  padding: 0.55rem 0.85rem;
  min-width: 0;
}

.tcal-gantt-row {
  background: #ffffff;
  transition: background-color 0.14s ease;
}

.tcal-gantt-row:hover {
  background: #f8fafc;
}

.tcal-gantt-row:last-child {
  border-bottom: 0;
}

.tcal-gantt-day-head {
  text-align: center;
  padding: 0.4rem 0.1rem;
  font-size: 0.7rem;
  border-right: 1px solid #f1f5f9;
  color: #475569;
  font-variant-numeric: tabular-nums;
}

.tcal-gantt-day-head.is-weekend {
  background: #fef2f2;
  color: #dc2626;
}

.tcal-gantt-day-head.is-today {
  background: var(--app-primary, #0b294f);
  color: #ffffff;
  font-weight: 700;
}

.tcal-gantt-dow {
  display: block;
  font-size: 0.62rem;
  opacity: 0.78;
}

.tcal-gantt-track {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: repeat(var(--tcal-days, 30), minmax(26px, 1fr));
  align-items: center;
  position: relative;
  min-height: 3.15rem;
  background-image: linear-gradient(to right, #f1f5f9 1px, transparent 1px);
  background-size: calc(100% / var(--tcal-days, 30)) 100%;
}

.tcal-gantt-bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin: 0 2px;
  padding: 0.25rem 0.55rem;
  height: 1.95rem;
  border: 1px solid transparent;
  border-left-width: 4px;
  border-radius: 0.45rem;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.tcal-gantt-bar:hover,
.tcal-gantt-bar:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
  outline: 2px solid var(--app-primary, #0b294f);
  outline-offset: 1px;
}

.tcal-gantt-today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: color-mix(in srgb, var(--app-primary, #0b294f) 55%, transparent);
  pointer-events: none;
  z-index: 1;
}

/* Detail Dialog */
dialog.tcal-dialog:modal {
  max-width: 36rem;
  width: calc(100% - 2rem);
  overscroll-behavior: contain;
}

dialog.tcal-dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

.tcal-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.tcal-detail-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 0.65rem;
  padding: 0.65rem 0.8rem;
}

.tcal-detail-box.is-full {
  grid-column: 1 / -1;
}

.tcal-detail-label {
  font-size: 0.73rem;
  color: #64748b;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.tcal-detail-value {
  font-size: 0.88rem;
  color: #0f172a;
  font-weight: 600;
}

.tcal-agenda-item {
  width: 100%;
  text-align: left;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-left-width: 4px;
  border-radius: 0.65rem;
  padding: 0.7rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, transform 0.12s ease;
}

.tcal-agenda-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.tcal-agenda-item.is-step-1 { border-left-color: #2563eb; }
.tcal-agenda-item.is-step-2 { border-left-color: #059669; }
.tcal-agenda-item.is-step-3 { border-left-color: #d97706; }
.tcal-agenda-item.is-step-4 { border-left-color: #0f766e; }

@media (max-width: 575.98px) {
  .tcal-detail-grid {
    grid-template-columns: 1fr;
  }
  .tcal-gantt-head,
  .tcal-gantt-row {
    grid-template-columns: 180px repeat(var(--tcal-days, 30), minmax(24px, 1fr));
  }
}

/* =====================================================================
   User Profile Avatar Upload & Camera Capture (.user-avatar-img, .avatar-*)
   ===================================================================== */
.user-avatar-chip {
  overflow: hidden;
  padding: 0;
}

.user-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
}

.avatar-upload-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 0.85rem;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
}

.avatar-preview-lg {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 50%;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--app-primary, #0b294f), var(--app-primary-mid, #1d4ed8));
  color: #ffffff;
  font-size: 1.65rem;
  font-weight: 700;
  border: 3px solid #ffffff;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.14);
}

.avatar-camera-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 320px;
  margin-inline: auto;
  border-radius: 0.85rem;
  overflow: hidden;
  background: #0f172a;
}

.avatar-camera-stage video,
.avatar-camera-stage img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-camera-guide {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.72);
  box-shadow: 0 0 0 999px rgba(15, 23, 42, 0.35);
  pointer-events: none;
}

/* =====================================================================
   User Manual Infographic Frame (.manual-infographic-*)
   ===================================================================== */
.manual-infographic-frame {
  margin: 0;
  padding: 0.75rem;
  border-radius: 1rem;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05);
}

.manual-infographic-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 0.65rem;
}

.manual-infographic-caption {
  margin-top: 0.6rem;
  font-size: 0.78rem;
  color: #64748b;
  text-align: center;
}

/* =====================================================================
   Official Vehicle Fleet Statistics & Live Status (.vstat-*)
   ===================================================================== */
.vstat-kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1rem;
}

@media (max-width: 1279.98px) {
  .vstat-kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 767.98px) {
  .vstat-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 479.98px) {
  .vstat-kpi-grid {
    grid-template-columns: 1fr;
  }
}

.vstat-vehicle-card {
  border-radius: 1rem;
  border-top: 4px solid #cbd5e1 !important;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.vstat-vehicle-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08) !important;
}

.vstat-vehicle-card.is-available { border-top-color: #10b981 !important; }
.vstat-vehicle-card.is-busy { border-top-color: #ef4444 !important; }
.vstat-vehicle-card.is-maint { border-top-color: #f59e0b !important; }
.vstat-vehicle-card.is-retired { border-top-color: #64748b !important; }

.vstat-code-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.35rem;
  height: 2.35rem;
  padding: 0 0.45rem;
  border-radius: 0.65rem;
  border: 1px solid transparent;
  font-weight: 800;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.vstat-pulse-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  display: inline-block;
}

.vstat-free-badge {
  grid-column: 1 / -1;
  justify-self: center;
  font-size: 0.74rem;
  font-weight: 600;
  color: #059669;
  background: #ecfdf5;
  border: 1px dashed #a7f3d0;
  border-radius: 999px;
  padding: 0.18rem 0.75rem;
}


/* ==========================================================================
   AI PDF Processing & Confirmation Modal (Native <dialog>)
   ========================================================================== */
dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

.aip-dialog {
  width: min(680px, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 0;
  border-radius: 1.25rem;
  background: transparent;
  box-shadow: 0 28px 64px -16px rgba(15, 23, 42, 0.38);
  overflow: visible;
}

.aip-dialog::backdrop {
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.aip-dialog[open] {
  display: flex;
  flex-direction: column;
  animation: aipPopIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes aipPopIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.aip-shell {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 2rem);
  background: #ffffff;
  border-radius: 1.25rem;
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.aip-header {
  padding: 1.25rem 1.5rem 1rem;
  color: #ffffff;
  position: relative;
  transition: background 0.3s ease;
}

.aip-header.is-loading {
  background: linear-gradient(135deg, #1d4ed8 0%, #4338ca 55%, #6366f1 100%);
}

.aip-header.is-success {
  background: linear-gradient(135deg, #047857 0%, #059669 55%, #10b981 100%);
}

.aip-header.is-error {
  background: linear-gradient(135deg, #b91c1c 0%, #dc2626 55%, #ef4444 100%);
}

.aip-header-main {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.aip-emblem {
  width: 2.85rem;
  height: 2.85rem;
  flex-shrink: 0;
  border-radius: 0.85rem;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}

.aip-header.is-loading .aip-emblem {
  animation: aipPulse 1.6s ease-in-out infinite;
}

@keyframes aipPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.35); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(255, 255, 255, 0); }
}

.aip-title {
  font-size: 1.08rem;
  font-weight: 700;
  margin: 0 0 0.15rem;
  line-height: 1.3;
  color: #ffffff;
}

.aip-subtitle {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.86);
}

.aip-header-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.aip-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 0.76rem;
  max-width: 72%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.aip-timer {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.24);
}

.aip-progress-track {
  margin-top: 0.75rem;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.aip-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: #ffffff;
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.aip-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.aip-stepper {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.aip-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  transition: all 0.22s ease;
}

.aip-step-icon {
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  border-radius: 999px;
  background: #e2e8f0;
  color: #64748b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.aip-step-title {
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.25;
}

.aip-step-desc {
  font-size: 0.74rem;
  opacity: 0.85;
}

.aip-step.is-active {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1e3a8a;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
}

.aip-step.is-active .aip-step-icon {
  background: #2563eb;
  color: #ffffff;
}

.aip-step.is-done {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: #065f46;
}

.aip-step.is-done .aip-step-icon {
  background: #10b981;
  color: #ffffff;
}

.aip-step.is-error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.aip-step.is-error .aip-step-icon {
  background: #ef4444;
  color: #ffffff;
}

.aip-stepper.is-compact {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.aip-stepper.is-compact .aip-step {
  flex-direction: column;
  text-align: center;
  padding: 0.45rem 0.35rem;
  gap: 0.3rem;
}

.aip-stepper.is-compact .aip-step-icon {
  width: 1.55rem;
  height: 1.55rem;
  font-size: 0.76rem;
}

.aip-stepper.is-compact .aip-step-title {
  font-size: 0.7rem;
}

.aip-stepper.is-compact .aip-step-desc {
  display: none;
}

.aip-engine-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  margin-bottom: 0.85rem;
  font-size: 0.78rem;
}

.aip-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.aip-preview-item {
  padding: 0.65rem 0.85rem;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  background: #ffffff;
}

.aip-preview-item.aip-span-2 {
  grid-column: 1 / -1;
}

.aip-preview-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 0.2rem;
}

.aip-preview-val {
  font-size: 0.86rem;
  font-weight: 600;
  color: #0f172a;
  word-break: break-word;
}

.aip-people-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.aip-person-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.aip-person-chip.is-student {
  background: #ecfeff;
  color: #0e7490;
  border-color: #a5f3fc;
}

.aip-error-box {
  padding: 0.9rem 1rem;
  border-radius: 0.85rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  margin-bottom: 0.85rem;
}

.aip-error-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #b91c1c;
  margin-bottom: 0.3rem;
}

.aip-error-msg {
  font-size: 0.82rem;
  color: #7f1d1d;
  word-break: break-word;
}

.aip-error-question {
  padding: 0.8rem 1rem;
  border-radius: 0.85rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-size: 0.84rem;
  color: #334155;
}

.aip-footer {
  padding: 0.9rem 1.5rem;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
}

.aip-footer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.aip-footer-row[hidden] {
  display: none !important;
}

@media (max-width: 576px) {
  .aip-header,
  .aip-body,
  .aip-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .aip-preview-grid {
    grid-template-columns: 1fr;
  }
  .aip-stepper.is-compact {
    grid-template-columns: repeat(2, 1fr);
  }
}
