/*
 * ════════════════════════════════════════════════════════════════════════════
 *  TIME-MACHINE DESIGN SYSTEM
 *  Single source of truth for every UI component.
 *  Define once · Use everywhere · Never repeat.
 *
 *  Load order in HTML:
 *    1. design-system.css  ← this file (all tokens + components)
 *    2. portal-shell.css   ← sidebar / desktop topbar only (portal.html)
 *  No other CSS files should duplicate component definitions.
 * ════════════════════════════════════════════════════════════════════════════
 */

/* ╔══════════════════════════════════════════════════════════════════════════╗
   ║  1. DESIGN TOKENS                                                        ║
   ╚══════════════════════════════════════════════════════════════════════════╝ */
   :root {
    /* ══════════════════════════════════════════════════════
       CANONICAL TOKENS — single source of truth
       Use these in all new code.
    ══════════════════════════════════════════════════════ */

    /* ── Primary colour ── */
    --color-primary:       #198754;   /* ← THE one green, used everywhere */
    --color-primary-dark:  #146c43;
    --color-primary-hover: #157347;
    --color-primary-light: #ecfdf5;
    --color-primary-soft:  rgba(25,135,84,0.10);

    /* ── Brand ── */
    --clr-green:        #198754;
    --clr-green-dark:   #146c43;
    --clr-green-light:  #d1fae5;
    --clr-teal:         #0f9d8a;

    /* ── Semantic ── */
    --clr-blue:         #3b82f6;
    --clr-blue-dark:    #2563eb;
    --clr-amber:        #f59e0b;
    --clr-amber-dark:   #d97706;
    --clr-red:          #ef4444;
    --clr-red-dark:     #dc2626;
    --clr-purple:       #8b5cf6;

    /* ── Neutral Scale ── */
    --clr-slate:        #0f172a;
    --clr-slate-700:    #334155;
    --clr-slate-600:    #475569;
    --clr-slate-500:    #64748b;
    --clr-slate-400:    #94a3b8;
    --clr-slate-300:    #cbd5e1;
    --clr-slate-200:    #e2e8f0;
    --clr-slate-100:    #f1f5f9;
    --clr-white:        #ffffff;

    /* ── Surface ── */
    --clr-bg:           #eef1f4;
    --clr-line:         #dbe5ef;
    --clr-glass:        rgba(255,255,255,0.92);
    --clr-glass-border: rgba(255,255,255,0.5);

    /* ── Border Radius ── */
    --radius-xl:        18px;
    --radius-lg:        14px;
    --radius-md:        10px;
    --radius-sm:        8px;
    --radius-xs:        6px;
    --radius-pill:      999px;

    /* ── Shadows ── */
    --shadow-sm:        0 2px 8px rgba(15,23,42,0.05);
    --shadow-md:        0 4px 20px rgba(15,23,42,0.07);
    --shadow-lg:        0 8px 32px rgba(15,23,42,0.10);
    --shadow-xl:        0 20px 60px rgba(15,23,42,0.18);

    /* ── Typography ── */
    --font-body:        "Plus Jakarta Sans", system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-sans:        var(--font-body);
    --text-xs:          0.68rem;
    --text-sm:          0.78rem;
    --text-base:        0.88rem;
    --text-md:          1rem;
    --text-lg:          1.1rem;
    --text-xl:          1.25rem;

    /* ── Spacing scale (8px base) ── */
    --space-half:       4px;
    --space-1:          8px;
    --space-2:          16px;
    --space-3:          24px;
    --space-4:          32px;
    --space-5:          40px;
    --space-6:          48px;
    --space-8:          64px;

    /* ── Transitions ── */
    --tx:               0.18s cubic-bezier(0.4, 0, 0.2, 1);
    --tx-fast:          0.12s ease;

    /* ── Component Sizes ── */
    --btn-h:            40px;
    --input-h:          42px;
    --topbar-h:         64px;

    /* ── Backward-compat aliases (legacy variable names still work) ── */
    --green:            var(--color-primary);
    --green-dark:       var(--color-primary-dark);
    --green-light:      var(--clr-green-light);
    --teal:             var(--clr-teal);
    --slate:            var(--clr-slate);
    --slate-700:        var(--clr-slate-700);
    --slate-600:        var(--clr-slate-600);
    --slate-400:        var(--clr-slate-400);
    --slate-200:        var(--clr-slate-200);
    --slate-100:        var(--clr-slate-100);
    --bg:               var(--clr-bg);
    --line:             var(--clr-line);
    --dark:             var(--clr-slate);
    --blue:             var(--clr-blue);
    --amber:            var(--clr-amber);
    --red:              var(--clr-red);
    --purple:           var(--clr-purple);
  
    /* app-ui.css aliases */
    --app-green:        var(--clr-green);
    --app-green-dark:   var(--clr-green-dark);
    --app-green-light:  var(--clr-green-light);
    --app-teal:         var(--clr-teal);
    --app-slate:        var(--clr-slate);
    --app-slate-700:    var(--clr-slate-700);
    --app-slate-600:    var(--clr-slate-600);
    --app-slate-400:    var(--clr-slate-400);
    --app-slate-300:    var(--clr-slate-300);
    --app-slate-200:    var(--clr-slate-200);
    --app-slate-100:    var(--clr-slate-100);
    --app-bg:           var(--clr-bg);
    --app-line:         var(--clr-line);
    --app-white:        var(--clr-white);
    --app-red:          var(--clr-red);
    --app-amber:        var(--clr-amber);
    --app-blue:         var(--clr-blue);
    --app-radius:       var(--radius-xl);
    --app-radius-sm:    var(--radius-md);
    --app-shadow:       var(--shadow-md);
    --app-transition:   var(--tx);
    --app-glass-bg:     var(--clr-glass);
    --app-glass-border: var(--clr-glass-border);
  
    /* theme.css aliases */
    --tm-green:         var(--clr-green);
    --tm-green-dark:    var(--clr-green-dark);
    --tm-green-light:   var(--clr-green-light);
    --tm-teal:          var(--clr-teal);
    --tm-slate:         var(--clr-slate);
    --tm-slate-700:     var(--clr-slate-700);
    --tm-slate-600:     var(--clr-slate-600);
    --tm-slate-400:     var(--clr-slate-400);
    --tm-slate-200:     var(--clr-slate-200);
    --tm-bg:            var(--clr-bg);
    --tm-line:          var(--clr-line);
    --tm-radius-lg:     var(--radius-xl);
    --tm-radius-md:     var(--radius-md);
    --tm-shadow:        var(--shadow-md);
  }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  2. RESET & BASE                                                         ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  *, *::before, *::after { box-sizing: border-box; }
  
  html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
  }
  
  body {
    margin: 0;
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--clr-slate);
    background: var(--clr-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
  }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  3. ANIMATIONS                                                           ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  @keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  @keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
  @keyframes slideUp {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
  }
  @keyframes spin {
    to { transform: rotate(360deg); }
  }
  
  .anim-fade-up  { animation: fadeUp  0.25s ease both; }
  .anim-fade-in  { animation: fadeIn  0.2s  ease both; }
  .anim-slide-up { animation: slideUp 0.28s cubic-bezier(0.22, 0.68, 0, 1.2) both; }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  4. PAGE CHROME                                                          ║
     ║     top-accent · page-header · breadcrumb · page-title · tabs           ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  
  /* ── 4a. Top Accent Bar ─────────────────────────────────────── */
  .top-accent {
    height: 5px;
    background: linear-gradient(90deg, var(--clr-green), var(--clr-teal));
    flex-shrink: 0;
  }
  
  /* ── 4b. Page Header ────────────────────────────────────────── */
  .page-header {
    background: var(--clr-white);
    border-bottom: 1px solid var(--clr-line);
    box-shadow: 0 1px 6px rgba(15,23,42,0.05);
    position: sticky;
    top: 0;
    z-index: 50;
  }
  
  /* When embedded inside portal (no need for sticky) */
  [data-portal-shell] .page-header { position: static; }
  
  .page-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 22px;
    flex-wrap: wrap;
    width: 100%;
  }
  
  /* Left column: breadcrumb + title stack */
  .page-header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }
  
  /* Right column: action buttons */
  .page-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
  }
  
  /* ── 4c. Breadcrumb ─────────────────────────────────────────── */
  .breadcrumb {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--clr-slate-400);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  
  .breadcrumb a {
    color: var(--clr-green);
    text-decoration: none;
    transition: opacity var(--tx-fast);
  }
  
  .breadcrumb a:hover { opacity: 0.75; }
  
  .breadcrumb .bc-sep {
    color: var(--clr-slate-300);
    font-size: 0.6rem;
  }
  
  .breadcrumb .bc-curr { color: var(--clr-slate-600); }
  
  /* ── 4d. Page Title / Subtitle ──────────────────────────────── */
  .page-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--clr-slate);
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.2;
  }
  
  .page-title .title-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--clr-green), var(--clr-teal));
    flex-shrink: 0;
  }
  
  .page-subtitle {
    margin: 2px 0 0;
    font-size: var(--text-sm);
    color: var(--clr-slate-500);
  }
  
  /* ── 4e. Page Kicker (badge-like label in header) ───────────── */
  .page-kicker {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    border: 1px solid #bbf7d0;
    background: #ecfdf5;
    color: #166534;
    font-size: var(--text-xs);
    font-weight: 800;
  }
  
  /* ── 4f. Page Body ──────────────────────────────────────────── */
  .page-body {
    padding: 18px 22px 80px;
    width: 100%;
  }
  
  /* ── 4g. Page Stack / Grid ──────────────────────────────────── */
  .page-stack { display: flex; flex-direction: column; gap: 16px; }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  5. TAB NAVIGATION                                                       ║
     ║     Two canonical styles: underline-tabs & pill-tabs                     ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  
  /* ── 5a. Underline Tabs ─────────────────────────────────────── */
  /* Use when tabs sit at the bottom of a page-header or card-header */
  .u-tabs {
    display: flex;
    gap: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .u-tabs::-webkit-scrollbar { display: none; }
  
  .u-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px 10px;
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--clr-slate-500);
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2.5px solid transparent;
    white-space: nowrap;
    transition: color var(--tx-fast), border-color var(--tx-fast), background var(--tx-fast);
    line-height: 1;
  }
  
  .u-tab:hover { color: var(--clr-green); }
  
  .u-tab.active {
    color: var(--clr-green);
    border-bottom-color: var(--clr-green);
    background: rgba(25,135,84,0.04);
  }
  
  .u-tab i { font-size: 0.85em; }
  
  /* ── 5b. Pill Tabs ──────────────────────────────────────────── */
  /* Use for inline section switchers inside a page */
  .p-tabs {
    display: inline-flex;
    gap: 4px;
    background: var(--clr-slate-100);
    border: 1px solid var(--clr-slate-200);
    border-radius: var(--radius-pill);
    padding: 4px;
  }
  
  .p-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--clr-slate-600);
    border: none;
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--tx);
  }
  
  .p-tab.active {
    background: var(--clr-white);
    color: var(--clr-slate);
    box-shadow: 0 1px 6px rgba(15,23,42,0.1);
  }
  
  .p-tab:hover:not(.active) { background: rgba(255,255,255,0.5); }
  
  /* ── 5c. Chip Tabs (top-level navigation, green fill) ───────── */
  .c-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }
  
  .c-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: var(--clr-slate-100);
    color: var(--clr-slate-600);
    transition: all var(--tx);
  }
  
  .c-tab.active {
    background: var(--clr-green);
    color: var(--clr-white);
    box-shadow: 0 2px 8px rgba(25,135,84,0.25);
  }
  
  .c-tab:hover:not(.active) {
    background: var(--clr-slate-200);
    color: var(--clr-slate);
  }
  
  /* ── 5d. Tab Panel Content ──────────────────────────────────── */
  .tab-panel           { display: none; }
  .tab-panel.active    { display: block; animation: fadeUp 0.22s ease both; }
  .tab-section         { display: none; }
  .tab-section.active  { display: block; animation: fadeUp 0.22s ease both; }
  .sub-section         { display: none; }
  .sub-section.active  { display: block; animation: fadeUp 0.2s ease both; }
  
  /* Backward-compat: legacy tab classes that different pages used */
  /* hub-tabs  → u-tabs  style */
  .hub-tabs { display: flex; gap: 0; overflow-x: auto; scrollbar-width: none; }
  .hub-tabs::-webkit-scrollbar { display: none; }
  .hub-tab {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px 10px; font-family: inherit; font-size: var(--text-sm);
    font-weight: 700; color: var(--clr-slate-500); border: none; background: none;
    cursor: pointer; border-bottom: 2.5px solid transparent; white-space: nowrap;
    transition: color var(--tx-fast), border-color var(--tx-fast), background var(--tx-fast);
  }
  .hub-tab:hover { color: var(--clr-green); }
  .hub-tab.active { color: var(--clr-green); border-bottom-color: var(--clr-green); background: rgba(25,135,84,0.04); }
  
  /* tab-bar  → u-tabs style */
  .tab-bar { display: flex; gap: 0; overflow-x: auto; scrollbar-width: none; }
  .tab-bar::-webkit-scrollbar { display: none; }
  .tab-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px 10px; font-family: inherit; font-size: var(--text-sm);
    font-weight: 700; color: var(--clr-slate-500); border: none; background: none;
    cursor: pointer; border-bottom: 2.5px solid transparent; white-space: nowrap;
    transition: color var(--tx-fast), border-color var(--tx-fast), background var(--tx-fast);
  }
  .tab-btn:hover { color: var(--clr-green); }
  .tab-btn.active { color: var(--clr-green); border-bottom-color: var(--clr-green); background: rgba(25,135,84,0.04); }
  
  /* page-tabs → p-tabs style */
  .page-tabs {
    display: inline-flex; gap: 4px;
    background: var(--clr-slate-100); border: 1px solid var(--clr-slate-200);
    border-radius: var(--radius-pill); padding: 4px;
  }
  .page-tab {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 18px; border-radius: var(--radius-pill);
    font-family: inherit; font-size: var(--text-sm); font-weight: 700;
    color: var(--clr-slate-600); border: none; background: transparent; cursor: pointer;
    white-space: nowrap; transition: all var(--tx);
  }
  .page-tab.active {
    background: var(--clr-white); color: var(--clr-slate);
    box-shadow: 0 1px 6px rgba(15,23,42,0.1);
  }
  
  /* app-tabs → c-tabs style */
  .app-tabs {
    display: flex; gap: 4px;
    padding: 10px 16px; background: var(--clr-white);
    border-bottom: 1px solid var(--clr-slate-200);
    position: sticky; top: var(--topbar-h); z-index: 40;
    box-shadow: 0 1px 4px rgba(15,23,42,0.05);
    overflow-x: auto; scrollbar-width: none;
  }
  .app-tabs::-webkit-scrollbar { display: none; }
  [data-portal-shell] .app-tabs { top: 0 !important; }
  .app-tab {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 16px; border-radius: var(--radius-pill);
    font-family: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer; border: none; background: var(--clr-slate-100);
    color: var(--clr-slate-600); transition: all var(--tx);
  }
  .app-tab.active { background: var(--clr-green); color: var(--clr-white); box-shadow: 0 2px 8px rgba(25,135,84,0.25); }
  .app-tab:hover:not(.active) { background: var(--clr-slate-200); color: var(--clr-slate); }
  
  /* Sub-tab bar (underline inside a card) */
  .sub-tab-bar {
    display: flex; gap: 6px;
    border-bottom: 1px solid var(--clr-slate-200);
    padding-bottom: 0; margin-bottom: 20px;
    overflow-x: auto; scrollbar-width: none;
  }
  .sub-tab-bar::-webkit-scrollbar { display: none; }
  .sub-tab-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px 9px;
    font-family: inherit; font-size: 13px; font-weight: 600;
    color: var(--clr-slate-600); border: none; background: none; cursor: pointer;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
    white-space: nowrap; transition: all var(--tx);
  }
  .sub-tab-btn.active { color: var(--clr-green); border-bottom-color: var(--clr-green); }
  .sub-tab-btn:hover:not(.active) { color: var(--clr-slate); }
  
  /* Mini-nav (pill-style link nav in page headers) */
  .mini-nav { display: flex; gap: 6px; flex-wrap: wrap; }
  .mini-nav a, .admin-mini-nav a {
    display: inline-flex; align-items: center; gap: 5px;
    text-decoration: none; padding: 5px 12px;
    border: 1px solid var(--clr-slate-200); border-radius: var(--radius-pill);
    background: #f8fafc; color: var(--clr-slate-600);
    font-size: var(--text-sm); font-weight: 700;
    transition: all var(--tx-fast);
  }
  .mini-nav a:hover, .admin-mini-nav a:hover { border-color: var(--clr-green); color: var(--clr-green); }
  .mini-nav a.active, .admin-mini-nav a.active {
    border-color: #86efac; color: #166534; background: #ecfdf5;
  }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  6. CARDS & SURFACES                                                     ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  
  /* ── 6a. Base Card (glass-morphism) ─────────────────────────── */
  .card {
    background: var(--clr-glass);
    border: 1px solid var(--clr-glass-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    padding: 24px 28px;
    overflow: visible;
  }
  
  .card + .card { margin-top: 16px; }
  
  /* ── 6b. Card Panel (solid white, no blur) ──────────────────── */
  .card-panel {
    background: var(--clr-white);
    border: 1px solid var(--clr-slate-200);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    padding: 24px 28px;
    margin-bottom: 18px;
  }
  
  /* ── 6c. Card / Panel Header ────────────────────────────────── */
  .card-header,
  .card-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--clr-line);
  }
  
  .card-title,
  .card-panel-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--clr-slate);
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 0;
  }
  
  .card-title i,
  .card-panel-title i { color: var(--clr-green); }
  
  /* ── 6d. KPI Card ───────────────────────────────────────────── */
  .kpi-card {
    background: var(--clr-white);
    border: 1px solid var(--clr-slate-200);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    box-shadow: var(--shadow-sm);
    border-top: 3px solid var(--clr-slate-200);
    transition: box-shadow var(--tx), transform var(--tx);
  }
  
  .kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
  
  /* Color variants */
  .kpi-card.kpi-blue   { border-top-color: var(--clr-blue); }
  .kpi-card.kpi-green  { border-top-color: var(--clr-green); }
  .kpi-card.kpi-amber  { border-top-color: var(--clr-amber); }
  .kpi-card.kpi-red    { border-top-color: var(--clr-red); }
  .kpi-card.kpi-purple { border-top-color: var(--clr-purple); }
  
  /* backward compat */
  .kpi-blue   { border-top-color: var(--clr-blue) !important; }
  .kpi-green  { border-top-color: var(--clr-green) !important; }
  .kpi-amber  { border-top-color: var(--clr-amber) !important; }
  .kpi-red    { border-top-color: var(--clr-red) !important; }
  .kpi-purple { border-top-color: var(--clr-purple) !important; }
  
  .kpi-label {
    font-size: var(--text-xs);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--clr-slate-400);
    margin-bottom: 4px;
  }
  
  .kpi-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--clr-slate);
    line-height: 1.1;
  }
  
  .kpi-sub {
    font-size: var(--text-xs);
    color: var(--clr-slate-400);
    margin-top: 3px;
  }
  
  /* ── 6e. KPI Grid ───────────────────────────────────────────── */
  .kpi-grid { display: grid; gap: 14px; }
  .kpi-grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kpi-grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .kpi-grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .kpi-grid.cols-5 { grid-template-columns: repeat(5, minmax(0,1fr)); }
  
  /* backward-compat */
  .kpi-bar { display: grid; gap: 14px; }
  
  /* ── 6f. Section Grid ───────────────────────────────────────── */
  .section-grid { display: grid; gap: 16px; }
  .section-grid.cols-2 { grid-template-columns: minmax(0,1fr) minmax(260px,320px); }
  
  /* backward-compat */
  .tm-section-grid { display: grid; gap: 16px; }
  .tm-section-grid.cols-2 { grid-template-columns: minmax(0,1fr) minmax(260px,320px); }
  .tm-kpi-grid { display: grid; gap: 12px; }
  .tm-kpi-grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .tm-kpi-grid.cols-5 { grid-template-columns: repeat(5, minmax(0,1fr)); }
  
  /* ── 6g. Summary Card ───────────────────────────────────────── */
  .summary-card {
    background: var(--clr-white);
    border: 1px solid var(--clr-slate-200);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    padding: 20px 24px;
  }
  
  /* ── 6h. Glass Card (alternate name used by results.html) ───── */
  .glass-card {
    background: var(--clr-glass);
    border: 1px solid var(--clr-glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 18px 22px;
    margin-bottom: 16px;
  }
  
  /* ── 6i. Topbar Surface ─────────────────────────────────────── */
  .app-topbar,
  .top-bar {
    background: var(--clr-white);
    border-bottom: 1px solid var(--clr-line);
    box-shadow: 0 1px 6px rgba(15,23,42,0.05);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 50;
    width: 100%;
  }
  [data-portal-shell] .app-topbar { display: none; }
  
  .app-topbar-left,
  .top-bar-left { display: flex; flex-direction: column; gap: 1px; }
  
  .app-title,
  .top-bar-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--clr-slate);
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .app-subtitle,
  .top-bar-sub {
    font-size: var(--text-sm);
    color: var(--clr-slate-400);
    margin-top: 1px;
  }
  
  .app-breadcrumb,
  .bc {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--clr-slate-400);
    margin-bottom: 2px;
  }
  .app-breadcrumb a, .bc a { color: var(--clr-green); text-decoration: none; }
  .app-breadcrumb a:hover, .bc a:hover { opacity: 0.75; }
  .app-breadcrumb .bc-sep, .bc .sep { color: var(--clr-slate-300); font-size: 0.6rem; }
  .app-breadcrumb .bc-current, .bc .cur { color: var(--clr-slate-600); }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  7. BUTTONS                                                              ║
     ║     One base class (.btn) + modifier classes                             ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  
  /* ── 7a. Base Button ─────────────────────────────────────────── */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: var(--btn-h);
    padding: 9px 20px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: 600;
    cursor: pointer;
    border: 1.5px solid transparent;
    text-decoration: none;
    white-space: nowrap;
    transition: all var(--tx);
    position: relative;
    vertical-align: middle;
    line-height: 1;
  }
  
  .btn:disabled,
  .btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }
  
  /* ── 7b. Primary (Green) ────────────────────────────────────── */
  .btn-primary,
  .btn-green {
    background: var(--clr-green);
    color: var(--clr-white);
    border-color: var(--clr-green);
  }
  .btn-primary:hover:not(:disabled),
  .btn-green:hover:not(:disabled) {
    background: var(--clr-green-dark);
    border-color: var(--clr-green-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(25,135,84,0.28);
    color: var(--clr-white);
  }
  
  /* backward-compat gradient variant */
  .btn-green-solid {
    background: var(--clr-green);
    color: var(--clr-white);
    border-color: var(--clr-green);
    display: inline-flex; align-items: center; gap: 7px;
    min-height: var(--btn-h); padding: 9px 20px;
    border-radius: var(--radius-md); font-family: inherit;
    font-size: var(--text-base); font-weight: 600; cursor: pointer;
    text-decoration: none; transition: all var(--tx);
  }
  .btn-green-solid:hover { background: var(--clr-green-dark); border-color: var(--clr-green-dark); color: var(--clr-white); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(25,135,84,0.28); }
  
  .btn-green-sm {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 16px; border: none; border-radius: var(--radius-md);
    background: var(--clr-green); color: var(--clr-white);
    font-family: inherit; font-size: var(--text-sm); font-weight: 700;
    cursor: pointer; text-decoration: none; transition: all var(--tx);
    min-height: 36px;
  }
  .btn-green-sm:hover { background: var(--clr-green-dark); color: var(--clr-white); transform: translateY(-1px); }
  
  /* ── 7c. Secondary (Ghost / Outline) ───────────────────────── */
  .btn-secondary,
  .btn-ghost,
  .btn-outline {
    background: var(--clr-white);
    color: var(--clr-slate-600);
    border-color: var(--clr-slate-200);
  }
  .btn-secondary:hover:not(:disabled),
  .btn-ghost:hover:not(:disabled),
  .btn-outline:hover:not(:disabled) {
    border-color: var(--clr-green);
    color: var(--clr-green);
    background: var(--clr-green-light);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(25,135,84,0.12);
  }
  
  /* ── 7d. Blue ───────────────────────────────────────────────── */
  .btn-blue {
    background: var(--clr-blue);
    color: var(--clr-white);
    border-color: var(--clr-blue);
  }
  .btn-blue:hover:not(:disabled) {
    background: var(--clr-blue-dark);
    border-color: var(--clr-blue-dark);
    transform: translateY(-1px);
    color: var(--clr-white);
  }
  
  /* gradient blue (used for resources/quiz) */
  .btn-resources,
  .btn-resources-save,
  .btn-quiz-gen {
    display: inline-flex; align-items: center; gap: 7px;
    min-height: var(--btn-h); padding: 9px 20px;
    border-radius: var(--radius-md); font-family: inherit;
    font-size: var(--text-base); font-weight: 700;
    cursor: pointer; border: none;
    background: linear-gradient(135deg, #0ea5e9, #6366f1);
    color: var(--clr-white); transition: all var(--tx);
  }
  .btn-resources:hover, .btn-resources-save:hover, .btn-quiz-gen:hover {
    filter: brightness(1.07); transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(99,102,241,0.3); color: var(--clr-white);
  }
  
  /* ── 7e. Danger (Red) ───────────────────────────────────────── */
  .btn-danger {
    background: var(--clr-red);
    color: var(--clr-white);
    border-color: var(--clr-red);
  }
  .btn-danger:hover:not(:disabled) {
    background: var(--clr-red-dark);
    border-color: var(--clr-red-dark);
    transform: translateY(-1px);
    color: var(--clr-white);
  }
  
  /* ── 7f. Amber ──────────────────────────────────────────────── */
  .btn-amber {
    background: var(--clr-amber);
    color: var(--clr-white);
    border-color: var(--clr-amber);
  }
  .btn-amber:hover:not(:disabled) {
    background: var(--clr-amber-dark);
    border-color: var(--clr-amber-dark);
    transform: translateY(-1px);
    color: var(--clr-white);
  }
  
  /* ── 7g. Dark ───────────────────────────────────────────────── */
  .btn-dark,
  .btn-dark-sm {
    background: var(--clr-slate);
    color: var(--clr-white);
    border-color: var(--clr-slate);
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; border-radius: var(--radius-sm);
    font-family: inherit; font-size: var(--text-sm); font-weight: 600;
    cursor: pointer; transition: background var(--tx-fast);
    text-decoration: none; min-height: 32px;
  }
  .btn-dark:hover, .btn-dark-sm:hover { background: #1e293b; color: var(--clr-white); }
  
  /* ── 7h. Size Modifiers ─────────────────────────────────────── */
  .btn.btn-sm { min-height: 34px; padding: 6px 14px; font-size: var(--text-sm); gap: 5px; }
  .btn.btn-lg { min-height: 48px; padding: 12px 28px; font-size: var(--text-md); }
  .btn.btn-block { width: 100%; }
  
  /* ── 7i. Icon-Only Button ───────────────────────────────────── */
  .btn-icon,
  .abtn,
  .dt-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--clr-slate-200);
    background: #f8fafc;
    color: var(--clr-slate-500);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all var(--tx-fast);
    flex-shrink: 0;
  }
  .btn-icon:hover,
  .abtn:hover,
  .dt-icon-btn:hover {
    background: #f0fdf4;
    border-color: #86efac;
    color: var(--clr-green);
  }
  
  /* ── 7j. Copy Button ────────────────────────────────────────── */
  .btn-copy {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 16px; min-height: var(--btn-h);
    background: var(--clr-white);
    border: 1.5px solid var(--clr-slate-200);
    border-radius: var(--radius-md);
    font-family: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer; color: var(--clr-slate-600);
    transition: all var(--tx); white-space: nowrap;
  }
  .btn-copy:hover { border-color: var(--clr-green); color: var(--clr-green); }
  .btn-copy.copied { border-color: var(--clr-green); color: var(--clr-green); background: var(--clr-green-light); }
  
  /* ── 7k. Dashed Add Button ──────────────────────────────────── */
  .btn-add {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 7px 14px; border-radius: var(--radius-md);
    border: 1.5px dashed var(--clr-slate-200); background: transparent;
    color: var(--clr-slate-400); font-family: inherit; font-size: var(--text-sm);
    font-weight: 700; cursor: pointer; transition: all var(--tx); width: 100%;
  }
  .btn-add:hover { border-color: var(--clr-green); color: var(--clr-green); background: #f0fdf4; }
  
  /* ── 7l. Loading State ──────────────────────────────────────── */
  .btn .spinner-sm {
    width: 15px; height: 15px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
    display: none;
  }
  .btn.loading .spinner-sm { display: block; }
  .btn.loading .btn-label { display: none; }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  8. FORMS                                                                ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  
  /* ── 8a. Form Group ─────────────────────────────────────────── */
  .form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }
  
  /* ── 8b. Labels ─────────────────────────────────────────────── */
  .form-label,
  label.form-label {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--clr-slate);
    margin-bottom: 0;
  }
  
  /* ── 8c. Inputs / Selects / Textareas ───────────────────────── */
  .form-input,
  .form-select,
  input.form-control,
  select.form-control,
  textarea.form-control {
    width: 100%;
    min-height: var(--input-h);
    padding: 9px 14px;
    border: 1.5px solid var(--clr-slate-200);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--clr-slate);
    background: var(--clr-white);
    outline: none;
    transition: border-color var(--tx), box-shadow var(--tx);
    appearance: none;
  }
  
  .form-input:focus,
  .form-select:focus,
  input.form-control:focus,
  select.form-control:focus,
  textarea.form-control:focus {
    border-color: var(--clr-green);
    box-shadow: 0 0 0 3px rgba(25,135,84,0.12);
  }
  
  .form-select,
  select.form-control { cursor: pointer; }
  
  textarea.form-control { min-height: 90px; resize: vertical; }
  
  /* Readonly */
  .form-readonly,
  .ro {
    background: var(--clr-slate-100) !important;
    color: var(--clr-slate-600) !important;
    cursor: default !important;
  }
  
  /* Date input alignment */
  input[type="date"].form-control,
  input[type="date"].form-input {
    min-height: 42px;
    font-size: 0.88rem;
    font-weight: 600;
  }
  
  /* ── 8d. Form Row / Grid ────────────────────────────────────── */
  .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
  
  .form-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 14px 16px;
    align-items: start;
  }
  
  /* Span helpers */
  .fg-12 { grid-column: span 12; }
  .fg-8  { grid-column: span 8; }
  .fg-6  { grid-column: span 6; }
  .fg-4  { grid-column: span 4; }
  .fg-3  { grid-column: span 3; }
  .fg-2  { grid-column: span 2; }
  
  /* ── 8e. Form Section Divider ───────────────────────────────── */
  .form-divider,
  .form-section-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    grid-column: span 12;
    margin: 2px 0;
  }
  
  .form-divider span,
  .form-section-divider span {
    font-size: var(--text-xs);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--clr-slate-400);
    white-space: nowrap;
  }
  
  .form-divider::after,
  .form-section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--clr-slate-200);
  }
  
  /* ── 8f. Form Actions Row ───────────────────────────────────── */
  .form-actions,
  .form-actions-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    grid-column: span 12;
    padding-top: 6px;
    border-top: 1px solid var(--clr-slate-200);
  }
  
  /* ── 8g. Link Input (URL fields) ────────────────────────────── */
  .link-box { display: flex; gap: 8px; align-items: stretch; }
  .link-input {
    flex: 1;
    padding: 9px 14px;
    background: var(--clr-slate-100);
    border: 1.5px solid var(--clr-slate-200);
    border-radius: var(--radius-md);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
    color: var(--clr-slate-700);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  /* ── 8h. Custom Select Dropdown ─────────────────────────────── */
  .select-wrap { position: relative; width: 100%; }
  .select-wrap .select-display {
    width: 100%; min-height: var(--input-h); padding: 9px 36px 9px 14px;
    border: 1.5px solid var(--clr-slate-200); border-radius: var(--radius-md);
    font-family: inherit; font-size: 0.9rem; color: var(--clr-slate);
    background: var(--clr-white); outline: none; cursor: pointer;
    display: flex; align-items: center; justify-content: space-between;
    user-select: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: border-color var(--tx), box-shadow var(--tx);
  }
  .select-wrap.open .select-display,
  .select-wrap .select-display:focus {
    border-color: var(--clr-green);
    box-shadow: 0 0 0 3px rgba(25,135,84,0.12);
  }
  .select-wrap .select-chevron {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    color: var(--clr-slate-400); font-size: 0.75rem; pointer-events: none;
    transition: transform var(--tx);
  }
  .select-wrap.open .select-chevron { transform: translateY(-50%) rotate(180deg); }
  .select-wrap .select-panel {
    display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: var(--clr-white); border: 1.5px solid var(--clr-green);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(15,23,42,0.13);
    z-index: 9999; max-height: 220px; overflow-y: auto;
  }
  .select-wrap .select-panel.open { display: block; }
  .select-wrap .select-option {
    padding: 9px 14px; font-size: 13px; color: var(--clr-slate-700);
    cursor: pointer; border-bottom: 1px solid var(--clr-slate-100);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: background var(--tx-fast);
  }
  .select-wrap .select-option:last-child { border-bottom: none; }
  .select-wrap .select-option:hover { background: var(--clr-green-light); color: var(--clr-green-dark); }
  .select-wrap .select-option.selected { background: var(--clr-green-light); color: var(--clr-green-dark); font-weight: 700; }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  9. STATUS BADGES & CHIPS                                                ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  
  /* ── 9a. Status Chips (session states) ──────────────────────── */
  .chip,
  .course-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.76rem;
    font-weight: 700;
    white-space: nowrap;
  }
  
  /* Planned → blue */
  .chip-planned  { background: #dbeafe; color: #1d4ed8; }
  /* In Progress → amber */
  .chip-progress { background: #fef3c7; color: #b45309; }
  /* Completed → green */
  .chip-completed,
  .chip-done     { background: #dcfce7; color: #15803d; }
  /* Cancelled → gray */
  .chip-cancelled { background: #f1f5f9; color: var(--clr-slate-500); }
  
  /* Dashboard dot variants (k-plan etc) */
  .k-plan   .kpi-value { color: var(--clr-blue); }
  .k-prog   .kpi-value { color: var(--clr-amber); }
  .k-done   .kpi-value { color: var(--clr-green); }
  .k-cancel .kpi-value { color: var(--clr-slate-400); }
  
  /* ── 9b. Stat Pills (summary row) ───────────────────────────── */
  .stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 700;
    border: 1px solid transparent;
  }
  
  .sp-blue   { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
  .sp-green  { background: #f0fdf4; color: #166534; border-color: #86efac; }
  .sp-amber  { background: #fffbeb; color: #92400e; border-color: #fde68a; }
  .sp-red    { background: #fef2f2; color: #dc2626; border-color: #fca5a5; }
  .sp-purple { background: #faf5ff; color: #6b21a8; border-color: #d8b4fe; }
  
  .stats-row { display: flex; flex-wrap: wrap; gap: 8px; }
  
  /* ── 9c. Generic Badges ─────────────────────────────────────── */
  .badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-xs);
    font-size: 0.72rem;
    font-weight: 800;
    white-space: nowrap;
  }
  
  .badge-green  { background: #dcfce7; color: #15803d; }
  .badge-blue   { background: #dbeafe; color: #1d4ed8; }
  .badge-amber  { background: #fef3c7; color: #b45309; }
  .badge-red    { background: #fee2e2; color: #dc2626; }
  .badge-purple { background: #ede9fe; color: #6b21a8; }
  .badge-gray   { background: var(--clr-slate-100); color: var(--clr-slate-500); }
  
  /* Score & status badges used in results tables */
  .score-badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 800;
  }
  .status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.73rem;
    font-weight: 800;
  }
  
  /* GST/Finance pills */
  .gst-pill {
    display: flex; flex-direction: column; gap: 3px;
    background: var(--clr-slate-100); border: 1.5px solid var(--clr-slate-200);
    border-radius: var(--radius-md); padding: 9px 14px;
  }
  .gst-pill.final {
    background: linear-gradient(90deg, #f0fdf4, #eff6ff);
    border-color: #bbf7d0;
  }
  .gst-pill .gl {
    font-size: var(--text-xs); font-weight: 800; text-transform: uppercase;
    letter-spacing: 0.07em; color: var(--clr-slate-400);
  }
  .gst-pill .gv {
    font-size: 1rem; font-weight: 800; color: var(--clr-slate);
  }
  .gst-pill.final .gv { color: var(--clr-green-dark); font-size: 1.1rem; }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  10. TABLES                                                              ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  .tbl-wrap,
  .table-wrap,
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
  }
  
  .res-table,
  .tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
  }
  
  .res-table thead th,
  .tbl thead th {
    background: #f8fafc;
    padding: 9px 12px;
    font-weight: 800;
    color: var(--clr-slate-700);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--clr-slate-200);
    position: sticky;
    top: 0;
    z-index: 2;
    white-space: nowrap;
  }
  
  .res-table tbody td,
  .tbl tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--clr-slate-100);
    color: var(--clr-slate-700);
    vertical-align: middle;
  }
  
  .res-table tbody tr:hover td,
  .tbl tbody tr:hover td { background: #f8fafc; }
  .res-table tbody tr:last-child td,
  .tbl tbody tr:last-child td { border-bottom: none; }
  
  /* Loading state */
  .tbl-loading {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    padding: 40px; color: var(--clr-slate-400); font-size: 0.84rem; font-weight: 600;
  }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  11. ALERTS & MESSAGES                                                   ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  .alert {
    display: none;
    align-items: flex-start;
    gap: 8px;
    padding: 11px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
    margin-bottom: 14px;
    line-height: 1.5;
  }
  .alert.visible { display: flex; animation: fadeUp 0.2s ease both; }
  .alert i { font-size: 0.95rem; flex-shrink: 0; margin-top: 1px; }
  
  .alert-success,
  .alert-info    { background: #f0fdf4; color: var(--clr-green-dark); border-color: #bbf7d0; }
  .alert-error   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
  .alert-warning,
  .alert-amber   { background: #fffbeb; color: #92400e; border-color: #fde68a; }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  12. MODALS                                                              ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  .modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.55);
    backdrop-filter: blur(5px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 16px;
  }
  .modal-backdrop.open { display: flex; animation: fadeIn 0.18s ease; }
  
  .modal-box,
  .modal {
    background: var(--clr-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    animation: slideUp 0.26s cubic-bezier(0.22, 0.68, 0, 1.2) both;
  }
  
  .modal-box.modal-lg,
  .modal.modal-lg { max-width: 720px; }
  .modal-box.modal-sm,
  .modal.modal-sm { max-width: 400px; }
  
  /* Modal sections */
  .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px 14px;
    border-bottom: 1px solid var(--clr-slate-200);
  }
  
  .modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--clr-slate);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .modal-close {
    width: 32px; height: 32px; border-radius: var(--radius-sm);
    border: 1px solid var(--clr-slate-200); background: transparent;
    color: var(--clr-slate-400); font-size: 1rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--tx-fast);
  }
  .modal-close:hover { background: #fef2f2; border-color: #fecaca; color: var(--clr-red); }
  
  .modal-body { padding: 20px 24px; }
  .modal-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--clr-slate-200);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  
  /* Colored modal headers */
  .modal-header-green {
    background: linear-gradient(135deg, var(--clr-green-dark), var(--clr-green));
    color: var(--clr-white);
    padding: 18px 24px 14px;
  }
  .modal-header-blue {
    background: linear-gradient(135deg, #1d4ed8, var(--clr-blue));
    color: var(--clr-white);
    padding: 18px 24px 14px;
  }
  .modal-header-green .modal-title,
  .modal-header-blue  .modal-title { color: var(--clr-white); }
  .modal-header-green p,
  .modal-header-blue  p { font-size: 0.78rem; color: rgba(255,255,255,0.65); margin: 0; }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  13. DIVIDERS & TYPOGRAPHY UTILITIES                                     ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  .divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--clr-slate-200), transparent);
    margin: 20px 0;
    border: none;
  }
  
  .section-label,
  .section-heading {
    font-size: var(--text-xs);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--clr-slate-400);
    margin-bottom: 12px;
  }
  
  .subtitle {
    font-size: 14px;
    color: var(--clr-slate-600);
    line-height: 1.6;
    margin-bottom: 16px;
  }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  14. LAYOUT UTILITIES                                                    ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  .actions-row,
  .tm-actions-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
  }
  
  .scroll-x,
  .tm-scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  
  /* Page shell container */
  .app-container,
  .app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
  }
  
  .app-container > *,
  .container {
    width: 100%;
    padding: 20px 22px 80px;
  }
  
  /* Embed signal: portal.html injects [data-portal-shell] on the iframe body */
  /* Child pages should hide their standalone chrome elements */
  [data-portal-shell] .page-header    { position: static; }
  [data-portal-shell] .top-accent     { display: none; }
  [data-portal-shell] .app-topbar     { display: none; }
  [data-portal-shell] .hub-header     { position: static; }
  
  /* QR code wrapper */
  .qr-wrap {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding: 16px; background: var(--clr-white);
    border: 1.5px solid var(--clr-slate-200); border-radius: var(--radius-md);
  }
  .qr-label {
    font-size: var(--text-xs); font-weight: 600; color: var(--clr-slate-400);
    letter-spacing: 0.06em; text-transform: uppercase;
  }
  
  /* Session preview info bar */
  .spv {
    border-radius: var(--radius-md); padding: 11px 16px;
    display: flex; gap: 18px; flex-wrap: wrap; align-items: center; font-size: 0.8rem;
  }
  .spv.ok  { background: linear-gradient(90deg, #f0fdf4, #eff6ff); border: 1.5px solid #bbf7d0; }
  .spv.miss { background: #fff1f2; border: 1.5px solid #fecaca; }
  .spv-item { display: flex; flex-direction: column; gap: 2px; }
  .spv-lbl { font-size: var(--text-xs); font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em; color: var(--clr-slate-400); }
  .spv-val { font-weight: 700; color: var(--clr-slate); }
  .spv.miss .spv-val { color: var(--clr-red-dark); }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  15. SPINNER / LOADING                                                   ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  .spinner {
    width: 22px; height: 22px;
    border: 2.5px solid var(--clr-slate-200);
    border-top-color: var(--clr-green);
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
    display: inline-block;
    flex-shrink: 0;
  }
  
  .spinner-sm {
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
  }
  
  .loading-state {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    padding: 48px 24px; color: var(--clr-slate-400);
    font-size: 0.84rem; font-weight: 600;
  }
  
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  16. RESPONSIVE                                                          ║
     ╚══════════════════════════════════════════════════════════════════════════╝ */
  @media (max-width: 860px) {
    /* Cards */
    .card, .card-panel, .glass-card, .summary-card { border-radius: var(--radius-lg); }
    .card, .card-panel { padding: 18px 20px; }
  
    /* Grids collapse */
    .section-grid.cols-2,
    .tm-section-grid.cols-2,
    .kpi-grid.cols-3,
    .kpi-grid.cols-4,
    .kpi-grid.cols-5,
    .tm-kpi-grid.cols-4,
    .tm-kpi-grid.cols-5 { grid-template-columns: 1fr; }
  
    /* Page header stacks */
    .page-header-inner { flex-direction: column; align-items: stretch; }
    .page-header-right { flex-wrap: wrap; }
  
    /* Actions stack */
    .actions-row,
    .tm-actions-row { flex-direction: column; align-items: stretch; }
    .actions-row > *,
    .tm-actions-row > * { flex: 1 1 100%; }
  
    /* Page body */
    .page-body { padding: 14px 16px 60px; }
  }
  
  @media (max-width: 640px) {
    /* Form rows collapse */
    .form-row { grid-template-columns: 1fr; }
    .fg-6, .fg-4, .fg-3, .fg-2 { grid-column: span 12; }
  
    /* Buttons full width */
    .btn { width: 100%; }
    .btn-icon, .abtn, .dt-icon-btn { width: 36px !important; }
  
    /* Link box stacks */
    .link-box { flex-direction: column; }
  
    /* App container */
    .app-container > * { padding: 14px 12px 60px; }
  }
  
  @media (max-width: 800px) {
    .app-topbar { display: none; }
    .app-tabs { top: 0; padding: 8px 12px; }
    .app-tab { flex: 1 0 auto; justify-content: center; white-space: nowrap; }
  }
  
  /* ╔══════════════════════════════════════════════════════════════════════════╗
     ║  MINIMAL / FLAT UI DESIGN SYSTEM                                          ║
     ║  Clean, modern, flat design with subtle shadows                           ║
  ╚══════════════════════════════════════════════════════════════════════════╝ */
  
  /* ── Base Reset for Minimal ── */
  :root {
    /* Minimal Color Palette */
    --flat-bg: #f8f9fa;
    --flat-surface: #ffffff;
    --flat-border: #e9ecef;
    --flat-text: #212529;
    --flat-text-muted: #6c757d;
    --flat-primary: #2563eb;
    --flat-primary-hover: #1d4ed8;
    --flat-success: #10b981;
    --flat-warning: #f59e0b;
    --flat-danger: #ef4444;
    --flat-info: #06b6d4;
    
    /* Minimal Shadows */
    --flat-shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --flat-shadow: 0 1px 3px rgba(0,0,0,0.08);
    --flat-shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --flat-shadow-lg: 0 10px 15px rgba(0,0,0,0.06);
    
    /* Minimal Radius */
    --flat-radius: 8px;
    --flat-radius-sm: 6px;
    --flat-radius-lg: 12px;
  }
  
  /* ── Body & Background ── */
  body {
    background: var(--flat-bg) !important;
    color: var(--flat-text) !important;
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif !important;
  }
  
  /* ── Cards (Flat) ── */
  .card-panel,
  .card,
  .glass-card {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
    box-shadow: var(--flat-shadow-sm) !important;
    padding: 20px 24px !important;
  }
  
  /* ── Headers ── */
  .page-header {
    background: var(--flat-surface) !important;
    border-bottom: 1px solid var(--flat-border) !important;
    box-shadow: none !important;
  }
  
  .page-title {
    color: var(--flat-text) !important;
    font-weight: 600 !important;
  }
  
  /* ── Navigation Tabs ── */
  .sp-tabnav {
    background: var(--flat-surface) !important;
    border-bottom: 1px solid var(--flat-border) !important;
    box-shadow: none !important;
  }
  
  .sp-tab {
    color: var(--flat-text-muted) !important;
    border: none !important;
    background: transparent !important;
    padding: 12px 16px !important;
  }
  
  .sp-tab:hover {
    color: var(--flat-primary) !important;
    background: var(--flat-bg) !important;
  }
  
  .sp-tab.active {
    color: var(--flat-primary) !important;
    background: transparent !important;
    border-bottom: 2px solid var(--flat-primary) !important;
    margin-bottom: -1px;
  }
  
  .sp-tab i {
    color: var(--flat-text-muted) !important;
  }
  
  .sp-tab.active i {
    color: var(--flat-primary) !important;
  }
  
  /* ── Top Bar ── */
  .top-bar {
    background: var(--flat-surface) !important;
    border-bottom: 1px solid var(--flat-border) !important;
    box-shadow: none !important;
  }
  
  .top-bar-title {
    color: var(--flat-text) !important;
  }
  
  /* ── Pills Tabs ── */
  .page-tabs {
    background: var(--flat-bg) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
    padding: 3px !important;
  }
  
  .page-tab {
    background: transparent !important;
    color: var(--flat-text-muted) !important;
    border: none !important;
    border-radius: var(--flat-radius-sm) !important;
  }
  
  .page-tab.active {
    background: var(--flat-surface) !important;
    color: var(--flat-primary) !important;
    box-shadow: var(--flat-shadow-sm) !important;
  }
  
  /* ── Buttons (Flat) ── */
  .btn-green-solid,
  .btn-success {
    background: var(--flat-primary) !important;
    border: none !important;
    border-radius: var(--flat-radius-sm) !important;
    color: #fff !important;
    font-weight: 500 !important;
    padding: 10px 18px !important;
    box-shadow: none !important;
  }
  
  .btn-green-solid:hover,
  .btn-success:hover {
    background: var(--flat-primary-hover) !important;
  }
  
  .btn-resources {
    background: var(--flat-info) !important;
    border: none !important;
    border-radius: var(--flat-radius-sm) !important;
    color: #fff !important;
  }
  
  .btn-quiz-gen {
    background: var(--flat-success) !important;
    border: none !important;
    border-radius: var(--flat-radius-sm) !important;
    color: #fff !important;
  }
  
  .btn-outline-secondary {
    background: transparent !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius-sm) !important;
    color: var(--flat-text-muted) !important;
  }
  
  .btn-outline-secondary:hover {
    background: var(--flat-bg) !important;
    border-color: var(--flat-text-muted) !important;
    color: var(--flat-text) !important;
  }
  
  /* ── Form Inputs (Flat) ── */
  .form-control,
  .form-select {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius-sm) !important;
    box-shadow: none !important;
    padding: 10px 14px !important;
  }
  
  .form-control:focus,
  .form-select:focus {
    border-color: var(--flat-primary) !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1) !important;
  }
  
  /* ── Course Dropdown ── */
  .course-dd-trigger {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius-sm) !important;
    box-shadow: none !important;
  }
  
  .course-dd-trigger:focus,
  .course-dd-trigger.open {
    border-color: var(--flat-primary) !important;
  }
  
  .course-dd-panel {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
    box-shadow: var(--flat-shadow-md) !important;
  }
  
  /* ── Table (Flat) ── */
  .table-wrap {
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
    overflow: hidden;
  }
  
  .table thead th {
    background: var(--flat-bg) !important;
    color: var(--flat-text-muted) !important;
    border-bottom: 1px solid var(--flat-border) !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    font-size: 0.7rem !important;
    letter-spacing: 0.05em;
  }
  
  .table tbody tr {
    background: var(--flat-surface) !important;
  }
  
  .table tbody tr:nth-child(even) {
    background: var(--flat-bg) !important;
  }
  
  .table tbody tr:hover td {
    background: #f1f3f5 !important;
  }
  
  .table td {
    border-color: var(--flat-border) !important;
    padding: 12px 16px !important;
  }
  
  /* ── Action Buttons ── */
  .action-btn {
    background: transparent !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius-sm) !important;
    color: var(--flat-text-muted) !important;
  }
  
  .action-btn:hover {
    background: var(--flat-bg) !important;
    border-color: var(--flat-text-muted) !important;
  }
  
  /* ── Modal (Flat) ── */
  .modal-box {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius-lg) !important;
    box-shadow: var(--flat-shadow-lg) !important;
  }
  
  .modal-head {
    background: var(--flat-surface) !important;
    border-bottom: 1px solid var(--flat-border) !important;
    color: var(--flat-text) !important;
    padding: 16px 20px !important;
  }
  
  .modal-head.green {
    background: var(--flat-success) !important;
    border-bottom: none !important;
    color: #fff !important;
  }
  
  .modal-close {
    background: transparent !important;
    border: none !important;
    color: var(--flat-text-muted) !important;
  }
  
  /* ── Search Box ── */
  .search-wrap input {
    background: var(--flat-bg) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius-sm) !important;
    box-shadow: none !important;
  }
  
  .search-wrap input:focus {
    border-color: var(--flat-primary) !important;
    background: var(--flat-surface) !important;
  }
  
  /* ── CSV Button ── */
  .csv-btn {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius-sm) !important;
    color: var(--flat-text-muted) !important;
  }
  
  .csv-btn:hover {
    background: var(--flat-bg) !important;
    border-color: var(--flat-text-muted) !important;
    color: var(--flat-text) !important;
  }
  
  /* ── FAB (Flat) ── */
  .fab-new-session {
    background: var(--flat-primary) !important;
    border: none !important;
    border-radius: 50px !important;
    box-shadow: var(--flat-shadow-md) !important;
    padding: 12px 20px !important;
  }
  
  .fab-new-session:hover {
    background: var(--flat-primary-hover) !important;
    box-shadow: var(--flat-shadow-lg) !important;
    transform: translateY(-1px);
  }
  
  /* ── Status Chips ── */
  .chip-planned {
    background: #eff6ff !important;
    color: #2563eb !important;
    border: none !important;
  }
  
  .chip-progress {
    background: #fffbeb !important;
    color: #d97706 !important;
    border: none !important;
  }
  
  .chip-completed {
    background: #ecfdf5 !important;
    color: #059669 !important;
    border: none !important;
  }
  
  .chip-cancelled {
    background: #f8fafc !important;
    color: #64748b !important;
    border: none !important;
  }
  
  /* ── Hub Cards ── */
  .hub-card {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
    box-shadow: var(--flat-shadow-sm) !important;
    padding: 20px 24px !important;
  }
  
  /* ── Session Cards (Mobile) ── */
  .session-card {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
    box-shadow: var(--flat-shadow-sm) !important;
  }
  
  /* ── Session Details Modal ── */
  #sessionDetailsModalBackdrop .sd-box {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
    box-shadow: var(--flat-shadow-lg) !important;
  }
  
  /* ── Input Group ── */
  .input-group .btn {
    background: var(--flat-bg) !important;
    border: 1px solid var(--flat-border) !important;
  }
  
  /* ── Summary Bar ── */
  .summary-bar {
    border-top: 1px solid var(--flat-border) !important;
    background: var(--flat-bg) !important;
    padding: 12px 0 !important;
  }
  
  /* ── Schedule Options ── */
  .btn-sched-options {
    background: var(--flat-bg) !important;
    border: 1px dashed var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
  }
  
  .sched-options-bar {
    background: var(--flat-bg) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
  }
  
  /* ── Badge Auto ── */
  .badge-auto {
    background: var(--flat-bg) !important;
    color: var(--flat-text-muted) !important;
    border: 1px solid var(--flat-border) !important;
    font-size: 0.65rem !important;
  }
  
  /* ── Scrollbar (Minimal) ── */
  ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  
  ::-webkit-scrollbar-track {
    background: var(--flat-bg);
  }
  
  ::-webkit-scrollbar-thumb {
    background: var(--flat-border);
    border-radius: 3px;
  }
  
  ::-webkit-scrollbar-thumb:hover {
    background: var(--flat-text-muted);
  }
  
  /* ── Sidebar (Flat) ── */
  .sidebar {
    background: var(--flat-surface) !important;
    border-right: 1px solid var(--flat-border) !important;
  }
  
  .sb-link {
    color: var(--flat-text-muted) !important;
  }
  
  .sb-link:hover {
    background: var(--flat-bg) !important;
    color: var(--flat-text) !important;
  }
  
  .sb-link.active {
    background: var(--flat-bg) !important;
    color: var(--flat-primary) !important;
    border-left: none !important;
  }
  
  /* ── Stat Cards ── */
  .stat-card {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
    box-shadow: none !important;
  }
  
  /* ── Attendance ── */
  .att-stat-pill.total {
    background: #ecfdf5 !important;
    color: #059669 !important;
    border: none !important;
  }
  
  .att-stat-pill.enrolled {
    background: #faf5ff !important;
    color: #7c3aed !important;
    border: none !important;
  }
  
  .att-stat-pill.absent {
    background: #fef2f2 !important;
    color: #dc2626 !important;
    border: none !important;
  }
  
  .att-session-bar {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
  }
  
  .att-matrix-table th {
    background: var(--flat-bg) !important;
    color: var(--flat-text-muted) !important;
  }
  
  /* ── Breadcrumb ── */
  .breadcrumb-bar a {
    color: var(--flat-primary) !important;
    text-decoration: none !important;
  }
  
  .breadcrumb-bar a:hover {
    text-decoration: underline !important;
  }
  
  /* ── Empty State ── */
  .results-empty,
  .empty-state {
    color: var(--flat-text-muted) !important;
    text-align: center;
    padding: 40px 20px;
  }
  
  /* ── Resource Sections ── */
  .res-section {
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius) !important;
    overflow: hidden;
  }
  
  .res-section-header {
    background: var(--flat-bg) !important;
    border-bottom: 1px solid var(--flat-border) !important;
  }
  
  .res-btn-add {
    background: transparent !important;
    border: 1px dashed var(--flat-border) !important;
    border-radius: var(--flat-radius-sm) !important;
    color: var(--flat-text-muted) !important;
  }
  
  .res-btn-add:hover {
    border-color: var(--flat-primary) !important;
    color: var(--flat-primary) !important;
  }
  
  .res-btn-remove {
    background: transparent !important;
    border: 1px solid var(--flat-border) !important;
    color: var(--flat-text-muted) !important;
  }
  
  .res-btn-remove:hover {
    background: #fef2f2 !important;
    border-color: var(--flat-danger) !important;
    color: var(--flat-danger) !important;
  }
  
  /* ── Hub QR Wrap ── */
  .hub-qr-wrap {
    background: var(--flat-bg) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius-sm) !important;
  }
  
  .hub-link-input {
    background: var(--flat-bg) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius-sm) !important;
  }
  
  .hub-btn-copy {
    background: var(--flat-surface) !important;
    border: 1px solid var(--flat-border) !important;
    border-radius: var(--flat-radius-sm) !important;
    color: var(--flat-text-muted) !important;
  }
  
  /* ── Toggle Switch ── */
  .hub-gate-track {
    background: var(--flat-border) !important;
  }
  
  .hub-gate-thumb {
    background: var(--flat-surface) !important;
    box-shadow: var(--flat-shadow-sm) !important;
  }
  
  /* ── Copy Toast ── */
  .copy-toast {
    background: var(--flat-text) !important;
    border-radius: var(--flat-radius-sm) !important;
    box-shadow: var(--flat-shadow-md) !important;
  }
  
  /* ── Form Readonly ── */
  .form-readonly-field {
    background: var(--flat-bg) !important;
    border-color: var(--flat-border) !important;
  }
  