/* ==========================================================================
   JIOCHAEL EdOS — Master Stylesheet
   Theme: Ink & Laurel
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --ink-900: #0B1F3A; --ink-800: #12294A; --ink-700: #1E3A5F;
  --ink-600: #2B4A72; --ink-500: #3B5F87; --ink-300: #94A9C2;
  --ink-200: #C7D3E0; --ink-100: #E4EAF1;
  --laurel-700: #0A3A24; --laurel-600: #0F5132; --laurel-500: #1A7F4E;
  --laurel-400: #34A76A; --laurel-200: #B7E0C7; --laurel-100: #DCF2E5;
  --brass-700: #6E5215; --brass-600: #8C6A1F; --brass-500: #A9832A;
  --brass-400: #C9A24A; --brass-300: #DEC27F; --brass-200: #EEDCB0;
  --brass-100: #F5EBD1; --brass-50:  #FAF5E7;
  --paper: #FBF9F4; --paper-alt: #F4F1E9; --paper-raised: #FFFFFF;
  --paper-line: #E8E3D5; --paper-line-2: #D9D3C0;
  --success: #0F5132; --success-bg: #DCF2E5;
  --warning: #B45309; --warning-bg: #FEF3C7;
  --danger: #A41E22; --danger-bg: #FBE9EA;
  --info: #1E3A5F; --info-bg: #E4EAF1;
  --header-h: 60px; --sidebar-w: 248px; --footer-h: 44px;
  --r-xs: 4px; --r-sm: 6px; --r-md: 8px; --r-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(11,31,58,.05);
  --shadow-md: 0 2px 8px rgba(11,31,58,.06), 0 1px 2px rgba(11,31,58,.04);
  --shadow-lg: 0 12px 32px rgba(11,31,58,.10), 0 2px 6px rgba(11,31,58,.04);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: 'Fraunces', "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow-x: hidden; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, svg, video { max-width: 100%; height: auto; }
body {
  font-family: var(--font-sans);
  font-size: 14.5px; line-height: 1.55;
  color: var(--ink-900); background: var(--paper);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
  word-wrap: break-word;
}
h1, h2, h3, h4 {
  font-family: var(--font-serif); font-weight: 600;
  color: var(--ink-900); letter-spacing: -0.01em; margin: 0;
}
a { color: var(--laurel-600); text-decoration: none; }
a:hover { color: var(--laurel-700); text-decoration: underline; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; max-width: 100%; }
::selection { background: var(--brass-200); color: var(--ink-900); }

/* ---------- Shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr var(--footer-h);
  grid-template-areas: "header header" "sidebar main" "footer footer";
  height: 100vh;
  height: 100dvh;
  max-width: 100vw;
  overflow: hidden;
}
.app-header { grid-area: header; }
.app-sidebar { grid-area: sidebar; min-height: 0; }
.app-main    { grid-area: main;    min-height: 0; overflow-y: auto; overflow-x: hidden; }
.app-footer  { grid-area: footer; }

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "header" "main" "footer";
  }
  .app-sidebar {
    position: fixed; top: var(--header-h); left: 0; width: 272px;
    height: calc(100vh - var(--header-h) - var(--footer-h));
    height: calc(100dvh - var(--header-h) - var(--footer-h));
    transform: translateX(-100%);
    transition: transform .24s cubic-bezier(.4,0,.2,1);
    z-index: 60;
    box-shadow: 0 20px 60px rgba(11,31,58,.24);
    overflow-y: auto;
  }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open::after {
    content: ''; position: fixed; inset: 0; top: var(--header-h);
    background: rgba(11,31,58,.42); z-index: 55;
  }
}

/* ---------- Header ---------- */
.app-header {
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; background: var(--ink-900); color: #fff;
  position: relative; z-index: 70;
  min-width: 0;
}
.app-header::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--brass-400) 0%, var(--brass-600) 40%, transparent 100%);
}
.sidebar-toggle {
  display: none; width: 36px; height: 36px; border: none;
  background: transparent; flex-direction: column;
  justify-content: center; gap: 5px; padding: 6px;
  border-radius: var(--r-sm); flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.08); }
.sidebar-toggle span { display: block; height: 1.5px; background: #fff; border-radius: 2px; }

.brand {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: #fff;
  min-width: 0;
}
.brand:hover { text-decoration: none; }
.brand-seal {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--brass-400) 0%, var(--brass-600) 100%);
  color: var(--ink-900); border-radius: 8px;
  font-family: var(--font-serif); font-weight: 700; font-size: 17px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name {
  font-family: var(--font-serif); font-weight: 600; font-size: 15px; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-tag { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--brass-300); font-weight: 500; }

.header-search { position: relative; flex: 1; max-width: 420px; margin: 0 12px; min-width: 0; }
.header-search input {
  width: 100%; padding: 8px 12px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--r-md); color: #fff; font-size: 13.5px;
  transition: background .15s, border-color .15s;
}
.header-search input::placeholder { color: rgba(255,255,255,.55); }
.header-search input:focus {
  outline: none; background: rgba(255,255,255,.14); border-color: var(--brass-400);
}

