/* ============================================================
   SJ Academy — Design system & motion layer
   Layered on top of Tailwind (CDN) utilities.
   ============================================================ */

/* ---------- Brand color variables (overridden per-request by
   includes/theme.php via html[data-brand=...]; indigo is default) ---------- */
:root {
  --brand-50: #eef2ff; --brand-100: #e0e7ff; --brand-200: #c7d2fe; --brand-300: #a5b4fc;
  --brand-400: #818cf8; --brand-500: #6366f1; --brand-600: #4f46e5; --brand-700: #4338ca;
  --brand-800: #3730a3; --brand-900: #312e81; --brand-950: #1e1b4b;
  --brand-rgb-500: 99 102 241; --brand-rgb-600: 79 70 229; --brand-rgb-700: 67 56 202;
  --accent-100: #ede9fe; --accent-300: #c4b5fd; --accent-500: #8b5cf6; --accent-600: #7c3aed; --accent-700: #6d28d9;
  --accent-rgb-500: 139 92 246; --accent-rgb-100: 237 233 254;
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(100,116,139,.3); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(100,116,139,.5); }
* { scrollbar-width: thin; scrollbar-color: rgba(100,116,139,.4) transparent; }
.scrollbar-none { scrollbar-width: none; }
.scrollbar-none::-webkit-scrollbar { display: none; }

::selection { background: rgba(var(--brand-rgb-500), .25); }

/* ---------- Smooth scroll (motion-safe only) ---------- */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* ---------- Ambient background ---------- */
body {
  background-color: #f8fafc;
  background-image:
    radial-gradient(1100px 520px at 12% -8%, rgba(var(--brand-rgb-500), .10), transparent 55%),
    radial-gradient(900px 480px at 100% 4%, rgba(var(--accent-rgb-500), .09), transparent 55%),
    radial-gradient(1000px 620px at 55% 112%, rgba(14,165,233,.05), transparent 55%);
  background-attachment: fixed;
}
.dark body {
  background-color: #020617;
  background-image:
    radial-gradient(1100px 520px at 12% -8%, rgba(var(--brand-rgb-500), .15), transparent 55%),
    radial-gradient(900px 480px at 100% 4%, rgba(var(--accent-rgb-500), .13), transparent 55%),
    radial-gradient(1000px 620px at 55% 112%, rgba(14,165,233,.08), transparent 55%);
}

/* ---------- Focus rings ---------- */
a:focus-visible, button:focus-visible, [tabindex]:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
}

/* ---------- Buttons & controls: smooth press + color motion ---------- */
button {
  transition-property: transform, color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow;
  transition-duration: 150ms;
  transition-timing-function: cubic-bezier(.4, 0, .2, 1);
  -webkit-tap-highlight-color: transparent;
}
button:not(:disabled):active { transform: scale(.97); }
a.tappable, .tappable {
  transition: transform .15s ease, color .15s ease, background-color .15s ease, box-shadow .2s ease;
}
a.tappable:active, .tappable:active { transform: scale(.97); }

input, select, textarea {
  transition: box-shadow .2s ease, border-color .2s ease, background-color .2s ease;
}

/* ---------- Page section entrance cascade ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
#app-content > * { animation: fadeUp .42s cubic-bezier(.21,.61,.35,1) both; }
#app-content > *:nth-child(1) { animation-delay: .02s; }
#app-content > *:nth-child(2) { animation-delay: .05s; }
#app-content > *:nth-child(3) { animation-delay: .08s; }
#app-content > *:nth-child(4) { animation-delay: .11s; }
#app-content > *:nth-child(5) { animation-delay: .14s; }
#app-content > *:nth-child(6) { animation-delay: .17s; }
#app-content > *:nth-child(7) { animation-delay: .20s; }
#app-content > *:nth-child(8) { animation-delay: .23s; }
#app-content > *:nth-child(9) { animation-delay: .26s; }
#app-content > *:nth-child(10) { animation-delay: .29s; }
#app-content > *:nth-child(n+11) { animation-delay: .32s; }

.stagger > * { animation: fadeUp .5s cubic-bezier(.21,.61,.35,1) both; }
.stagger > *:nth-child(1) { animation-delay: .02s; }
.stagger > *:nth-child(2) { animation-delay: .10s; }
.stagger > *:nth-child(3) { animation-delay: .18s; }
.stagger > *:nth-child(4) { animation-delay: .26s; }
.stagger > *:nth-child(5) { animation-delay: .34s; }
.stagger > *:nth-child(6) { animation-delay: .42s; }

/* ---------- Native view transitions (page swap) ---------- */
::view-transition-old(root) { animation: vtout .16s ease both; }
::view-transition-new(root) { animation: vtin .32s ease both; }
@keyframes vtout { to { opacity: 0; transform: translateY(-8px); } }
@keyframes vtin { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Route progress bar ---------- */
#route-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  z-index: 80; pointer-events: none; opacity: 0; overflow: hidden;
}
#route-progress::before {
  content: ''; display: block; height: 100%; width: 40%; border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-500), var(--accent-500), #06b6d4);
  transform: translateX(-100%);
}
#route-progress.is-active { opacity: 1; }
#route-progress.is-active::before { animation: routeprogress 1s ease-in-out infinite; }
@keyframes routeprogress {
  0% { transform: translateX(-100%); }
  55% { transform: translateX(120%); }
  100% { transform: translateX(320%); }
}

