/*
 * JEE CMS: Admin panel styles (self-contained, no framework).
 * Previously layered on Bootstrap 5.3; now ships its own compact design
 * system so the admin loads no external CSS/JS:
 *   - design tokens below re-declare the `--bs-*` names the components use,
 *     in both light and dark, driven by [data-bs-theme]
 *   - a small reset + utility set replaces the Bootstrap classes the admin
 *     templates rely on (d-flex, gap-*, mb-*, text-*, w-100, …)
 * Dark mode "just works" because every colour flows through these tokens.
 */

/* ══════════════════════════════════════════════════════════
   Design tokens: matched to the Business Catalysts main site
   ══════════════════════════════════════════════════════════
   The names below (--primary, --surface, --heading, …) are the single source
   of truth for colour. The --bs-* names the components below use are aliases
   onto them, so a palette change means editing only this block.

   Values come from the main site's theme (../../../theme/css/layout.css and
   custom.css), and are shared with the public blog's assets/css/public.css:
     accent   #17bed2  (hover #63cbd7)   headings #515769
     body     #81848f  muted #a6a7aa     alt band #fafafa
     borders  #e8e8e8 / #f0f0f0          font Hind, square corners, flat

   Light reproduces the main site. Dark is the same palette on a dark field,
   so the admin's light/dark toggle keeps working; the accent is unchanged in
   both, and both sides have to stay legible.
   ══════════════════════════════════════════════════════════ */
:root {
    /* Hind is the main site's typeface. The admin deliberately loads no
       external CSS, so it is requested here without a webfont link: it renders
       in Hind where the font is available locally and falls back to the same
       neo-grotesque stack the theme names otherwise. */
    --font-sans: Hind, "Helvetica Neue", Helvetica, Arial, sans-serif;
    --font-mono: Consolas, Monaco, ui-monospace, SFMono-Regular, Menlo, monospace;

    /* Radius scale: The main site is square-cornered throughout. */
    --radius-sm: 0;
    --radius: 0;
    --radius-lg: 0;

    --transition: .3s cubic-bezier(0.7, 1, 0.7, 1);

    /* Back-compat aliases for the component rules further down */
    --admin-radius: var(--radius);
    --admin-shadow: var(--shadow-sm);
    --bs-border-radius: var(--radius);
}

/* Light counterpart: derived, not from the file. */
[data-bs-theme="light"] {
    --primary: #17bed2;   --primary-hover: #63cbd7;   --primary-light: #e3f7fa;
    --secondary: #17bed2; --secondary-hover: #63cbd7; --secondary-light: #e3f7fa;
    --accent: #17bed2;    --accent-hover: #63cbd7;    --accent-light: #e3f7fa;

    --success: #46b3a0;
    --warning: #e2a55a;
    --error:   #e66262;
    --info:    #17bed2;

    --background:     #fafafa;
    --surface:        #ffffff;
    --surface-alt:    #fafafa;
    --surface-hover:  #f4f4f4;

    --heading:    #515769;
    --text:       #515769;
    --text-light: #81848f;
    --text-muted: #a6a7aa;

    --border:       #e8e8e8;
    --border-light: #f0f0f0;

    /* The main site uses no elevation at all. */
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: none;

    --zebra:      #fafafa;
    --row-hover:  rgba(23, 190, 210, .07);
    --code-bg:    #fafafa;
    --code-color: #17bed2;
    --link:       var(--primary);
    --link-hover: var(--primary-hover);
    --footer-bg:  #272c37;

    --primary-rgb:   23, 190, 210;
    --secondary-rgb: 23, 190, 210;
    --accent-rgb:    23, 190, 210;
    --success-rgb:   70, 179, 160;
    --warning-rgb:   226, 165, 90;
    --error-rgb:     230, 98, 98;
    --info-rgb:      23, 190, 210;
}

/* The same accent on a dark field; text tones are the main site's own footer
   colours, which is where it already renders light-on-dark. */