.header-right {
  margin-left: auto; display: flex; align-items: center; gap: 14px;
  min-width: 0; flex-shrink: 0;
}
.institution-name {
  font-size: 12.5px; color: var(--brass-300);
  padding-right: 14px; border-right: 1px solid rgba(255,255,255,.14);
  letter-spacing: .02em; max-width: 220px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-chip { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.user-initials {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; background: var(--brass-400); color: var(--ink-900);
  border-radius: 50%; font-weight: 600; font-size: 12px; letter-spacing: .04em;
  flex-shrink: 0;
}
.user-name {
  font-size: 13px; color: #fff; font-weight: 500; max-width: 160px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-header .btn-ghost { color: rgba(255,255,255,.85); }
.app-header .btn-ghost:hover { background: rgba(255,255,255,.10); color: #fff; }

@media (max-width: 900px) {
  .sidebar-toggle { display: flex; }
  .header-search { display: none; }
  .institution-name { display: none; }
  .app-header { padding: 0 14px; gap: 10px; }
  .header-right { gap: 10px; }
}
@media (max-width: 640px) {
  .user-name { display: none; }
  .brand-tag { display: none; }
  .brand-name { font-size: 14px; }
  .app-header { padding: 0 10px; }
  .header-right { gap: 8px; }
  .app-header .btn-ghost { padding: 6px 8px; }
}
@media (max-width: 400px) {
  .brand-name { display: none; }
}

/* ---------- Sidebar ---------- */
.app-sidebar {
  background: var(--paper-alt); border-right: 1px solid var(--paper-line);
  display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;
}
.sidebar-nav { flex: 1; padding: 8px 8px 16px; }
.sidebar-foot {
  padding: 12px 16px; border-top: 1px solid var(--paper-line);
  font-size: 11px; color: var(--ink-500);
  letter-spacing: .08em; text-transform: uppercase;
}
.nav-section { padding: 8px 0; }
.nav-section-title {
  font-size: 10.5px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--brass-600); padding: 10px 14px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 14px; margin: 1px 0; border-radius: var(--r-sm);
  color: var(--ink-700); font-size: 13.5px; font-weight: 500;
  text-decoration: none; position: relative;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: var(--paper-line); color: var(--ink-900); text-decoration: none; }
.nav-link.active {
  background: var(--paper-raised); color: var(--ink-900);
  font-weight: 600; box-shadow: var(--shadow-sm);
}
.nav-link.active::before {
  content: ''; position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 3px; background: var(--brass-500); border-radius: 0 2px 2px 0;
}
.nav-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; color: var(--ink-500); flex-shrink: 0;
}
.nav-link.active .nav-icon { color: var(--brass-600); }
.nav-icon svg { display: block; width: 16px; height: 16px; }

/* ---------- Locked (feature-gated) nav entries ---------- */
.nav-link.nav-locked {
  opacity: 0.55;
}
.nav-link.nav-locked:hover {
  opacity: 0.78;
  background: var(--paper-line);
  color: var(--ink-900);
}
.nav-link.nav-locked .nav-lock-icon {
  margin-left: auto;
  font-size: 11px;
  opacity: 0.7;
  flex-shrink: 0;
  line-height: 1;
}
.nav-link.nav-locked.active::before {
  background: var(--ink-300);
}

/* ---------- Main ---------- */
.app-main {
  padding: 28px 32px;
  background: var(--paper);
  overflow-x: hidden;
}
@media (max-width: 1200px) { .app-main { padding: 24px; } }
@media (max-width: 900px)  { .app-main { padding: 20px 16px; } }
@media (max-width: 640px)  { .app-main { padding: 16px 12px; } }
@media (max-width: 400px)  { .app-main { padding: 14px 10px; } }

/* ---------- Footer ---------- */
.app-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; background: var(--paper-raised);
  border-top: 1px solid var(--paper-line);
  font-size: 12px; color: var(--ink-500);
  gap: 12px;
}
@media (max-width: 640px) {
  .app-footer {
    padding: 0 12px;
    font-size: 11px;
  }
  #footer-context { display: none; }
}

/* ---------- Page primitives ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 22px; gap: 16px; flex-wrap: wrap;
}
.page-head-text { min-width: 0; flex: 1; }
.page-title {
  font-family: var(--font-serif); font-size: 26px; font-weight: 600;
  color: var(--ink-900); margin: 0 0 4px;
  letter-spacing: -0.015em; line-height: 1.2;
}
.page-subtitle { font-size: 13.5px; color: var(--ink-500); margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

@media (max-width: 640px) {
  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 18px;
  }
  .page-title { font-size: 22px; }
  .page-subtitle { font-size: 13px; }
  .page-actions { justify-content: flex-start; }
  .page-actions .btn { flex: 0 1 auto; }
}

.card {
  background: var(--paper-raised); border: 1px solid var(--paper-line);
  border-radius: var(--r-md); padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.card-title { font-family: var(--font-serif); font-size: 16px; font-weight: 600; color: var(--ink-900); margin: 0; }

@media (max-width: 640px) {
  .card { padding: 16px 14px; }
  .card-head { align-items: flex-start; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 7px; padding: 8px 16px; border-radius: var(--r-md);
  font-size: 13.5px; font-weight: 500;
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
  max-width: 100%;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(201,162,74,.35); }
.btn-primary { background: var(--laurel-600); color: #fff; }
.btn-primary:hover { background: var(--laurel-700); text-decoration: none; }
.btn-secondary { background: var(--paper-raised); color: var(--ink-800); border-color: var(--paper-line-2); }
.btn-secondary:hover { background: var(--paper-alt); text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #8B181C; text-decoration: none; }
.btn-ghost { background: transparent; color: var(--ink-700); }
.btn-ghost:hover { background: var(--paper-line); text-decoration: none; }
.btn-brass {
  background: linear-gradient(135deg, var(--brass-400) 0%, var(--brass-600) 100%);
  color: var(--ink-900); font-weight: 600;
}
.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }

@media (max-width: 640px) {
  .btn { padding: 8px 12px; font-size: 13px; }
  .btn-sm { padding: 5px 9px; font-size: 12px; }
}

/* ---------- Forms ---------- */
.input, .select, .textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--paper-line-2); border-radius: var(--r-sm);
  background: var(--paper-raised); color: var(--ink-900); font-size: 14px;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brass-500);
  box-shadow: 0 0 0 3px rgba(201,162,74,.20);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-300); }
.textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--ink-700); margin-bottom: 6px;
}
.field-required::after { content: ' *'; color: var(--danger); }
.field-hint { font-size: 12px; color: var(--ink-500); margin-top: 5px; }
.field-error { color: var(--danger); font-size: 12px; margin-top: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 640px) {
  .field-row, .field-row-3 { grid-template-columns: 1fr; gap: 12px; }
  .field { margin-bottom: 14px; }
}

.form-error {
  padding: 11px 14px; background: var(--danger-bg);
  border: 1px solid #F2C7C9; color: #6E1114;
  border-radius: var(--r-sm); font-size: 13px; margin-bottom: 16px;
}
.form-error:empty { display: none; }
.form-success {
  padding: 11px 14px; background: var(--success-bg);
  border: 1px solid #B7E0C7; color: #0A3A24;
  border-radius: var(--r-sm); font-size: 13px; margin-bottom: 16px;
}
.form-success:empty { display: none; }

/* ---------- Filters ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 12px;
  margin-bottom: 20px; align-items: flex-end;
}
.filters .field { margin-bottom: 0; }

@media (max-width: 640px) {
  .filters {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 16px;
  }
  .filters .field { width: 100% !important; max-width: none !important; }
}

/* ---------- Tabs (generic wrapper for data-tab buttons) ---------- */
.tabs-row,
[data-tab],
[data-el-tab],
[data-lib-tab],
[data-stab] {
  /* Each module wraps these in a div with inline style. The rule below
     only nudges the wrapper to wrap on small screens. */
}

@media (max-width: 640px) {
  /* Any horizontal flex containing tab buttons wraps + scrolls if needed */
  .app-main > div[style*="display:flex"] { flex-wrap: wrap; }
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto; border: 1px solid var(--paper-line);
  border-radius: var(--r-md); background: var(--paper-raised);
  -webkit-overflow-scrolling: touch;
}
.table {
  width: 100%; border-collapse: collapse;
  font-size: 13.5px; font-variant-numeric: tabular-nums;
  min-width: 560px;
}
.table thead th {
  position: sticky; top: 0; padding: 11px 14px; text-align: left;
  font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--brass-700);
  background: var(--brass-50); border-bottom: 1px solid var(--paper-line);
  white-space: nowrap;
}
.table tbody td {
  padding: 12px 14px; border-bottom: 1px solid var(--paper-line);
  color: var(--ink-800); vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--brass-50); }
.table td.num, .table th.num { text-align: right; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 640px) {
  .table thead th { padding: 9px 10px; font-size: 10.5px; }
  .table tbody td { padding: 10px; font-size: 13px; }
  .table .actions { justify-content: flex-start; }
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; line-height: 1.4;
  white-space: nowrap;
}
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-red   { background: var(--danger-bg);  color: var(--danger); }
.badge-amber { background: var(--warning-bg); color: var(--warning); }
.badge-blue  { background: var(--info-bg);    color: var(--info); }
.badge-brass { background: var(--brass-100);  color: var(--brass-700); }
.badge-slate { background: var(--ink-100);    color: var(--ink-700); }