/* ---------- Card hover lift ---------- */
.card-hover { transition: box-shadow .2s ease, transform .2s ease, border-color .2s ease; }
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px -12px rgb(15 23 42 / .16);
  border-color: rgba(var(--brand-rgb-500), .25);
}
.hover-lift { transition: transform .22s cubic-bezier(.21,.61,.35,1), box-shadow .22s ease, border-color .22s ease; }
.hover-lift:hover {
  transform: translateY(-3px);
  box-shadow: 0 18px 34px -18px rgb(15 23 42 / .25);
}

tbody tr { transition: background-color .15s ease; }

/* ---------- Sidebar: active marker + collapse ---------- */
#sidebar-nav a { position: relative; }
#sidebar-nav a.is-active::before {
  content: ''; position: absolute; left: 0; top: 50%; translate: 0 -50%;
  width: 3px; height: 55%; border-radius: 0 999px 999px 0;
  background: linear-gradient(180deg, var(--brand-500), var(--accent-500));
}
body.sidebar-collapsed aside { width: 5rem; }
body.sidebar-collapsed #sidebar-nav .section-label { text-align: center; overflow: hidden; }
body.sidebar-collapsed #sidebar-nav .section-label::after { content: '·'; display: block; font-size: 12px; line-height: 1; }
body.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed #sidebar-nav a span,
body.sidebar-collapsed .sidebar-user-meta,
body.sidebar-collapsed .sidebar-logout { display: none; }
body.sidebar-collapsed #sidebar-nav a { justify-content: center; gap: 0; padding-left: .6rem; padding-right: .6rem; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; gap: .5rem; }
body.sidebar-collapsed .sidebar-footer-user { justify-content: center; }
@media (min-width: 1024px) {
  body.sidebar-collapsed .content-shell { padding-left: 5rem; }
}

/* ---------- Sidebar color schemes (Settings > Appearance) ---------- */
html[data-sidebar="dark"] #sidebar { background-color: var(--color-slate-900, #0f172a); border-color: var(--color-slate-800, #1e293b); }
html[data-sidebar="midnight"] #sidebar { background: linear-gradient(180deg, #3730a3, #1e1b4b); border-color: transparent; }
html[data-sidebar="brand"] #sidebar { background: linear-gradient(180deg, var(--brand-800), var(--brand-950)); border-color: transparent; }
html[data-sidebar="forest"] #sidebar { background: linear-gradient(180deg, #065f46, #022c22); border-color: transparent; }
html[data-sidebar="navy"] #sidebar { background: linear-gradient(180deg, #1e40af, #172554); border-color: transparent; }
html[data-sidebar="wine"] #sidebar { background: linear-gradient(180deg, #9f1239, #4c0519); border-color: transparent; }
html[data-sidebar="charcoal"] #sidebar { background: linear-gradient(180deg, #374151, #111827); border-color: transparent; }

html[data-sidebar]:not([data-sidebar="light"]) #sidebar .sidebar-brand,
html[data-sidebar]:not([data-sidebar="light"]) #sidebar nav + div { border-color: rgba(255, 255, 255, .1); }