[data-bs-theme="dark"] {
    --primary: #17bed2;   --primary-hover: #63cbd7;   --primary-light: #8ddbe4;
    --secondary: #17bed2; --secondary-hover: #63cbd7; --secondary-light: #8ddbe4;
    --accent: #17bed2;    --accent-hover: #63cbd7;    --accent-light: #8ddbe4;

    --success: #57c4b1;
    --warning: #e8b673;
    --error:   #ec7b7b;
    --info:    #17bed2;

    --background:     #1b1f27;
    --surface:        #232833;
    --surface-alt:    #2b313d;
    --surface-hover:  #343b49;

    --heading:    #ffffff;
    --text:       #cbd3e1;
    --text-light: #a6a7aa;
    --text-muted: #8b8f9c;

    --border:       #333a47;
    --border-light: #3d4553;

    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: none;

    --zebra:      rgba(255, 255, 255, .03);
    --row-hover:  rgba(23, 190, 210, .12);
    --code-bg:    #12151b;
    --code-color: #63cbd7;
    --link:       var(--primary);
    --link-hover: var(--primary-hover);
    --footer-bg:  #12151b;

    --primary-rgb:   23, 190, 210;
    --secondary-rgb: 23, 190, 210;
    --accent-rgb:    23, 190, 210;
    --success-rgb:   87, 196, 177;
    --warning-rgb:   232, 182, 115;
    --error-rgb:     236, 123, 123;
    --info-rgb:      23, 190, 210;
}

/* --bs-* aliases: what every component rule below actually reads. */
[data-bs-theme="light"],
[data-bs-theme="dark"] {
    --bs-primary: var(--primary);   --bs-primary-rgb: var(--primary-rgb);
    --bs-success: var(--success);   --bs-success-rgb: var(--success-rgb);
    --bs-danger:  var(--error);     --bs-danger-rgb:  var(--error-rgb);
    --bs-warning: var(--warning);   --bs-warning-rgb: var(--warning-rgb);
    --bs-info:    var(--info);      --bs-info-rgb:    var(--info-rgb);

    --bs-body-bg:         var(--surface);
    --bs-body-color:      var(--text);
    --bs-secondary-color: var(--text-light);
    --bs-secondary-bg:    var(--surface-alt);
    --bs-border-color:    var(--border);

    --admin-page-bg:   var(--background);
    --admin-surface:   var(--surface);
    --admin-surface-2: var(--surface-alt);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 14px; scroll-behavior: smooth; }        /* compact admin density */
body {
    margin: 0;
    background: var(--admin-page-bg);
    color: var(--bs-body-color);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
img { max-width: 100%; }
/* Links carry the site accent and lighten on hover, as .color-base does on the
   main site. */
a { color: var(--link); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--link-hover); text-decoration: none; }

/* Scrollbar (Chromium/Edge/Safari). */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--surface-alt); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }
p { margin: 0 0 1rem; }
h1, h2, h3, h4, h5, h6 { margin: 0 0 .5rem; color: var(--heading); font-weight: 700; line-height: 1.25; }
button, input, select, textarea { font-family: inherit; font-size: 100%; }
table { border-collapse: collapse; }

/* ── Utilities (subset the admin templates use) ── */
.d-flex { display: flex; }
.d-inline-flex { display: inline-flex; }
.d-block { display: block; }
.d-none { display: none; }
.flex-column { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.gap-1 { gap: .25rem; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: 1rem; }
.ms-auto { margin-left: auto; }
.w-100 { width: 100%; }
.text-center { text-align: center; }
.text-secondary { color: var(--bs-secondary-color); }
.text-decoration-none { text-decoration: none; }
.small { font-size: .875em; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-3 { margin-top: 1rem; }
.link-secondary { color: var(--bs-secondary-color); }
.link-secondary:hover { color: var(--bs-body-color); }

/* ── Page content wrapper ── */
.page-main { padding: 1.75rem 0; }

/* ── Page Heading ── */
.page-heading {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}
.page-heading .math-render { display: inline; }

/* ── Card Grid ── */
.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}
@media (min-width: 640px)  { .card-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .card-grid { grid-template-columns: repeat(3, 1fr); } }

/* Content card */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    display: block;
    color: var(--text);
}
.card:hover {
    background: var(--surface-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-4px);
    border-color: var(--primary);
    text-decoration: none;
    color: var(--text);
}
.card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: .35rem;
}
.card:hover h2 { color: var(--bs-primary); }
.card p  { font-size: .875rem; color: var(--bs-secondary-color); margin-top: .5rem; margin-bottom: 0; }
.card .meta { font-size: .75rem; color: var(--bs-secondary-color); margin-top: .75rem; }