/* ---------- Stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat {
  background: var(--paper-raised); border: 1px solid var(--paper-line);
  border-radius: var(--r-md); padding: 18px 20px;
  position: relative; overflow: hidden;
}
.stat::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--brass-400);
}
.stat-label {
  font-size: 11.5px; color: var(--ink-500);
  text-transform: uppercase; letter-spacing: .08em;
  font-weight: 600; margin-bottom: 8px;
}
.stat-value {
  font-family: var(--font-serif); font-size: 30px; font-weight: 600;
  color: var(--ink-900); line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.stat-delta { font-size: 12px; margin-top: 8px; color: var(--ink-500); }
.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--danger); }

@media (max-width: 640px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
  .stat { padding: 14px 16px; }
  .stat-value { font-size: 24px; }
}
@media (max-width: 400px) {
  .stat-grid { grid-template-columns: 1fr; }
}

/* ---------- States ---------- */
.empty-state {
  padding: 56px 24px; text-align: center;
  color: var(--ink-500); font-size: 14px;
}
.empty-state h3 {
  font-family: var(--font-serif); font-size: 18px;
  color: var(--ink-700); margin: 0 0 8px; font-weight: 600;
}
@media (max-width: 640px) {
  .empty-state { padding: 40px 16px; }
}

/* ---------- Skeleton loading ---------- */
.skeleton {
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    var(--paper-line)    0%,
    var(--paper-line-2) 50%,
    var(--paper-line)   100%
  );
  background-size: 200% 100%;
  animation: skel 1.4s ease-in-out infinite;
  color: transparent;
  user-select: none;
  pointer-events: none;
}
@keyframes skel {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Shape helpers */
.skeleton-row    { height: 16px; border-radius: 6px; }
.skeleton-row + .skeleton-row { margin-top: 10px; }
.skeleton-row.short  { width: 40%; }
.skeleton-row.medium { width: 70%; }
.skeleton-row.long   { width: 100%; }

.skeleton-circle { border-radius: 50%; }

.skeleton-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Prefer reduced motion: freeze the animation for accessibility */
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed; top: calc(var(--header-h) + 12px); right: 20px;
  z-index: 200; display: flex; flex-direction: column; gap: 10px;
  max-width: 360px; pointer-events: none;
}
.toast {
  padding: 12px 16px; border-radius: var(--r-md);
  background: var(--ink-900); color: #fff; font-size: 13.5px;
  box-shadow: var(--shadow-lg); pointer-events: auto;
  display: flex; gap: 10px; align-items: flex-start;
  animation: toast-in .22s cubic-bezier(.4,0,.2,1);
  border-left: 3px solid var(--brass-400);
}
.toast.success { background: var(--laurel-700); border-left-color: var(--laurel-400); }
.toast.error   { background: #7E1819;          border-left-color: #F87171; }
.toast.warn    { background: #7C4A0F;          border-left-color: var(--warning); }
.toast.info    { background: var(--ink-900);   border-left-color: var(--brass-400); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } }

@media (max-width: 640px) {
  .toast-stack {
    top: auto;
    bottom: 16px;
    right: 12px;
    left: 12px;
    max-width: none;
  }
  .toast { font-size: 13px; padding: 10px 14px; }
}

/* ---------- Modal ---------- */
#modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(11,31,58,.55);
  z-index: 150; display: flex; align-items: center; justify-content: center;
  padding: 20px; animation: fade .15s ease; backdrop-filter: blur(2px);
}
.modal {
  background: var(--paper-raised); border-radius: var(--r-lg);
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in .22s cubic-bezier(.4,0,.2,1);
}
.modal-head {
  padding: 20px 24px 16px; border-bottom: 1px solid var(--paper-line);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.modal-title { font-family: var(--font-serif); font-size: 18px; font-weight: 600; margin: 0; }
.modal-sub { font-size: 13px; color: var(--ink-500); margin: 4px 0 0; }
.modal-close {
  background: transparent; border: none; font-size: 22px; line-height: 1;
  color: var(--ink-500); padding: 2px 8px; border-radius: var(--r-sm);
  flex-shrink: 0;
}
.modal-close:hover { background: var(--paper-line); color: var(--ink-900); }
.modal-body { padding: 20px 24px; }
.modal-foot {
  padding: 16px 24px; border-top: 1px solid var(--paper-line);
  display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  background: var(--paper); border-radius: 0 0 var(--r-lg) var(--r-lg);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes fade { from { opacity: 0; } }

@media (max-width: 640px) {
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: none;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    max-height: 92vh;
  }
  .modal-head { padding: 16px 18px 12px; }
  .modal-title { font-size: 16px; }
  .modal-body { padding: 16px 18px; }
  .modal-foot {
    padding: 14px 18px;
    border-radius: 0;
    justify-content: stretch;
  }
  .modal-foot .btn { flex: 1; }
}

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top left,  rgba(201,162,74,.12) 0%, transparent 45%),
    radial-gradient(ellipse at bottom right, rgba(15,81,50,.10) 0%, transparent 50%),
    linear-gradient(160deg, var(--paper) 0%, var(--paper-alt) 100%);
  position: relative;
}
.login-shell::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--ink-900) 0%, var(--brass-500) 50%, var(--laurel-600) 100%);
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--paper-raised); border: 1px solid var(--paper-line);
  border-radius: var(--r-lg); padding: 40px 36px;
  box-shadow: var(--shadow-lg); position: relative;
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.login-brand .brand-seal { width: 46px; height: 46px; font-size: 22px; border-radius: 10px; }
.login-brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.login-brand-text .brand-name { font-family: var(--font-serif); font-size: 20px; font-weight: 600; color: var(--ink-900); }
.login-brand-text .brand-tag { font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--brass-600); font-weight: 600; }
.login-subtitle {
  font-size: 13.5px; color: var(--ink-500);
  margin: 18px 0 26px; padding-bottom: 22px;
  border-bottom: 1px solid var(--paper-line);
}
.login-switch {
  margin-top: 18px; text-align: center; font-size: 13px;
  color: var(--ink-500);
}
.login-switch a { font-weight: 500; }
.login-footer {
  margin-top: 26px; padding-top: 20px;
  border-top: 1px solid var(--paper-line);
  text-align: center; font-size: 11.5px;
  letter-spacing: .08em; text-transform: uppercase; color: var(--ink-500);
}
@media (max-width: 480px) {
  .login-shell { padding: 16px; }
  .login-card { padding: 28px 22px; }
  .login-brand-text .brand-name { font-size: 18px; }
}