html[data-sidebar]:not([data-sidebar="light"]) #sidebar .sidebar-brand-text p:first-child { color: #fff; }
html[data-sidebar]:not([data-sidebar="light"]) #sidebar .sidebar-brand-text p:last-child { color: rgba(203, 213, 225, .8); }

html[data-sidebar]:not([data-sidebar="light"]) #sidebar .section-label { color: rgba(148, 163, 184, .9); }

html[data-sidebar]:not([data-sidebar="light"]) #sidebar-nav a { color: #cbd5e1; }
html[data-sidebar]:not([data-sidebar="light"]) #sidebar-nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
html[data-sidebar]:not([data-sidebar="light"]) #sidebar-nav a.is-active { background: rgba(255, 255, 255, .12); color: #fff; }

html[data-sidebar]:not([data-sidebar="light"]) #sidebar-user-name { color: #fff; }
html[data-sidebar]:not([data-sidebar="light"]) #sidebar-user-role { color: rgba(203, 213, 225, .7); }

html[data-sidebar]:not([data-sidebar="light"]) #sidebar-collapse-btn,
html[data-sidebar]:not([data-sidebar="light"]) .sidebar-logout { color: rgba(203, 213, 225, .7); }
html[data-sidebar]:not([data-sidebar="light"]) #sidebar-collapse-btn:hover,
html[data-sidebar]:not([data-sidebar="light"]) .sidebar-logout:hover { background: rgba(255, 255, 255, .1); color: #fff; }

/* ---------- Topbar: role switcher is desktop-only ---------- */
#role-wrap { display: none; }
@media (min-width: 1024px) {
  #role-wrap { display: block; }
  #role-wrap.hidden { display: none; }
}

/* ---------- Dropdown pop-in ---------- */
.drop-enter { animation: dropIn .18s ease both; }
@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px) scale(.98); }
  to { opacity: 1; transform: none; }
}
#search-results { transform-origin: top left; }
#context-panel, #notif-panel, #profile-panel { transform-origin: top right; }

/* ---------- Toast (right-bottom, image-matched with timeout progress) ---------- */
#toast-host {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  z-index: 70; display: flex; flex-direction: column; gap: .75rem;
  width: min(420px, 92vw); pointer-events: none; align-items: stretch;
}
#toast-host .toast {
  position: relative; overflow: hidden;
  display: flex; align-items: stretch;
  min-height: 64px;
  background: #fff; border-radius: .5rem;
  box-shadow: 0 8px 24px -12px rgb(15 23 42 / .14), 0 4px 16px -6px rgb(15 23 42 / .10);
  pointer-events: auto;
  transition: transform .32s cubic-bezier(.21,.61,.35,1), opacity .28s ease;
  will-change: transform, opacity;
}
#toast-host .toast-success { background: #f0fdf4; }
#toast-host .toast-error   { background: #fef2f2; }
#toast-host .toast-warning { background: #fffbeb; }
#toast-host .toast-info    { background: #eff6ff; }
.dark #toast-host .toast { box-shadow: 0 8px 24px -12px rgb(0 0 0 / .35); }
.dark #toast-host .toast-success { background: rgba(34,197,94,.14); }
.dark #toast-host .toast-error   { background: rgba(239,68,68,.14); }
.dark #toast-host .toast-warning { background: rgba(245,158,11,.14); }
.dark #toast-host .toast-info    { background: rgba(59,130,246,.14); }
#toast-host .toast-enter { transform: translateX(12px); opacity: 0; }
#toast-host .toast-show { transform: translateX(0); opacity: 1; }
#toast-host .toast-exit { transform: translateX(12px); opacity: 0; }
#toast-host .toast-accent {
  position: absolute; left: 0; top: 0; bottom: 0; width: 6px; border-radius: .5rem 0 0 .5rem;
}
#toast-host .toast-main {
  display: flex; align-items: center; gap: .85rem;
  flex: 1; min-width: 0;
  padding: .75rem .75rem .75rem 1.15rem;
}
#toast-host .toast-icon-wrap {
  flex-shrink: 0; width: 2rem; height: 2rem; border-radius: 999px;
  border: 1.5px solid; display: flex; align-items: center; justify-content: center;
  background: #fff;
}
.dark #toast-host .toast-icon-wrap { background: transparent; }
#toast-host .toast-body { min-width: 0; flex: 1; }
#toast-host .toast-title {
  font-size: 15px; font-weight: 600; line-height: 1.25; color: #0f172a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dark #toast-host .toast-title { color: #f1f5f9; }