/* ── Badges ── */
/* Option 2 badges: an 18% translucent fill of the status colour, no border,
   with the light tint of that colour as the text. */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .3rem .8rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    border: 0;
}
/* Every badge reads its text colour from the same token as its fill, so both
   themes stay in step without a per-theme override. */
.badge-easy   { background: rgba(var(--success-rgb), .18);   color: var(--success); }
.badge-medium { background: rgba(var(--warning-rgb), .18);   color: var(--warning); }
.badge-hard   { background: rgba(var(--error-rgb), .18);     color: var(--error); }
.badge-year   { background: rgba(var(--primary-rgb), .18);   color: var(--primary); }
.badge-type   { background: rgba(var(--secondary-rgb), .18); color: var(--secondary); }
.badge-info   { background: rgba(var(--info-rgb), .18);      color: var(--info); }

/* ── Question List (chapter page) ── */
.question-list { display: flex; flex-direction: column; gap: .875rem; }
.question-card {
    background: var(--admin-surface);
    border: 1px solid var(--bs-border-color);
    border-left: 4px solid var(--bs-border-color);
    border-radius: var(--admin-radius);
    padding: 1.25rem;
    transition: box-shadow .15s, border-left-color .15s;
}
.question-card:hover { box-shadow: var(--admin-shadow); }
.question-card.easy   { border-left-color: var(--bs-success); }
.question-card.medium { border-left-color: var(--bs-warning); }
.question-card.hard   { border-left-color: var(--bs-danger); }
.question-card-header { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: .65rem; }
.question-card-body .math-render { font-size: .9375rem; color: var(--bs-body-color); }
.question-card-footer { margin-top: 1rem; }

/* ── Single Question ── */
.question-meta { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.question-body { font-size: 1rem; margin-bottom: 1.5rem; line-height: 1.8; color: var(--bs-body-color); }

.options-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1.5rem; }
.option-item {
    display: flex;
    align-items: flex-start;
    gap: .85rem;
    background: var(--admin-surface);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--admin-radius);
    padding: .875rem 1rem;
    transition: border-color .15s, background .15s;
}
.option-item.correct { border-color: var(--bs-success); background: rgba(var(--bs-success-rgb), .12); }
.option-label { font-weight: 700; min-width: 1.5rem; color: var(--bs-primary); }