/* ---------- Utilities ---------- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--ink-500); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-serif { font-family: var(--font-serif); }
.font-semibold { font-weight: 600; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-5 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-5 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.flex-center { display: flex; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; min-width: 0; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; }
.gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-5 { gap: 24px; }
.w-full { width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Boot splash ---------- */
#boot {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #0B1F3A; z-index: 9999;
  font-family: var(--font-sans);
}
#boot .seal {
  width: 56px; height: 56px; margin: 0 auto 20px; border-radius: 12px;
  background: linear-gradient(135deg, #C9A24A 0%, #8C6A1F 100%);
  color: #0B1F3A; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-serif); font-weight: 700; font-size: 26px;
  box-shadow: 0 8px 32px rgba(201,162,74,.25);
}
#boot .ring {
  width: 32px; height: 32px; margin: 0 auto;
  border: 2px solid rgba(201,162,74,.25); border-top-color: #C9A24A;
  border-radius: 50%; animation: spin .9s linear infinite;
}
#boot .label {
  margin-top: 16px; color: #C9A24A; font-size: 12px;
  letter-spacing: .18em; text-transform: uppercase; font-weight: 500;
}
@keyframes spin { to { transform: rotate(360deg); } }

body.booting #app-shell { display: none; }
body:not(.booting) #boot { display: none; }

/* ---------- Scrollbars ---------- */
.app-main::-webkit-scrollbar,
.app-sidebar::-webkit-scrollbar { width: 10px; }
.app-main::-webkit-scrollbar-track,
.app-sidebar::-webkit-scrollbar-track { background: transparent; }
.app-main::-webkit-scrollbar-thumb,
.app-sidebar::-webkit-scrollbar-thumb {
  background: var(--paper-line-2); border-radius: 10px;
  border: 2px solid var(--paper);
}
@media (max-width: 640px) {
  .app-main::-webkit-scrollbar,
  .app-sidebar::-webkit-scrollbar { width: 6px; }
  .app-main::-webkit-scrollbar-thumb,
  .app-sidebar::-webkit-scrollbar-thumb { border-width: 1px; }
}

/* ---------- Report card (printable) ---------- */
.report-card {
  background: white;
  border: 1px solid var(--paper-line);
  border-radius: var(--r-md);
  padding: 32px;
  max-width: 900px;
  margin: 0 auto;
}
.report-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--ink-900);
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.report-card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px 24px;
  margin-bottom: 24px;
}
.report-card-grid > div {
  font-size: 14px;
  color: var(--ink-900);
}
.report-card-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 20px;
}
.report-card-table thead th {
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--brass-700);
  background: var(--brass-50);
  border-bottom: 1px solid var(--paper-line);
}
.report-card-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--paper-line);
  color: var(--ink-900);
}
.report-card-table tbody tr:last-child td { border-bottom: none; }
.report-card-table td.num, .report-card-table th.num { text-align: right; }
.report-card-traits {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  padding: 16px 0;
  border-top: 1px solid var(--paper-line);
  border-bottom: 1px solid var(--paper-line);
  margin-bottom: 20px;
}
.report-card-comments {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}
.report-card-comment-block {
  padding: 12px 0;
  border-top: 1px solid var(--paper-line);
  border-bottom: 1px solid var(--paper-line);
}
.report-card-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 24px;
  margin-top: 40px;
  text-align: center;
  font-size: 12px;
}

@media (max-width: 640px) {
  .report-card { padding: 20px 16px; }
  .report-card-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .report-card-traits { grid-template-columns: 1fr 1fr; }
  .report-card-comments { grid-template-columns: 1fr; gap: 16px; }
  .report-card-signatures { grid-template-columns: 1fr; gap: 20px; }
  .report-card-table { min-width: 500px; }
}