#toast-host .toast-msg {
  font-size: 13px; line-height: 1.35; color: #9ca3af; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dark #toast-host .toast-msg { color: #94a3b8; }
#toast-host .toast-close-wrap {
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  width: 4.5rem; border-left: 1px solid #f1f5f9; margin-left: .25rem;
}
.dark #toast-host .toast-close-wrap { border-color: #334155; }
#toast-host .toast-close {
  font-size: 12px; font-weight: 500; letter-spacing: .06em; color: #cbd5e1;
  padding: .5rem .75rem; border-radius: .375rem; transition: color .15s, background .15s;
}
#toast-host .toast-close:hover { color: #475569; background: #f8fafc; }
.dark #toast-host .toast-close { color: #64748b; }
.dark #toast-host .toast-close:hover { color: #e2e8f0; background: rgba(255,255,255,.06); }
#toast-host .toast-bar {
  position: absolute; left: 6px; right: 0; bottom: 0; height: 3px;
  transform-origin: left; opacity: 1; border-radius: 0 0 .5rem 0;
}
#toast-host .toast-bar-run { animation: toastbar linear forwards; }
@keyframes toastbar { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (max-width: 640px) {
  #toast-host { bottom: .75rem; right: .75rem; left: .75rem; width: auto; }
  #toast-host .toast-close-wrap { width: 3.75rem; }
}

/* ---------- Loading overlay ---------- */
#loading-overlay { animation: overlayFade .2s ease; }
@keyframes overlayFade { from { opacity: 0; } to { opacity: 1; } }
#loading-overlay .overlay-card { transition: opacity .16s ease, transform .16s ease, scale .16s ease; }

/* ---------- Back to top ---------- */
#back-to-top {
  position: fixed; right: 1.25rem; bottom: 2.75rem; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem; border-radius: .75rem;
  background: #fff; color: #475569;
  box-shadow: 0 10px 24px -10px rgb(15 23 42 / .25);
  border: 1px solid #e2e8f0;
  opacity: 0; transform: translateY(8px) scale(.9); pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
#back-to-top.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.dark #back-to-top { background: #0f172a; color: #cbd5e1; border-color: #1e293b; }

/* ---------- Empty state icon float ---------- */
.empty-icon { animation: floaty 3.2s ease-in-out infinite; }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* ---------- Modal / drawer depth ---------- */
.modal-panel { box-shadow: 0 24px 60px -12px rgb(15 23 42 / .28); }
.drawer-panel { box-shadow: -24px 0 60px -12px rgb(15 23 42 / .18); border-left: 1px solid rgba(226,232,240,.6); }
.dark .drawer-panel { border-color: rgba(30,41,59,.6); }

/* ---------- Skeleton ---------- */
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skeleton { position: relative; overflow: hidden; background: rgba(148,163,184,.18); border-radius: .5rem; }
.skeleton::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
  animation: shimmer 1.4s infinite;
}