/* ── CSS Toggle (Show Answer / Solution) ── */
.toggle-input { display: none; }
.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    cursor: pointer;
    background: var(--bs-primary);
    color: #fff;
    padding: .55rem 1.25rem;
    border-radius: var(--admin-radius);
    font-size: .875rem;
    font-weight: 600;
    margin-bottom: .85rem;
    user-select: none;
    transition: background .15s;
    border: none;
}
.toggle-label:hover { background: color-mix(in srgb, var(--bs-primary), #000 12%); }
.toggle-input:checked ~ .toggle-label { background: color-mix(in srgb, var(--bs-primary), #000 12%); }
.toggle-content { display: none; }
.toggle-input:checked ~ .toggle-content { display: block; }

.answer-box {
    background: rgba(var(--bs-success-rgb), .1);
    border: 1px solid rgba(var(--bs-success-rgb), .3);
    border-radius: var(--admin-radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.solution-box {
    background: rgba(var(--bs-warning-rgb), .1);
    border: 1px solid rgba(var(--bs-warning-rgb), .3);
    border-radius: var(--admin-radius);
    padding: 1.25rem;
}
.hint-box {
    background: rgba(var(--bs-primary-rgb), .08);
    border: 1px solid rgba(var(--bs-primary-rgb), .3);
    border-radius: var(--admin-radius);
    padding: .85rem 1rem;
    margin-top: .85rem;
    font-size: .875rem;
    color: var(--bs-body-color);
}

/* ── Tags ── */
.tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: 1.25rem; }
.tag {
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    border-radius: 999px;
    padding: .25em .7em;
    font-size: .75rem;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.tag:hover { background: var(--bs-primary); color: #fff; }

/* ── Prev/Next navigation ── */
.q-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--bs-border-color);
}
.q-nav a { font-size: .875rem; }

/* ── Filter Bar ── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .65rem;
    align-items: flex-end;
    margin-bottom: 1.5rem;
    background: var(--admin-surface);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--admin-radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--admin-shadow);
}
.filter-bar label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    text-transform: uppercase;
    letter-spacing: .04em;
    display: block;
    margin-bottom: .3rem;
}
.filter-bar select {
    padding: .5rem .85rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--admin-radius);
    font-size: .8125rem;
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    cursor: pointer;
    transition: border-color .15s;
}
.filter-bar select:focus { outline: none; border-color: var(--bs-primary); }
.filter-bar .btn { margin-top: auto; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    padding: .625rem 1.125rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
    line-height: 1.4;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover  { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
/* Option 2's warning button: amber with near-black text for contrast. No
   markup uses it yet; it is here so the palette is complete. */
.btn-warning   { background: var(--warning); color: #515769; border-color: var(--warning); }
.btn-warning:hover  { background: color-mix(in srgb, var(--warning), #000 12%); border-color: color-mix(in srgb, var(--warning), #000 12%); color: #515769; }
.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover  { background: color-mix(in srgb, var(--success), #000 12%); border-color: color-mix(in srgb, var(--success), #000 12%); color: #fff; }
.btn-danger    { background: var(--error); color: #fff; border-color: var(--error); }
.btn-danger:hover   { background: color-mix(in srgb, var(--error), #000 12%); border-color: color-mix(in srgb, var(--error), #000 12%); color: #fff; }
/* Kept neutral on purpose: this app uses .btn-secondary for Cancel and Logout,
   where Option 2's cyan fill would read as a second call to action. */
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: color-mix(in srgb, var(--surface-alt), var(--text) 12%); color: var(--text); }
.btn-outline   { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-outline:hover  { background: var(--primary); color: #fff; }
.btn-light     { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-light:hover    { background: var(--surface-alt); border-color: var(--border); }
.btn-sm { padding: .4rem .85rem; font-size: .8rem; }
.btn-lg { padding: .825rem 1.5rem; font-size: 1rem; }

/* ── Pagination ── */
.pagination { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: 1.75rem; justify-content: center; align-items: center; }
.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 .65rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--admin-radius);
    font-size: .8125rem;
    font-weight: 500;
    color: var(--bs-primary);
    background: var(--admin-surface);
    transition: all .15s;
    text-decoration: none;
}
.page-link:hover { background: var(--bs-primary); color: #fff; border-color: var(--bs-primary); }
.page-link.active { background: var(--bs-primary); color: #fff; border-color: var(--bs-primary); font-weight: 700; }
.page-ellipsis { padding: 0 .4rem; font-size: .875rem; color: var(--bs-secondary-color); display: inline-flex; align-items: center; height: 2.25rem; }

/* ── Math Render ── */
.math-render { overflow-x: auto; max-width: 100%; display: inline-block; vertical-align: middle; }
div.math-render { display: block; margin: .5rem 0; }

/* Markdown blocks produced by prepareMathText(): keep the first and last
   block flush with the container so a one-paragraph field is not offset. */
.math-render p, .preview-pane p { margin: 0 0 .75rem; }
.math-render ul, .math-render ol,
.preview-pane ul, .preview-pane ol { margin: 0 0 .75rem; padding-left: 1.5rem; }
.math-render li, .preview-pane li { margin-bottom: .25rem; }
.math-render h1, .math-render h2, .math-render h3,
.math-render h4, .math-render h5, .math-render h6,
.preview-pane h1, .preview-pane h2, .preview-pane h3,
.preview-pane h4, .preview-pane h5, .preview-pane h6 {
    margin: 1rem 0 .5rem;
    font-size: 1.05rem;
    font-weight: 600;
}
.math-render > :first-child, .preview-pane > :first-child { margin-top: 0; }
.math-render > :last-child, .preview-pane > :last-child { margin-bottom: 0; }

/* ── Inline SVG figures ── */
.inline-svg { display: inline-block; max-width: 100%; vertical-align: middle; }
.inline-svg svg { max-width: 100%; height: auto; }
.inline-svg-error { display: block; white-space: pre-wrap; word-break: break-all; color: #b91c1c; }

/* ── Question / solution image upload field ── */
.qimg-field input[type="file"] {
    width: 100%;
    padding: .5rem;
    border: 1px dashed var(--bs-border-color);
    border-radius: .4rem;
    background: var(--bs-body-bg);
    font-size: .85rem;
}
.qimg-list {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: .6rem;
}
.qimg-item {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    width: 150px;
    padding: .5rem;
    border: 1px solid var(--bs-border-color);
    border-radius: .4rem;
    background: var(--bs-body-bg);
}
.qimg-item img {
    display: block;
    width: 100%;
    height: 96px;
    object-fit: contain;
    background: #fff;
    border-radius: .25rem;
}
.qimg-meta { font-size: .7rem; color: var(--bs-secondary-color); word-break: break-word; }
.qimg-item.is-removed { border-style: dashed; border-color: var(--bs-danger, #dc3545); }
.qimg-item.is-removed img { opacity: .3; }
.qimg-item.is-removed .qimg-meta { text-decoration: line-through; }
.qimg-paste {
    margin-top: .5rem;
    padding: .75rem;
    border: 1px dashed var(--bs-border-color);
    border-radius: .4rem;
    background: var(--bs-body-bg);
    color: var(--bs-secondary-color);
    font-size: .85rem;
    text-align: center;
    cursor: text;
}
.qimg-paste:focus, .qimg-paste.is-active {
    outline: none;
    border-color: var(--bs-primary, #0d6efd);
    color: var(--bs-body-color);
}
.qimg-pending {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    margin-top: .5rem;
}
.qimg-pending:empty { display: none; }

/* ── Chapter List ── */
.chapter-list { display: flex; flex-direction: column; gap: .5rem; }
.chapter-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--admin-surface);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--admin-radius);
    padding: 1rem 1.25rem;
    transition: box-shadow .15s, border-color .15s;
}
.chapter-item:hover { box-shadow: var(--admin-shadow); border-color: var(--bs-primary); }
.chapter-item a { color: var(--bs-body-color); font-weight: 500; font-size: .9375rem; }
.chapter-item a:hover { color: var(--bs-primary); text-decoration: none; }
.q-count {
    background: var(--admin-surface-2);
    border: 1px solid var(--bs-border-color);
    border-radius: 999px;
    padding: .2em .8em;
    font-size: .75rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    white-space: nowrap;
}

/* ── Subject card accent ── */
.subject-card { border-top: 3px solid var(--bs-primary); }

/* ── Results count ── */
.results-count { font-size: .8125rem; color: var(--bs-secondary-color); margin-bottom: .85rem; }

/* ── Flash Messages ── */
/* Option 2 alerts: a 5px status bar on the left over a 12% translucent fill,
   with pale text. The light counterpart keeps the fill and darkens the text. */
.flash {
    padding: 1rem;
    border-radius: var(--radius-sm);
    border-left: 5px solid;
    margin-bottom: 1rem;
    font-size: .875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.flash::before { font-size: 1rem; flex-shrink: 0; }
/* Body text stays on --text so the message itself is read at full contrast in
   both themes; the state is carried by the left bar and the tinted field, the
   way the main site's .alert-theme does it. */
.flash-success { background: rgba(var(--success-rgb), .12);   border-color: var(--success);   color: var(--text); }
.flash-success::before { content: "✓"; color: var(--success); }
.flash-error   { background: rgba(var(--error-rgb), .12);     border-color: var(--error);     color: var(--text); }
.flash-error::before { content: "✕"; color: var(--error); }
.flash-warning { background: rgba(var(--warning-rgb), .12);   border-color: var(--warning);   color: var(--text); }
.flash-warning::before { content: "!"; color: var(--warning); }
.flash-info    { background: rgba(var(--secondary-rgb), .12); border-color: var(--secondary); color: var(--text); }
.flash-info::before { content: "ℹ"; color: var(--secondary); }

/* ═══════════════════════════════════════
   ADMIN LAYOUT (dark sidebar retained)
   ═══════════════════════════════════════ */

.jee-admin-layout { display: flex; min-height: 100vh; }

/* ── Admin Sidebar ── */
.jee-sidebar {
    width: 265px;
    flex-shrink: 0;
    /* The main site's dark footer tone, fixed rather than tokenised so the
       sidebar stays dark in both themes. */
    background: #272c37;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
    transition: width .2s;
}
.jee-sidebar-logo {
    padding: 1.5rem 1.5rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}
.jee-sidebar-logo a {
    min-width: 0;
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -.2px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.jee-sidebar-logo a:hover { color: var(--bs-primary); }
.jee-sidebar-logo .logo-icon {
    width: 32px;
    height: 32px;
    background: var(--bs-primary);
    border-radius: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    color: #fff;
}
.jee-sidebar-nav {
    flex: 1;
    padding: 1.25rem 0 1rem;
}
.jee-sidebar-nav .nav-section {
    padding: .75rem 1.5rem .3rem;
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(255, 255, 255, .25);
}
.jee-sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .6rem 1.5rem;
    color: rgba(255, 255, 255, .55);
    font-size: .8125rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
    border-radius: 0;
    position: relative;
}
.jee-logout-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    width: 100%;
    padding: .6rem 1.5rem;
    color: rgba(255, 255, 255, .55);
    font-size: .8125rem;
    font-weight: 500;
    font-family: inherit;
    text-align: left;
    background: none;
    border: 0;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.jee-sidebar-nav a:hover,
.jee-logout-link:hover {
    background: rgba(255, 255, 255, .05);
    color: rgba(255, 255, 255, .9);
}
.jee-sidebar-nav a.active,
.jee-sidebar-nav a.active:hover {
    background: rgba(var(--bs-primary-rgb), .15);
    color: #fff;
}
.jee-sidebar-nav a.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--bs-primary);
    border-radius: 0;
}
.jee-sidebar-nav .nav-icon {
    font-size: .9rem;
    width: 1.1rem;
    text-align: center;
    flex-shrink: 0;
    opacity: .7;
}
.jee-sidebar-nav a:hover .nav-icon,
.jee-sidebar-nav a.active .nav-icon { opacity: 1; }
.jee-sidebar-divider {
    margin: .5rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, .07);
}

/* ── Sidebar collapse toggle (lives in the topbar, desktop only) ── */
.jee-collapse-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--admin-surface-2);
    border-radius: 0;
    cursor: pointer;
    color: var(--bs-body-color);
    font-size: 1.2rem;
    line-height: 1;
    transition: background .15s, color .15s;
}
.jee-collapse-toggle:hover {
    background: var(--bs-primary);
    color: #fff;
}

/* ── Collapsed sidebar state (desktop) ── */
@media (min-width: 992px) {
    html.sidebar-collapsed .jee-sidebar { width: 74px; }
    html.sidebar-collapsed .jee-admin-body { margin-left: 74px; }
    html.sidebar-collapsed .jee-sidebar-logo {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }
    html.sidebar-collapsed .logo-text,
    html.sidebar-collapsed .jee-sidebar-nav a .nav-label,
    html.sidebar-collapsed .jee-logout-link .nav-label,
    html.sidebar-collapsed .jee-sidebar-nav .nav-section {
        display: none;
    }
    html.sidebar-collapsed .jee-sidebar-nav a,
    html.sidebar-collapsed .jee-logout-link {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
        gap: 0;
    }
    html.sidebar-collapsed .jee-sidebar-divider { margin: .5rem 1rem; }
}

/* ── Admin Content ── */
.jee-admin-body {
    margin-left: 265px;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ── Admin Topbar ── */
.jee-topbar {
    background: var(--admin-surface);
    border-bottom: 1px solid var(--bs-border-color);
    padding: .875rem 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}
.jee-topbar-title { font-size: 1.1rem; font-weight: 700; color: var(--bs-body-color); }
.jee-topbar-actions { display: flex; align-items: center; gap: .5rem; }

/* ── Admin Main Content ── */
.jee-admin-content { padding: 1.75rem; flex: 1; }

/* ── Admin Page Header ── */
.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .5rem;
}
.admin-header h1 { font-size: 1.25rem; font-weight: 700; margin: 0; }

/* ── Dashboard helpers ── */
.admin-section-title {
    font-size: .95rem;
    font-weight: 700;
    color: var(--bs-secondary-color);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: .85rem;
}
.manage-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .875rem 1rem;
    background: var(--admin-surface);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--admin-radius);
    color: var(--bs-body-color);
    font-size: .875rem;
    font-weight: 600;
    text-decoration: none;
    transition: border-color .15s, color .15s;
}
.manage-link:hover { border-color: var(--bs-primary); color: var(--bs-primary); }
.manage-link .manage-count { margin-left: auto; color: var(--bs-secondary-color); font-size: .8rem; }

/* ── Admin Table ── */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--admin-surface);
    border-radius: var(--admin-radius);
    overflow: hidden;
    box-shadow: var(--admin-shadow);
    font-size: .8125rem;
    border: 1px solid var(--bs-border-color);
}
/* Option 2 table treatment: primary-filled header, 3% wash zebra, blue hover. */
.admin-table th {
    background: var(--primary);
    padding: .75rem 1rem;
    text-align: left;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #fff;
    border-bottom: 1px solid var(--primary);
    white-space: nowrap;
}
.admin-table td {
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text);
}
.admin-table tbody tr:nth-child(even) td { background: var(--zebra); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover td { background: var(--row-hover); }
.admin-table .actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.admin-table code {
    background: var(--code-bg);
    border: 1px solid var(--border);
    padding: .15rem .45rem;
    border-radius: 0;
    font-family: var(--font-mono);
    font-size: .78rem;
    color: var(--code-color);
}

/* ── Admin Form ── */
.admin-form {
    background: var(--admin-surface);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--admin-radius);
    padding: 1.75rem;
    max-width: 860px;
    box-shadow: var(--admin-shadow);
}
.admin-form h2 { font-size: 1rem; font-weight: 700; margin-bottom: 1.5rem; padding-bottom: .85rem; border-bottom: 1px solid var(--bs-border-color); }
.form-group { margin-bottom: 1.1rem; }
.form-group label {
    display: block;
    font-size: .8125rem;
    font-weight: 600;
    color: var(--bs-body-color);
    margin-bottom: .4rem;
}
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .875rem;
    background: var(--surface-alt);
    color: var(--text);
    transition: var(--transition);
    appearance: auto;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .25);
}
.form-group textarea { min-height: 110px; resize: vertical; line-height: 1.6; }
.form-group .hint-text { font-size: .75rem; color: var(--bs-secondary-color); margin-top: .3rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.form-check { display: flex; align-items: center; gap: .55rem; }
.form-check input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--bs-primary);
    cursor: pointer;
}
.form-check label { font-size: .875rem; font-weight: 500; cursor: pointer; margin: 0; }
.form-actions {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--bs-border-color);
}

/* ── Question form: options section ── */
.options-section { border: 1px solid var(--bs-border-color); border-radius: var(--admin-radius); padding: 1.25rem; margin-top: .875rem; background: var(--admin-surface-2); }
.options-section h3 { font-size: .875rem; font-weight: 700; color: var(--bs-secondary-color); margin-bottom: 1rem; text-transform: uppercase; letter-spacing: .05em; }
.option-row { display: grid; grid-template-columns: auto 1fr auto; gap: .875rem; align-items: start; margin-bottom: .875rem; }
.option-row:last-child { margin-bottom: 0; }
.option-lbl { font-weight: 700; padding-top: .65rem; min-width: 1.5rem; color: var(--bs-primary); font-size: .9rem; }
.option-correct-lbl { display: flex; align-items: center; gap: .35rem; font-size: .8rem; font-weight: 600; padding-top: .65rem; white-space: nowrap; color: var(--bs-secondary-color); }

/* ── Live Preview ── */
.preview-pane {
    background: var(--admin-surface-2);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--admin-radius);
    padding: 1rem;
    min-height: 80px;
    font-size: .9375rem;
    margin-top: .5rem;
    line-height: 1.7;
}
.preview-pane-label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--bs-secondary-color);
    margin-bottom: .3rem;
}
.preview-pane {
    overflow-wrap: break-word;
    word-break: break-word;
    overflow-x: auto;
    max-width: 100%;
}