/* Dark mode adjustments — report card stays white */
.theme-dark .report-card {
  background: #ffffff;
  color: #0B1F3A;
}
.theme-dark .report-card .text-muted { color: #64748b; }
.theme-dark .report-card-table thead th { background: #f5ebd1; color: #6e5215; }
.theme-dark .report-card-table tbody td { color: #0B1F3A; border-bottom-color: #e8e3d5; }
.theme-dark .report-card-traits,
.theme-dark .report-card-comment-block { border-color: #e8e3d5; }

/* Print rules */
@media print {
  /* Reset page defaults */
  html, body {
    background: #fff !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* Hide shell chrome and interactive elements everywhere */
  .no-print,
  .app-header,
  .app-sidebar,
  .app-footer,
  .toast-stack,
  .page-actions,
  .filters,
  .pagination,
  .modal-backdrop,
  .modal-foot,
  .modal-close,
  .lib-tabs,
  [data-tab],
  [data-stab],
  [data-lib-tab],
  [data-el-tab],
  [data-set-tab],
  button.btn {
    display: none !important;
  }

  /* The main scroll container must not clip its content when printing */
  .app-main,
  #app,
  #set-body,
  #lib-body,
  #ex-body,
  #rp-body {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* ---------- Path A: pages that contain a report card ----------
     When #rp-printable is present, print only it. Everything else
     on the page stays hidden. */
  body:has(#rp-printable) * {
    visibility: hidden;
  }
  body:has(#rp-printable) #rp-printable,
  body:has(#rp-printable) #rp-printable * {
    visibility: visible;
  }
  body:has(#rp-printable) #rp-printable {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    max-width: none;
    border: none;
    box-shadow: none;
    padding: 0;
    background: #fff;
    color: #000;
  }

  /* ---------- Path B: pages without a report card ----------
     Print the whole #app main area with sensible defaults. */
  body:not(:has(#rp-printable)) .app-main {
    display: block !important;
    padding: 0 !important;
  }
  body:not(:has(#rp-printable)) .card {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    page-break-inside: avoid;
    background: #fff !important;
  }

  /* Tables print with repeating header rows and don't split mid-row */
  .table-wrap {
    overflow: visible !important;
    border: 1px solid #999 !important;
    border-radius: 0 !important;
  }
  .table {
    width: 100% !important;
    min-width: 0 !important;
    font-size: 10.5pt !important;
    border-collapse: collapse !important;
  }
  .table thead {
    display: table-header-group;
  }
  .table tfoot {
    display: table-footer-group;
  }
  .table tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .table th,
  .table td {
    border: 1px solid #999 !important;
    padding: 4pt 6pt !important;
    color: #000 !important;
    background: #fff !important;
  }
  .table thead th {
    background: #eee !important;
    color: #000 !important;
    font-weight: 700 !important;
  }

  /* Library grid prints as single-column cards */
  .lib-grid { display: block !important; }
  .lib-card {
    border: 1px solid #999 !important;
    margin-bottom: 8pt !important;
    padding: 8pt !important;
    page-break-inside: avoid;
    background: #fff !important;
  }
  .lib-cover { display: none !important; }

  /* E-learning course cards print as simple rows */
  .el-course-grid { display: block !important; }
  .el-course-card {
    border: 1px solid #999 !important;
    margin-bottom: 8pt !important;
    padding: 8pt !important;
    page-break-inside: avoid;
    background: #fff !important;
  }
  .el-course-cover { display: none !important; }

  /* Badges stay readable in black and white */
  .badge {
    border: 1px solid #666 !important;
    background: #fff !important;
    color: #000 !important;
  }

  /* Links: show the URL after the link text */
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #333;
  }

  /* Page margins */
  @page { size: A4 portrait; margin: 14mm 12mm; }
}

/* ---------- CBT exam-taking screen ---------- */
.ex-timer {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink-900);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.ex-timer-low { color: var(--danger); }

.ex-question {
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-900);
  margin-bottom: 18px;
  padding: 14px 16px;
  background: var(--paper-alt);
  border-radius: var(--r-md);
}

.ex-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ex-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--paper-line-2);
  border-radius: var(--r-md);
  background: var(--paper-raised);
  color: var(--ink-900);
  font-size: 14.5px;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
  cursor: pointer;
  width: 100%;
}
.ex-option:hover { background: var(--brass-50); border-color: var(--brass-400); }
.ex-option-selected {
  background: var(--laurel-100);
  border-color: var(--laurel-500);
  color: var(--laurel-700);
  font-weight: 500;
}
.ex-option-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  background: var(--paper-alt);
  border-radius: 50%;
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-700);
  flex-shrink: 0;
}
.ex-option-selected .ex-option-letter {
  background: var(--laurel-500);
  color: #fff;
}
.ex-option-text { flex: 1; line-height: 1.4; padding-top: 2px; min-width: 0; }

.ex-dots { display: flex; flex-wrap: wrap; gap: 6px; }
.ex-dot {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--paper-line-2);
  background: var(--paper-raised);
  color: var(--ink-700);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ex-dot:hover { background: var(--paper-alt); }
.ex-dot-answered {
  background: var(--laurel-100);
  border-color: var(--laurel-400);
  color: var(--laurel-700);
}
.ex-dot-current {
  outline: 2px solid var(--brass-500);
  outline-offset: 1px;
  font-weight: 700;
}

@media (max-width: 640px) {
  .ex-timer { font-size: 18px; }
  .ex-question { font-size: 15px; padding: 12px 14px; }
  .ex-option { padding: 10px 12px; font-size: 14px; }
  .ex-dot { width: 28px; height: 28px; font-size: 11px; }
}

.theme-dark .ex-question { background: var(--paper-alt); color: var(--ink-900); }
.theme-dark .ex-option-selected {
  background: var(--laurel-200);
  border-color: var(--laurel-500);
  color: var(--laurel-700);
}

/* ---------- E-Learning course cards ---------- */
.el-course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.el-course-card {
  background: var(--paper-raised);
  border: 1px solid var(--paper-line);
  border-radius: var(--r-md);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
}
.el-course-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--brass-400);
}
.el-course-cover {
  height: 130px;
  background: linear-gradient(135deg, var(--brass-100) 0%, var(--brass-200) 100%);
  background-size: cover;
  background-position: center;
  position: relative;
}
.el-course-body { padding: 14px 16px 16px; }