/* ---------- Filter & toolbar bars ---------- */
.filter-bar {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}
.filter-field { display: flex; min-width: 0; flex-direction: column; gap: .35rem; }
.filter-label {
  font-size: .6875rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: #94a3b8;
}
.dark .filter-label { color: #64748b; }
.filter-control {
  width: 100%; border: 0; border-radius: .625rem;
  background: #f1f5f9; color: #1e293b; padding: .5rem .75rem;
  font-size: .875rem; line-height: 1.25rem;
  box-shadow: inset 0 0 0 1px rgba(226,232,240,.95);
  transition: box-shadow .15s ease, background .15s ease;
}
.dark .filter-control { background: #1e293b; color: #f1f5f9; box-shadow: inset 0 0 0 1px rgba(51,65,85,.95); }
.filter-control:hover { box-shadow: inset 0 0 0 1px rgba(148,163,184,.55); }
.filter-control:focus {
  outline: none; background: #fff;
  box-shadow: inset 0 0 0 2px var(--brand-500);
}
.dark .filter-control:focus { background: #1e293b; }
.filter-control:disabled { opacity: .55; cursor: not-allowed; }
.toolbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.toolbar-actions .ml-auto { margin-left: auto; }
@media (min-width: 1024px) {
  .filter-bar-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filter-bar-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .filter-bar-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (max-width: 639px) {
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
  .toolbar-actions > .btn-block-sm { width: 100%; }
}
@media (max-width: 379px) {
  .filter-bar { grid-template-columns: 1fr; }
}
.filter-bar + .toolbar-actions { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid rgba(226,232,240,.8); }
.dark .filter-bar + .toolbar-actions { border-top-color: rgba(30,41,59,.9); }

/* ---------- Misc ---------- */
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
.dropzone.dragover { border-color: var(--brand-500) !important; background: rgba(var(--brand-rgb-500), .05) !important; }

/* ---------- Print ---------- */
@media print {
  aside, header, #toast-host, .no-print, #back-to-top, #route-progress, #bottom-nav, #sub-banner,
  .filter-bar, .toolbar-actions, #tr-tabs, #bc-tabs { display: none !important; }
  main { padding: 0 !important; }
  body { background: #fff !important; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none !important; }
}

/* ---------- Feeding report: expanded rows & side cards ---------- */
tr.row-on td { background: var(--brand-50); }
tr.row-on .caret { transform: rotate(90deg); }
.side-on { border-color: var(--brand-300) !important; box-shadow: 0 0 0 2px var(--brand-300); }
.dark tr.row-on td { background: rgba(var(--brand-rgb-500), .12); }
.dark .side-on { border-color: var(--brand-500) !important; box-shadow: 0 0 0 2px var(--brand-500); }

/* ---------- TableFlow: collapse overflowing columns, expand vertically ---------- */
table.tf-measuring { width: max-content !important; min-width: 0 !important; max-width: none !important; }
table.tf-flow { width: 100%; }
table.tf-flow th.tf-hide, table.tf-flow td.tf-hide { display: none; }
table.tf-flow td, table.tf-flow th { overflow-wrap: anywhere; }
table.tf-flow .tf-caret {
  width: 2.5rem; padding: .25rem !important; text-align: center;
  vertical-align: middle; white-space: nowrap;
}
table.tf-flow .tf-caret .tf-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.75rem; height: 1.75rem; border-radius: .5rem;
  border: 0; background: transparent; color: var(--color-slate-500, #64748b);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
table.tf-flow .tf-caret .tf-btn:hover { background: rgba(148, 163, 184, .18); color: var(--brand-600); }
table.tf-flow .tf-caret .tf-btn svg { transition: transform .2s ease; }
table.tf-flow tr.tf-open > .tf-caret .tf-btn { color: var(--brand-600); }
table.tf-flow tr.tf-open > .tf-caret .tf-btn svg { transform: rotate(180deg); }
table.tf-flow tr.tf-open > td:not(.tf-caret) { background: var(--brand-50); }
.dark table.tf-flow tr.tf-open > td:not(.tf-caret) { background: rgba(var(--brand-rgb-500), .12); }

table.tf-flow tr.tf-more { display: none; }
table.tf-flow tr.tf-open + tr.tf-more { display: table-row; }
table.tf-flow tr.tf-more > td {
  padding: .875rem !important;
  background: linear-gradient(to bottom, rgba(var(--brand-rgb-500), .05), rgba(var(--brand-rgb-500), .02));
}
.dark table.tf-flow tr.tf-more > td { background: rgba(var(--brand-rgb-500), .09); }
table.tf-flow .tf-grid {
  display: grid; gap: .625rem .875rem;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
}
table.tf-flow .tf-item { display: flex; flex-direction: column; gap: .125rem; min-width: 0; }
table.tf-flow .tf-label {
  font-size: .625rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--color-slate-400, #94a3b8);
}
.dark table.tf-flow .tf-label { color: #64748b; }
table.tf-flow .tf-value { font-size: .8125rem; color: #1e293b; overflow-wrap: anywhere; }
.dark table.tf-flow .tf-value { color: #e2e8f0; }

/* Show every column on print/export; hide the collapse controls */
@media print {
  table.tf-flow th.tf-hide, table.tf-flow td.tf-hide { display: table-cell !important; }
  table.tf-flow td.tf-hide, table.tf-flow th.tf-hide { color: inherit; }
  table.tf-flow .tf-caret, table.tf-flow tr.tf-more { display: none !important; }
  table.tf-flow td, table.tf-flow th { overflow-wrap: normal; }
  table.tf-flow tr.tf-open > td:not(.tf-caret) { background: transparent; }
}