/* ── Question form responsive layout ── */
.q-form-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; }
.q-form-grid > * { min-width: 0; }
.editor-split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: stretch; }
.editor-split > * { min-width: 0; }
.editor-split textarea {
    width: 100%;
    height: var(--pane-h, 40vh);
    box-sizing: border-box;
    resize: vertical;
    font-family: var(--font-mono);
    font-size: .875rem;
}
.editor-split textarea#solution {
    overflow-y: auto;
    resize: none;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.editor-split textarea#solution::-webkit-scrollbar { display: none; }
.editor-preview { display: flex; flex-direction: column; }
.editor-split .preview-pane {
    margin-top: 0;
    flex: 1;
    height: var(--pane-h, 40vh);
    overflow: auto;
    box-sizing: border-box;
}
@media (max-width: 992px) {
    .q-form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .editor-split { grid-template-columns: 1fr; }
    .editor-split textarea,
    .editor-split .preview-pane { height: auto; min-height: 180px; }
}

/* ── Dashboard stat cards ── */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.75rem; }
.dash-card {
    background: var(--admin-surface);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--admin-radius);
    padding: 1.5rem 1.25rem;
    text-align: center;
    box-shadow: var(--admin-shadow);
    transition: box-shadow .15s, transform .15s;
}
.dash-card:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); }
.dash-card .dash-num { font-size: 2rem; font-weight: 700; color: var(--bs-primary); line-height: 1; }
.dash-card .dash-lbl { font-size: .8rem; font-weight: 500; color: var(--bs-secondary-color); margin-top: .35rem; text-transform: uppercase; letter-spacing: .04em; }