.el-progress {
  height: 6px;
  background: var(--paper-line);
  border-radius: 3px;
  overflow: hidden;
}
.el-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--laurel-500), var(--laurel-600));
  transition: width 0.4s ease;
}

@media (max-width: 640px) {
  .el-course-grid { grid-template-columns: 1fr; gap: 12px; }
  .el-course-cover { height: 110px; }
}

/* Lesson list (course player) */
.el-lesson-list { display: flex; flex-direction: column; }
.el-lesson-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  border-bottom: 1px solid var(--paper-line);
}
.el-lesson-row:last-child { border-bottom: none; }
.el-lesson-row:hover { background: var(--paper-alt); }
.el-lesson-active { background: var(--brass-50); font-weight: 600; }
.el-lesson-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--paper-alt); color: var(--ink-700);
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.el-lesson-active .el-lesson-num {
  background: var(--brass-400); color: #fff;
}
.el-lesson-title { flex: 1; min-width: 0; }
.el-lesson-dur { font-size: 12px; color: var(--ink-500); flex-shrink: 0; }

@media (max-width: 640px) {
  .el-lesson-row { gap: 8px; padding: 9px 10px; }
  .el-lesson-title { font-size: 13.5px; }
}

/* Video embed */
.el-video-wrap {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  border-radius: var(--r-md);
  background: #000;
  margin-bottom: 14px;
}
.el-video-wrap iframe,
.el-video-wrap video {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: 0;
}