/* ── Admin Login ── */
.jee-login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--admin-page-bg);
    padding: 1rem;
}
.jee-login-card {
    background: var(--admin-surface);
    border: 1px solid var(--bs-border-color);
    border-radius: calc(var(--admin-radius) * 2);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}
.jee-login-card .login-icon {
    width: 52px;
    height: 52px;
    background: rgba(var(--bs-primary-rgb), .1);
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin: 0 auto 1.5rem;
    color: var(--bs-primary);
}
.jee-login-card h1 { font-size: 1.25rem; font-weight: 700; text-align: center; margin-bottom: .35rem; }
.jee-login-card .login-subtitle { text-align: center; color: var(--bs-secondary-color); font-size: .875rem; margin-bottom: 1.75rem; }

/* ── Responsive: collapse sidebar on small screens ── */
@media (max-width: 991px) {
    .jee-sidebar { transform: translateX(-265px); }
    .jee-sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0, 0, 0, .2); }
    .jee-admin-body { margin-left: 0; }
    .jee-mobile-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: none;
        background: var(--admin-surface-2);
        border-radius: 0;
        cursor: pointer;
        color: var(--bs-body-color);
        font-size: 1.2rem;
    }
    .jee-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .45);
        z-index: 99;
        display: none;
    }
    .jee-overlay.active { display: block; }
    .jee-collapse-toggle { display: none; }
}
@media (min-width: 992px) {
    .jee-mobile-toggle { display: none !important; }
}

/* ── Theme toggle button (shared markup with the public site) ── */
#theme-toggle .icon-sun  { display: none; }
[data-bs-theme="dark"] #theme-toggle .icon-sun  { display: inline; }
[data-bs-theme="dark"] #theme-toggle .icon-moon { display: none; }

/* ── Ad containers (Google AdSense) ── */
.ad-container {
    margin: 2rem 0 0.5rem;
    padding: 0.5rem 0 0;
    text-align: center;
    clear: both;
}
.ad-container .ad-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
    margin-bottom: 0.35rem;
}
.ad-container .adsbygoogle { display: block; }
.ad-container .ad-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 90px;
    border: 1px dashed var(--bs-border-color);
    border-radius: var(--admin-radius);
    background: var(--admin-surface-2);
    color: var(--bs-secondary-color);
    font-size: 0.8rem;
}