/* Library grid */
.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.lib-card {
  background: var(--paper-raised);
  border: 1px solid var(--paper-line);
  border-radius: var(--r-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.lib-cover {
  height: 180px;
  background: linear-gradient(135deg, var(--ink-100), var(--paper-alt));
  background-size: cover;
  background-position: center;
  position: relative;
}
.lib-body { padding: 12px 14px 14px; flex: 1; display: flex; flex-direction: column; }
.lib-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 4px;
}

@media (max-width: 640px) {
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .lib-cover { height: 150px; }
  .lib-body { padding: 10px 12px 12px; }
  .lib-title { font-size: 14px; }
}

/* ==========================================================================
   Dark mode — Ink & Laurel (Night)
   Activated by adding class="theme-dark" to <html> or <body>.
   ========================================================================== */
.theme-dark {
  --ink-900: #F1F4F8; --ink-800: #E4EAF1; --ink-700: #C7D3E0;
  --ink-600: #94A9C2; --ink-500: #7A90AC; --ink-300: #4A5A72;
  --ink-200: #2E3E55; --ink-100: #1F2C3F;

  --laurel-700: #7BE0A4; --laurel-600: #4FCB86; --laurel-500: #34A76A;
  --laurel-400: #1F8A54; --laurel-200: #17402C; --laurel-100: #12301F;

  --brass-700: #F5EBD1; --brass-600: #EEDCB0; --brass-500: #DEC27F;
  --brass-400: #C9A24A; --brass-300: #A9832A; --brass-200: #6E5215;
  --brass-100: #3A2E13; --brass-50:  #221B0C;

  --paper: #0B1622;
  --paper-alt: #0F1E30;
  --paper-raised: #14263C;
  --paper-line: #1F3350;
  --paper-line-2: #2A4060;

  --success: #7BE0A4; --success-bg: #12301F;
  --warning: #F5C069; --warning-bg: #3A2A0C;
  --danger:  #F87171; --danger-bg:  #3B1416;
  --info:    #8AB6E8; --info-bg:    #16273D;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 2px 8px rgba(0,0,0,.40), 0 1px 2px rgba(0,0,0,.30);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.55), 0 2px 6px rgba(0,0,0,.35);

  color-scheme: dark;
}

.theme-dark .app-header {
  background: #0A1420;
  border-bottom: 1px solid var(--paper-line);
}
.theme-dark .app-header::after {
  background: linear-gradient(90deg, var(--brass-400) 0%, var(--brass-300) 40%, transparent 100%);
}
.theme-dark .sidebar-foot { border-top-color: var(--paper-line); }
.theme-dark .login-shell {
  background:
    radial-gradient(ellipse at top left,  rgba(201,162,74,.10) 0%, transparent 45%),
    radial-gradient(ellipse at bottom right, rgba(79,203,134,.08) 0%, transparent 50%),
    linear-gradient(160deg, #0B1622 0%, #0F1E30 100%);
}
.theme-dark #boot { background: #060D16; }
.theme-dark .brand-seal,
.theme-dark .login-brand .brand-seal { color: #0B1F3A; }
.theme-dark .user-initials { color: #0B1F3A; }

.theme-dark .header-search input {
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.12);
}
.theme-dark .header-search input:focus {
  background: rgba(255,255,255,.10);
  border-color: var(--brass-400);
}
.theme-dark .header-search input::placeholder { color: rgba(255,255,255,.45); }

.theme-dark .table thead th {
  background: #14263C;
  color: var(--brass-400);
  border-bottom-color: var(--paper-line);
}
.theme-dark .table tbody tr:hover { background: #182E48; }

.theme-dark .toast        { background: #14263C; }
.theme-dark .toast.success { background: #0F3222; }
.theme-dark .toast.error   { background: #3B1416; }
.theme-dark .toast.warn    { background: #3A2A0C; }

.theme-dark .form-success { border-color: #1F5A38; }
.theme-dark .form-error   { border-color: #5A1F22; }

.theme-dark .app-main::-webkit-scrollbar-thumb,
.theme-dark .app-sidebar::-webkit-scrollbar-thumb {
  background: var(--paper-line-2);
  border-color: var(--paper);
}

/* Dark mode — locked nav entries */
.theme-dark .nav-link.nav-locked {
  opacity: 0.45;
}
.theme-dark .nav-link.nav-locked:hover {
  opacity: 0.7;
}

html.theme-anim,
html.theme-anim body,
html.theme-anim .app-shell,
html.theme-anim .card,
html.theme-anim .app-header,
html.theme-anim .app-sidebar,
html.theme-anim .app-footer,
html.theme-anim .input,
html.theme-anim .select,
html.theme-anim .textarea,
html.theme-anim .btn {
  transition: background-color .18s ease, color .18s ease, border-color .18s ease;
}

@media (prefers-color-scheme: dark) {
  html:not(.theme-light):not(.theme-dark) {
    /* opt-in via JS */
  }
}

/* ==========================================================================
   Mobile — cross-cutting responsive fixes
   ========================================================================== */
@media (max-width: 900px) {
  .app-main > * { max-width: 100%; }
}

@media (max-width: 640px) {
  /* Force every container and its children to respect viewport width */
  .app-main,
  .app-main * {
    max-width: 100%;
  }
  /* No horizontal scroll on tabs, action bars, filter bars */
  .app-main div[style*="display:flex"] {
    flex-wrap: wrap !important;
  }
  /* Prevent wide tables from breaking layout — the wrapper handles scroll */
  .table-wrap { max-width: 100%; }
  /* Prevent long words / URLs from forcing horizontal scroll */
  .app-main { overflow-wrap: anywhere; word-break: break-word; }
  /* Inputs and buttons never exceed their container */
  .input, .select, .textarea, .btn { max-width: 100%; }
}

/* Extra-small screens (iPhone SE, small Androids) */
@media (max-width: 380px) {
  .app-main { padding: 12px 8px; }
  .page-title { font-size: 20px; }
  .card { padding: 14px 12px; }
  .btn { padding: 7px 10px; font-size: 12.5px; }
  .btn-sm { padding: 4px 8px; font-size: 11.5px; }
  .table thead th { padding: 8px; font-size: 10px; }
  .table tbody td { padding: 8px; font-size: 12.5px; }
}

/* Landscape mobile — protect header height and app-main padding */
@media (max-height: 500px) and (orientation: landscape) {
  .app-main { padding: 14px 16px; }
}

/* ---------- Settings page ---------- */
#set-body .card + .card { margin-top: 16px; }

#set-body .card[style*="max-width"] {
  width: 100%;
}

@media (max-width: 640px) {
  #set-body .field-row { grid-template-columns: 1fr; }
  #set-body .card { padding: 16px 14px; }
  #set-body div[style*="display:flex"] { flex-wrap: wrap; }
  #set-body .btn { flex: 1 1 auto; }
}