/* =========================================================
   Student Care v3.0.0 — Complete UX/UI & Responsive Remaster
   Layered after app.css so legacy screens keep their logic while
   receiving one coherent design system, responsive behavior and
   institution-aware theme.
   ========================================================= */

:root {
    --page-bg: #f6f8fc;
    --page-bg-soft: #fbfcff;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --surface-muted: #f1f4f8;
    --text: #17213a;
    --text-soft: #34445f;
    --muted: #6d7a90;
    --muted-2: #8994a6;
    --border: #dfe6f0;
    --border-strong: #cbd6e5;
    --green: #1f8759;
    --mint: #e5f7ef;
    --amber: #a86900;
    --amber-soft: #fff4d8;
    --red: #c94252;
    --red-soft: #fff0f2;
    --critical: #941d3b;
    --critical-soft: #ffe8ee;
    --cyan: #18748a;
    --cyan-soft: #e8f8fb;

    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
    --font-size-body: clamp(15.5px, .18vw + 14.9px, 17px);
    --line-body: 1.68;
    --content-max: 1520px;
    --reading-max: 920px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-7: 32px;
    --space-8: 40px;
    --space-9: 48px;

    --radius-xs: 9px;
    --radius-sm: 13px;
    --radius-md: 17px;
    --radius-lg: 22px;
    --radius-xl: 30px;
    --radius-pill: 999px;

    --shadow-xs: 0 2px 8px rgba(28, 42, 68, .045);
    --shadow-sm: 0 8px 24px rgba(28, 42, 68, .065);
    --shadow-md: 0 18px 48px rgba(28, 42, 68, .085);
    --shadow-focus: 0 0 0 4px rgba(var(--primary-rgb, 49,86,211), .14);

    /* Default values are intentionally overridden by the dynamic
       :root injected after this file on installed systems. */
    --primary: #3156d3;
    --primary-rgb: 49,86,211;
    --primary-dark: #2847ad;
    --primary-deep: #20378a;
    --primary-light: #879be5;
    --primary-soft: #e7edff;
    --primary-softer: #f3f6ff;
    --primary-border: #becaf2;
    --on-primary: #ffffff;
}

/* ---------- Foundation / typography ---------- */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    background: var(--page-bg);
}
body {
    font-family: var(--font-sans);
    font-size: var(--font-size-body);
    line-height: var(--line-body);
    color: var(--text);
    background: var(--page-bg);
    text-rendering: optimizeLegibility;
    font-kerning: normal;
}
body, button, input, select, textarea { font-family: var(--font-sans); }

h1, h2, h3, h4, h5, h6,
p, li, label, legend, strong, small, span, a, button, td, th {
    word-break: normal;
    overflow-wrap: break-word;
}
h1, h2, h3, h4, h5, h6 {
    color: var(--text);
    line-height: 1.26;
    text-wrap: balance;
}
p, li { text-wrap: pretty; }
.lead { color: var(--muted); line-height: 1.75; }
.muted { color: var(--muted) !important; }
.eyebrow {
    color: var(--primary);
    letter-spacing: .055em;
    line-height: 1.45;
}

.container {
    width: min(var(--content-max), calc(100% - clamp(28px, 4vw, 64px)));
}
.container-narrow { width: min(760px, calc(100% - clamp(24px, 5vw, 48px))); }
.container-survey { width: min(1040px, calc(100% - clamp(24px, 5vw, 48px))); }
.page-space { padding-block: clamp(28px, 4vw, 52px) clamp(52px, 7vw, 88px); }

/* Never allow generic text-field rules to turn radios and checkboxes
   into giant 48px-wide controls. This was the primary cause of text
   compression in the Student Voice screen. */
input[type="radio"],
input[type="checkbox"] {
    width: 19px;
    height: 19px;
    min-width: 19px;
    min-height: 19px;
    margin: 0;
    padding: 0;
    flex: 0 0 19px;
    accent-color: var(--primary);
    box-shadow: none;
}

input:not([type="radio"]):not([type="checkbox"]):not([type="color"]),
select,
textarea {
    min-height: 48px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    color: var(--text);
    background: #fff;
    line-height: 1.5;
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
textarea { min-height: 108px; }
input:not([type="radio"]):not([type="checkbox"]):not([type="color"]):hover,
select:hover,
textarea:hover { border-color: var(--primary-border); }
input:not([type="radio"]):not([type="checkbox"]):focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 0;
    border-color: var(--primary);
    box-shadow: var(--shadow-focus);
}
input[type="file"] { overflow: hidden; }
input[type="color"] {
    width: 74px;
    height: 46px;
    min-height: 46px;
    padding: 4px;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
}

.field { gap: 7px; min-width: 0; }
.field > span, fieldset > legend { line-height: 1.5; }
.field > span { color: var(--text-soft); font-weight: 800; }
.field small, .form-note { color: var(--muted); line-height: 1.55; }
.form-grid { gap: clamp(14px, 2vw, 20px); }
.form-stack { gap: clamp(16px, 2.4vw, 24px); }

/* ---------- Buttons / interactive states ---------- */
.button {
    min-height: 44px;
    padding: 10px 17px;
    border-radius: var(--radius-sm);
    line-height: 1.35;
    font-weight: 850;
    box-shadow: none;
    transition: background .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease;
}
.button:hover { transform: none; }
.button:focus-visible,
a:focus-visible,
.menu-toggle:focus-visible {
    outline: 0;
    box-shadow: var(--shadow-focus);
}
.button-primary,
.student-link {
    color: var(--on-primary);
    background: var(--primary);
    box-shadow: 0 8px 20px rgba(var(--primary-rgb), .18);
}
.button-primary:hover,
.student-link:hover { color: var(--on-primary); background: var(--primary-dark); }
.button-secondary {
    color: var(--text-soft);
    border: 1px solid var(--border);
    background: var(--surface-muted);
}
.button-secondary:hover { border-color: var(--primary-border); background: var(--primary-softer); }
.staff-link {
    color: var(--primary-dark);
    border: 1px solid var(--primary-border);
    background: var(--primary-softer);
}
.button-small { min-height: 36px; padding: 7px 11px; }
.button-large { min-height: 50px; padding: 13px 22px; }

/* ---------- Shared surfaces ---------- */
.card, .panel, .metric-card, .campaign-card, .tool-link-card {
    border-color: var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}
.card, .panel { border-radius: var(--radius-lg); }
.panel { padding: clamp(18px, 2.5vw, 26px); }
.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}
.panel-heading > * { min-width: 0; }
.panel-heading h2 { font-size: clamp(1.04rem, 1.5vw, 1.18rem); }
.panel-heading p { font-size: .82rem; line-height: 1.55; }
.alert {
    border-radius: var(--radius-md);
    padding: 14px 16px;
    line-height: 1.6;
    box-shadow: none;
}

/* ---------- Institution-aware branding ---------- */
.brand-mark {
    color: var(--on-primary);
    background: linear-gradient(145deg, var(--primary-light), var(--primary-dark));
    box-shadow: 0 8px 22px rgba(var(--primary-rgb), .23);
}
.brand-mark-logo { background: #fff; }
.progress-bar,
.student-preview-progress i,
.factor-track i {
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
}
.pagination-page:hover { background: var(--primary-softer); }
.pagination-page.is-current { color: var(--on-primary); background: var(--primary); border-color: var(--primary); }
.case-in_progress { color: var(--primary-deep); background: var(--primary-soft); }
.formula-box,
.risk-hero:not(.high):not(.urgent):not(.watch) {
    background: linear-gradient(135deg, var(--primary-deep), var(--primary));
}
.criteria-callout {
    border-color: var(--primary-border);
    background: var(--primary-softer);
}

/* ---------- Public header / student shell ---------- */
.public-header {
    z-index: 50;
    border-bottom: 1px solid rgba(215,224,237,.86);
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(18px) saturate(1.2);
}
.header-inner {
    min-height: 74px;
    gap: 18px;
}
.brand { min-width: 0; }
.brand > span:last-child { min-width: 0; }
.brand strong,
.brand small {
    max-width: min(44vw, 520px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.public-nav { min-width: 0; flex-wrap: wrap; }
.public-nav a { min-height: 40px; display: inline-flex; align-items: center; }

.student-experience {
    --student-mint: #e9f9f3;
    --student-mint-text: #247965;
    --student-peach: #fff0e8;
    --student-peach-text: #b96345;
    --student-sun: #fff8de;
    --student-lilac: #f4efff;
    --student-ink: #263a5b;
    --student-muted: #6f7f95;
    color: var(--student-ink);
    background:
        radial-gradient(circle at 8% 12%, rgba(var(--primary-rgb), .07), transparent 22rem),
        radial-gradient(circle at 90% 25%, rgba(255,190,145,.13), transparent 24rem),
        #f9fbff;
}
.student-experience .public-header { background: rgba(255,255,255,.86); }
.student-experience .public-footer { background: rgba(255,255,255,.9); }

/* ---------- Student landing: bright, soft, friendly ---------- */
.shape-home {
    min-height: 80vh;
    background:
        radial-gradient(circle at 88% 8%, var(--primary-soft) 0, transparent 28%),
        radial-gradient(circle at 4% 42%, #fff1d9 0, transparent 24%),
        linear-gradient(180deg, #fbfdff 0%, #fff 72%);
}
.shape-hero { padding: clamp(44px, 7vw, 82px) 0 34px; }
.shape-hero-inner {
    grid-template-columns: minmax(0, 1.05fr) minmax(320px, .75fr);
    gap: clamp(30px, 5vw, 70px);
    align-items: center;
}
.shape-kicker {
    color: var(--primary-dark);
    border-color: var(--primary-border);
    background: rgba(255,255,255,.86);
}
.shape-copy h1 {
    max-width: 760px;
    margin: 18px 0 14px;
    color: var(--student-ink);
    font-size: clamp(2.8rem, 6vw, 5.65rem);
    line-height: .98;
    letter-spacing: -.045em;
}
.shape-copy h1 span { color: var(--primary); }
.shape-copy > p { color: var(--student-muted); font-size: clamp(1rem, 1.4vw, 1.12rem); line-height: 1.75; }
.shape-round-pill {
    width: fit-content;
    max-width: 100%;
    color: var(--primary-dark);
    background: var(--primary-softer);
    border: 1px solid var(--primary-border);
    white-space: normal;
}
.shape-art {
    border: 1px solid rgba(var(--primary-rgb), .10);
    background: rgba(255,255,255,.75);
    box-shadow: var(--shadow-md);
}
.art-students span {
    color: var(--primary-dark);
    background: linear-gradient(160deg, var(--primary-soft), #fff);
}
.art-students span + span { color: #3e8d7b; background: linear-gradient(160deg,#e8faf4,#fff); }
.art-one { color: #e99b43; background: #fffaf0; }
.art-two { color: #e77895; background: #fff6f8; }
.art-three { color: #32957d; background: #f2fcf8; }

.shape-actions {
    grid-template-columns: repeat(3, minmax(0,1fr));
    gap: clamp(12px, 2vw, 18px);
}
.shape-action {
    grid-template-columns: 58px minmax(0,1fr) 26px;
    min-height: 112px;
    border-radius: 26px;
    border: 1px solid rgba(210,220,234,.72);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}
.shape-action > strong,
.shape-action > small { grid-column: 2; min-width: 0; }
.shape-action > i { grid-column: 3; }
.shape-action-blue { color: var(--primary-dark); background: var(--primary-soft); }
.shape-action-blue .shape-action-icon { color: var(--primary); }
.shape-action-mint { color: var(--student-mint-text); background: var(--student-mint); }
.shape-action-peach { color: var(--student-peach-text); background: var(--student-peach); }
.shape-action small { opacity: .78; }
.shape-trust span { box-shadow: var(--shadow-xs); }
.shape-trust b { color: var(--primary); }
.shape-help {
    border-color: rgba(var(--primary-rgb), .12);
    background: linear-gradient(130deg, #fff8f3, var(--primary-softer));
    box-shadow: var(--shadow-xs);
}
.shape-help-heart { color: #e46f8a; background: #fff; }

/* ---------- Student portal / profile ---------- */
.student-portal { padding-block: clamp(26px, 4vw, 44px) clamp(54px, 7vw, 82px); }
.student-shape-dashboard {
    padding: clamp(20px, 3vw, 34px);
    border-color: rgba(var(--primary-rgb), .13);
    border-radius: 32px;
    background:
        radial-gradient(circle at 94% 4%, var(--primary-soft), transparent 28%),
        radial-gradient(circle at 4% 100%, #fff0db, transparent 24%),
        linear-gradient(135deg,#fbfdff,#f8fffc);
    box-shadow: var(--shadow-md);
}
.portal-blob-a { background: var(--primary-soft); }
.student-shape-person { gap: 20px; }
.student-shape-person > div { min-width: 0; }
.student-shape-person h1 {
    margin: 3px 0 4px;
    color: var(--student-ink);
    font-size: clamp(1.45rem, 3vw, 2rem);
    line-height: 1.3;
}
.student-shape-person p { line-height: 1.55; }
.profile-avatar-fallback {
    color: var(--on-primary);
    background: linear-gradient(145deg, var(--primary-light), var(--primary));
}
.student-shape-actions {
    grid-template-columns: repeat(3, minmax(0,1fr));
    gap: 14px;
}
.portal-action {
    grid-template-columns: 50px minmax(0,1fr) 22px;
    grid-template-rows: auto auto;
    min-height: 96px;
    gap: 3px 12px;
    padding: 17px;
    border-radius: 22px;
    overflow: hidden;
}
.portal-action > b { grid-column: 1; grid-row: 1 / 3; }
.portal-action > strong,
.portal-action > small { grid-column: 2; min-width: 0; }
.portal-action > i { grid-column: 3; grid-row: 1 / 3; }
.portal-action strong { line-height: 1.38; }
.portal-action small {
    line-height: 1.42;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
}
.portal-action.is-done { grid-template-columns: 50px minmax(0,1fr); }
.portal-action.is-done > strong,
.portal-action.is-done > small { grid-column: 2; }
.portal-blue { color: var(--primary-dark); background: var(--primary-soft); }
.portal-mint { color: var(--student-mint-text); background: var(--student-mint); }
.portal-peach { color: var(--student-peach-text); background: var(--student-peach); }
.student-shape-chips span {
    color: var(--text-soft);
    background: rgba(255,255,255,.88);
    border-color: var(--border);
}
.student-dashboard-grid { gap: 18px; }
.student-campaign {
    gap: 18px;
    border-radius: var(--radius-md);
    background: #fff;
}
.student-campaign.is-highlighted {
    border-color: var(--primary-border);
    background: var(--primary-softer);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .07);
}
.student-campaign > div { min-width: 0; }
.student-campaign .button { flex: 0 0 auto; }
.simple-history > div { background: var(--surface-soft); }
.student-portal-help { margin-top: 22px; }

.profile-self-card {
    border-color: rgba(var(--primary-rgb), .12);
    background: linear-gradient(135deg,#fff,var(--primary-softer));
}
.profile-photo-editor { background: rgba(var(--primary-rgb), .045); }

/* ---------- Assessment flow ---------- */
.student-experience .container-survey { width: min(1040px, calc(100% - clamp(24px, 5vw, 54px))); }
.survey-heading { max-width: var(--reading-max); }
.survey-heading h1 { color: var(--student-ink); }
.survey-progress {
    top: 86px;
    border-color: rgba(var(--primary-rgb), .13);
    background: rgba(255,255,255,.94);
    box-shadow: 0 8px 24px rgba(28,42,68,.055);
}
.survey-section.card {
    padding: clamp(20px, 4vw, 38px);
    border-color: rgba(var(--primary-rgb), .11);
    box-shadow: var(--shadow-sm);
}
.section-title { gap: 14px; }
.section-title > span {
    color: var(--primary-dark);
    background: var(--primary-soft);
}
.section-title > div { min-width: 0; }
.section-title p { line-height: 1.62; }
.question-card { padding: 22px 0; }
.question-card legend {
    color: var(--student-ink);
    line-height: 1.62;
}
.question-number { color: var(--primary-dark); background: var(--primary-soft); }
.question-help { margin-left: 38px; line-height: 1.55; }
.question-choice-row,
.choice-row {
    grid-template-columns: repeat(4, minmax(0,1fr));
    gap: 10px;
}
.choice span {
    min-height: 68px;
    padding: 11px 10px;
    border-color: var(--border);
    background: #fbfcfe;
    line-height: 1.4;
}
.choice input:checked + span {
    border-color: var(--primary);
    background: var(--primary-softer);
    box-shadow: inset 0 0 0 1px var(--primary), 0 0 0 3px rgba(var(--primary-rgb), .08);
}
.choice b { color: var(--primary-dark); }
.assessment-identity-person > div { min-width: 0; }
.profile-confirm-note { border-color: #b8e4d0; }

/* Student Voice — explicit two-column grid, never a giant radio column */
.student-message-section {
    background:
        radial-gradient(circle at 100% 0%, var(--primary-soft), transparent 22rem),
        #fff;
}
.student-message-card {
    padding: clamp(16px, 3vw, 24px);
    border: 1px solid rgba(var(--primary-rgb), .13);
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg,#fff,var(--primary-softer));
}
.message-privacy-note {
    border: 1px solid rgba(var(--primary-rgb), .10);
    background: var(--primary-softer);
    color: var(--text-soft);
}
.contact-preference {
    display: grid;
    gap: 10px;
    margin-top: 16px;
    padding: 0;
    border: 0;
}
.contact-preference > legend {
    width: 100%;
    margin-bottom: 2px;
    color: var(--text);
    font-weight: 900;
    line-height: 1.55;
}
.contact-preference label {
    display: grid;
    grid-template-columns: 22px minmax(0,1fr);
    align-items: start;
    gap: 12px;
    min-width: 0;
    padding: 14px 15px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: rgba(255,255,255,.9);
    cursor: pointer;
}
.contact-preference label:hover { border-color: var(--primary-border); background: #fff; }
.contact-preference label:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-softer);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .08);
}
.contact-preference label input { margin-top: 3px; }
.contact-preference label span {
    display: grid;
    gap: 3px;
    min-width: 0;
}
.contact-preference label b { color: var(--text); line-height: 1.45; }
.contact-preference label small { color: var(--muted); line-height: 1.55; }
.urgent-help-choice {
    display: grid;
    grid-template-columns: 22px minmax(0,1fr);
    align-items: start;
    gap: 12px;
    min-width: 0;
    margin-top: 14px;
    padding: 15px;
    border: 1px solid #ffc5cf;
    border-radius: 16px;
    background: #fff5f7;
}
.urgent-help-choice input { margin-top: 3px; }
.urgent-help-choice span { min-width: 0; }
.urgent-help-choice strong { color: #a5112f; line-height: 1.5; }
.urgent-help-choice small { color: #80515a; line-height: 1.55; }

.survey-actions {
    gap: 12px;
    padding: 14px 0 2px;
}
.survey-action-hint { color: var(--muted); line-height: 1.5; }

/* ---------- Staff/Admin professional workspace ---------- */
.staff-experience,
.admin-body { background: #f4f6fa; }
.admin-shell { grid-template-columns: 272px minmax(0,1fr); }
.admin-sidebar {
    width: auto;
    padding: 20px 15px;
    color: #edf2fb;
    background:
        radial-gradient(circle at 20% 0%, rgba(var(--primary-rgb), .22), transparent 18rem),
        linear-gradient(180deg,#17233a,#111a2d);
    border-right: 1px solid rgba(255,255,255,.06);
}
.admin-brand { gap: 12px; padding: 4px 8px 20px; }
.admin-brand strong { line-height: 1.35; }
.admin-brand small { color: #aebbd0; }
.admin-nav { gap: 4px; padding: 18px 0; }
.admin-nav a {
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 12px;
    color: #bdc8db;
    line-height: 1.42;
}
.admin-nav a:hover { color: #fff; background: rgba(255,255,255,.07); }
.admin-nav a.is-active {
    color: var(--on-primary);
    background: var(--primary);
    box-shadow: 0 8px 22px rgba(var(--primary-rgb), .22);
}
.nav-dot { background: #70809b; }
.admin-nav a.is-active .nav-dot {
    background: var(--on-primary);
    box-shadow: 0 0 0 4px rgba(255,255,255,.13);
}
.sidebar-footer small { color: #aebbd0; }
.admin-main { min-width: 0; }
.admin-topbar {
    min-height: 72px;
    padding-inline: clamp(16px, 3vw, 36px);
    border-bottom-color: var(--border);
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(16px) saturate(1.15);
}
.admin-topbar > div { min-width: 0; }
.admin-topbar p,
.admin-topbar strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.admin-topbar strong { color: var(--text); font-size: 1rem; }
.view-public { color: var(--primary); white-space: nowrap; }
.menu-toggle { background: var(--surface-muted); }
.admin-content {
    width: 100%;
    max-width: var(--content-max);
    padding: clamp(22px,3vw,36px) clamp(16px,3vw,38px) 72px;
}
.page-heading {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    gap: 20px;
    align-items: start;
    margin-bottom: 24px;
}
.page-heading > div { min-width: 0; }
.page-heading h1 { font-size: clamp(1.75rem, 3vw, 2.55rem); }
.page-heading > div > p:last-child { max-width: 900px; line-height: 1.6; }
.page-heading > .button,
.page-heading > .campaign-filter,
.page-heading > .panel-actions { align-self: start; }
.campaign-filter { min-width: 0; }
.campaign-filter select { min-width: min(340px, 38vw); max-width: 100%; }

.metric-grid {
    grid-template-columns: repeat(4, minmax(180px,1fr));
    gap: 14px;
}
.metric-card {
    min-height: 128px;
    padding: 18px 19px;
    border-radius: var(--radius-md);
    overflow: hidden;
}
.metric-card strong { font-size: clamp(1.75rem,2.3vw,2.15rem); }
.dashboard-grid,
.lower-grid { gap: 18px; }
.kpi-ring {
    background: conic-gradient(var(--primary) calc(var(--value) * 1%), #e8edf5 0);
}

/* Tables: preserve readable typography instead of squeezing columns. */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: #fff;
    -webkit-overflow-scrolling: touch;
}
.table-wrap .data-table {
    min-width: 720px;
    border-collapse: separate;
    border-spacing: 0;
}
.data-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 11px 13px;
    color: var(--muted);
    background: #f7f9fc;
    border-bottom: 1px solid var(--border);
    font-size: .72rem;
    line-height: 1.4;
}
.data-table td {
    padding: 13px;
    border-bottom: 1px solid #edf1f5;
    line-height: 1.5;
    overflow-wrap: normal;
}
.data-table td code,
.data-table td .code-note { overflow-wrap: anywhere; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--primary-softer); }
.student-roster-table { min-width: 900px !important; }
.table-actions { flex-wrap: wrap; }

.pagination {
    gap: 10px;
    border-top-color: var(--border);
}
.pagination-page {
    border-color: var(--border);
    color: var(--text-soft);
}

/* Case management / forms */
.case-stepper li,
.case-summary-card > div,
.detail-item,
.simple-history > div { border: 1px solid #edf1f5; }
.case-stepper li.is-current {
    border-color: var(--primary-border);
    background: var(--primary-softer);
    box-shadow: inset 0 0 0 1px rgba(var(--primary-rgb), .08);
}
.timeline-item { border-left-color: var(--primary); background: #f8fafd; }
.group-picker-options > label:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-softer);
}

/* ---------- Assessment builder ---------- */
.assessment-builder-topbar,
.builder-panel,
.builder-preview-panel {
    border-color: var(--border);
    box-shadow: var(--shadow-xs);
}
.builder-mode-switch a.is-active,
.builder-mode-switch button.is-active { color: var(--on-primary); background: var(--primary); }
.builder-category-card.is-active {
    border-color: var(--primary);
    background: var(--primary-softer);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .07);
}
.builder-category-icon,
.builder-add-icon { color: var(--primary-dark); background: var(--primary-soft); }
.student-preview-progress i { background: var(--primary); }

/* ---------- Authentication / installer ---------- */
.install-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at 50% 0%, var(--primary-soft, #e7edff), transparent 34rem),
        #f6f8fc;
}
.installer-experience { --primary: #3156d3; --primary-rgb: 49,86,211; --primary-dark:#2443ad; --primary-light:#879be5; --primary-soft:#e7edff; --primary-softer:#f3f6ff; --primary-border:#becaf2; --on-primary:#fff; }
.auth-card {
    padding: clamp(22px,4vw,38px);
    border-radius: 26px;
    box-shadow: var(--shadow-md);
}
.auth-heading { margin-top: 22px; }
.auth-heading h1 { font-size: clamp(2rem,5vw,3rem); }
.student-login-card {
    border-color: rgba(var(--primary-rgb), .12);
    background: linear-gradient(145deg,#fff,var(--primary-softer));
}
.student-login-safe-note { border-color: #bce8d7; background: #f3fcf8; }

/* ---------- Semantic status colors remain fixed across themes ---------- */
.status-active, .dot-low, .priority-p5, .signal-normal { /* green stays green */ }
.status-draft { color:#5f6b80; background:#edf0f4; }
.priority-p1, .signal-urgent { color:#a5112f; background:#fff0f2; border-color:#ffc7d1; }
.priority-p2, .signal-followup { color:#a75300; background:#fff5e8; border-color:#ffd9a7; }
.priority-p3, .signal-watch { color:#806500; background:#fff9df; border-color:#f7df82; }
.priority-p4 { color:#2458b8; background:#eef5ff; border-color:#cbdcff; }
.priority-p5, .signal-normal { color:#217a48; background:#edf8f1; border-color:#c7ead4; }

/* ---------- Responsive: desktop -> laptop -> tablet -> phone ---------- */
@media (max-width: 1280px) {
    .admin-shell { grid-template-columns: 244px minmax(0,1fr); }
    .admin-sidebar { padding-inline: 12px; }
    .metric-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .shape-hero-inner { gap: 34px; }
    .student-shape-actions { grid-template-columns: repeat(3,minmax(0,1fr)); }
    .portal-action { grid-template-columns: 44px minmax(0,1fr) 18px; padding: 15px; }
    .portal-action > b { width:44px; height:44px; }
}

@media (max-width: 1100px) {
    .admin-shell { grid-template-columns: 1fr; }
    .admin-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 60;
        width: min(292px, 86vw);
        height: 100dvh;
        transform: translateX(-104%);
        transition: transform .2s ease;
        box-shadow: 18px 0 45px rgba(16,24,45,.25);
    }
    .admin-sidebar.is-open { transform: translateX(0); }
    .admin-body.sidebar-open { overflow: hidden; }
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 55;
        display: none;
        background: rgba(15,23,42,.48);
        backdrop-filter: blur(2px);
    }
    .sidebar-backdrop.is-open { display:block; }
    .menu-toggle { display:grid; place-items:center; flex:0 0 42px; }
    .shape-hero-inner { grid-template-columns: 1fr; }
    .shape-art { max-width: 720px; width:100%; margin-inline:auto; }
    .shape-copy { text-align:center; align-items:center; }
    .shape-copy > p { max-width:760px; }
    .student-shape-actions { grid-template-columns: 1fr 1fr; }
    .student-shape-actions > :last-child { grid-column: 1 / -1; }
    .question-choice-row, .choice-row { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 860px) {
    .container { width: min(100% - 28px, var(--content-max)); }
    .public-header { position: sticky; }
    .header-inner { min-height: 68px; }
    .brand strong { font-size: .92rem; }
    .brand small { font-size: .74rem; }
    .public-nav a { padding: 8px 11px; font-size: .82rem; }

    .page-heading { grid-template-columns: 1fr; }
    .page-heading > .button,
    .page-heading > .campaign-filter,
    .page-heading > .panel-actions { width: 100%; }
    .page-heading > .button { justify-self:stretch; }
    .campaign-filter select { min-width:0; width:100%; }
    .panel-heading { flex-direction:column; }
    .panel-actions { width:100%; justify-content:flex-start; }

    .form-grid,
    .detail-grid { grid-template-columns: 1fr; }
    .field-wide, .detail-wide { grid-column:auto; }
    .profile-admin-grid,
    .profile-self-card { grid-template-columns: 1fr; }
    .profile-photo-editor { max-width: 420px; width:100%; margin-inline:auto; }

    .student-shape-person { align-items:flex-start; }
    .student-dashboard-grid { grid-template-columns:1fr; }
    .student-campaign { align-items:flex-start; flex-direction:column; }
    .student-campaign .button { width:100%; }

    .assessment-identity { grid-template-columns:1fr; }
    .profile-confirm-note { grid-template-columns:34px minmax(0,1fr); }
    .profile-confirm-note .button { grid-column:1/-1; width:100%; }

    .shape-actions { grid-template-columns:1fr; }
    .shape-action { min-height:94px; }
    .shape-help { grid-template-columns:64px minmax(0,1fr); padding:22px; }
    .shape-help-heart { width:60px; height:60px; border-radius:20px; }
}

@media (max-width: 680px) {
    body { font-size: 16px; }
    .container,
    .container-narrow,
    .container-survey { width: min(100% - 22px, var(--content-max)); }
    .page-space { padding-block: 24px 50px; }

    .header-inner { min-height:64px; gap:10px; }
    .brand-mark { width:40px; height:40px; flex-basis:40px; border-radius:12px; }
    .brand strong { max-width:42vw; font-size:.86rem; }
    .brand small { display:none; }
    .public-nav { gap:5px; }
    .public-nav a { min-height:38px; padding:7px 9px; font-size:.76rem; }

    .card, .panel { border-radius:18px; }
    .card { padding:20px 17px; }
    .panel { padding:18px 16px; }
    .section-title { gap:11px; margin-bottom:20px; }
    .section-title > span { width:38px; height:38px; flex-basis:38px; }
    .section-title h2 { font-size:1.16rem; }

    .shape-copy h1 { font-size:clamp(2.55rem,13vw,3.6rem); }
    .shape-art { padding:16px; border-radius:24px; }
    .shape-actions { margin-top:0; }
    .shape-action { padding:17px; border-radius:21px; grid-template-columns:50px minmax(0,1fr) 22px; }
    .shape-action-icon { width:50px; height:50px; border-radius:17px; }
    .shape-help { grid-template-columns:1fr; padding:20px; border-radius:23px; }

    .student-shape-dashboard { padding:18px; border-radius:24px; }
    .student-shape-person { gap:13px; }
    .profile-avatar-xl { width:90px; height:90px; font-size:1.25rem; }
    .student-shape-actions { grid-template-columns:1fr; }
    .student-shape-actions > :last-child { grid-column:auto; }
    .portal-action { grid-template-columns:46px minmax(0,1fr) 20px; min-height:84px; padding:15px; }
    .portal-action > b { width:46px; height:46px; }
    .portal-action.is-done { grid-template-columns:46px minmax(0,1fr); }
    .student-shape-chips { gap:6px; }

    .survey-progress { top:72px; padding:12px 14px; }
    .survey-section.card { padding:20px 16px; }
    .question-card { padding:19px 0; }
    .question-help { margin-left:0; }
    .question-choice-row, .choice-row { grid-template-columns:1fr; }
    .choice span {
        min-height:54px;
        place-content:center start;
        text-align:left;
        padding:12px 14px;
    }
    .contact-preference label,
    .urgent-help-choice { padding:13px; }
    .survey-actions {
        position: sticky;
        bottom: 0;
        z-index: 12;
        margin-inline:-11px;
        padding:12px 11px calc(12px + env(safe-area-inset-bottom));
        border-top:1px solid var(--border);
        background:rgba(249,251,255,.94);
        backdrop-filter:blur(14px);
    }
    .survey-action-hint { order:-1; width:100%; margin:0 0 2px; text-align:center; font-size:.76rem; }
    .survey-actions .button { flex:1 1 130px; }

    .admin-topbar { min-height:64px; padding-inline:11px; gap:10px; }
    .admin-topbar p { display:none; }
    .admin-topbar strong { max-width:52vw; font-size:.9rem; }
    .view-public { max-width:34vw; overflow:hidden; text-overflow:ellipsis; font-size:.76rem; }
    .admin-content { padding:20px 11px 58px; }
    .page-heading { gap:14px; margin-bottom:18px; }
    .page-heading h1 { font-size:1.72rem; }
    .metric-grid { grid-template-columns:1fr 1fr; gap:10px; }
    .metric-card { min-height:112px; padding:15px; }
    .metric-card strong { font-size:1.65rem; }

    .table-wrap { border-radius:14px; }
    .table-wrap::after {
        content:"เลื่อนซ้าย–ขวาเพื่อดูข้อมูลเพิ่มเติม";
        position:sticky;
        left:0;
        display:block;
        width:max-content;
        max-width:100%;
        padding:6px 10px;
        color:var(--muted);
        background:#f8fafd;
        font-size:.68rem;
        border-top:1px solid var(--border);
    }
    .data-table th, .data-table td { padding:11px; }
    .pagination.pagination-wide { justify-content:center; }
    .pagination .button { flex:1 1 120px; }

    .auth-card { padding:22px 17px; border-radius:22px; }
}

@media (max-width: 430px) {
    .container,
    .container-narrow,
    .container-survey { width: min(100% - 16px, var(--content-max)); }
    .brand strong { max-width:38vw; }
    .public-nav .staff-link { display:none; }
    .shape-copy h1 { font-size:2.72rem; }
    .shape-copy > p { font-size:.96rem; }
    .shape-round-pill { font-size:.72rem; }
    .student-shape-person { flex-direction:column; }
    .profile-avatar-xl { width:78px; height:78px; }
    .metric-grid { grid-template-columns:1fr; }
    .metric-card { min-height:0; }
    .admin-topbar strong { max-width:48vw; }
    .view-public { font-size:0; width:40px; height:40px; display:grid; place-items:center; border-radius:11px; background:var(--primary-softer); }
    .view-public::before { content:"↗"; font-size:1rem; color:var(--primary); }
    .contact-preference label,
    .urgent-help-choice { grid-template-columns:20px minmax(0,1fr); gap:10px; }
    input[type="radio"],input[type="checkbox"] { width:18px; height:18px; min-width:18px; min-height:18px; flex-basis:18px; }
    .form-actions { flex-direction:column-reverse; }
    .form-actions .button { width:100%; }
}

@media (max-width: 360px) {
    body { font-size:15.5px; }
    .public-nav .student-link { padding-inline:8px; }
    .brand strong { max-width:36vw; }
    .shape-copy h1 { font-size:2.45rem; }
    .portal-action, .shape-action { grid-template-columns:44px minmax(0,1fr) 18px; gap:3px 9px; }
    .portal-action > b, .shape-action-icon { width:44px; height:44px; }
    .student-shape-dashboard { padding:15px; }
    .survey-section.card { padding:18px 14px; }
    .admin-content { padding-inline:8px; }
}

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

@media (forced-colors: active) {
    .button, .card, .panel, .portal-action, .shape-action, .contact-preference label { border:1px solid CanvasText; }
}

/* Theme picker live preview */
.theme-color-field { align-content:start; }
.theme-color-picker { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.theme-color-picker code { padding:7px 10px; border:1px solid var(--border); border-radius:10px; background:#fff; color:var(--text-soft); font-weight:800; }
.theme-preview { display:grid; grid-template-columns:34px minmax(0,1fr) 46px; align-items:center; gap:10px; margin-top:4px; padding:10px 12px; border:1px solid var(--primary-border); border-radius:13px; background:var(--primary-softer); }
.theme-preview span { width:34px; height:34px; border-radius:11px; background:var(--primary); box-shadow:0 6px 14px rgba(var(--primary-rgb),.18); }
.theme-preview b { min-width:0; color:var(--primary-dark); font-size:.82rem; }
.theme-preview i { height:9px; border-radius:99px; background:linear-gradient(90deg,var(--primary),var(--primary-light)); }

/* Remaining brand-accent surfaces that used legacy fixed blues */
.signal-blue { background: var(--primary-soft); }
.student-group-icon { color: var(--on-primary); background: linear-gradient(135deg,var(--primary),var(--primary-light)); }
.preview-round-icon { color: var(--primary); background: var(--primary-soft); }
.student-preview-actions button.is-primary { color:var(--on-primary); border-color:var(--primary); background:var(--primary); }
.builder-question-head .question-number,
.info-number { color:var(--primary-dark); background:var(--primary-soft); }

/* Earlier adaptive collapse for screens where multi-column admin layouts
   technically fit but make Thai labels unnaturally narrow. */
@media (max-width: 980px) {
    .dashboard-grid,
    .lower-grid,
    .split-layout,
    .criteria-grid,
    .question-category-management,
    .users-layout,
    .case-overview-grid,
    .case-layout,
    .care-hero-grid { grid-template-columns:1fr !important; }
    .case-sidebar { position:static; }
    .criteria-level-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
    .case-stepper { grid-template-columns:repeat(2,minmax(0,1fr)); }
    .case-status-tabs { grid-template-columns:repeat(3,minmax(0,1fr)); }
    .builder-critical-rules { grid-template-columns:1fr; }
    .critical-option-label { white-space:normal; overflow:visible; text-overflow:clip; line-height:1.45; }
}

@media (max-width: 560px) {
    .criteria-level-grid,
    .case-stepper,
    .case-status-tabs { grid-template-columns:1fr; }
    .case-action-options { grid-template-columns:1fr; }
    .mini-metrics,
    .case-mini-metrics,
    .intervention-grid,
    .today-work-grid { grid-template-columns:1fr 1fr; }
    .builder-answer-options { grid-template-columns:1fr; }
    .builder-critical-rules > div { grid-template-columns:1fr; }
}

@media (max-width: 380px) {
    .mini-metrics,
    .case-mini-metrics,
    .intervention-grid,
    .today-work-grid { grid-template-columns:1fr; }
}

/* =========================================================
   Student Care v3.1.0 — Responsive layout + Builder focus mode
   ========================================================= */

/* Installer uses the desktop space it actually has instead of squeezing
   KPI cards and Thai labels into the old narrow auth width. */
.installer-container {
    width: min(1180px, calc(100% - clamp(24px, 6vw, 72px)));
    max-width: 1180px;
}
.installer-card { overflow: hidden; }
.install-metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
    gap: 14px;
    align-items: stretch;
}
.install-metric-grid .metric-card {
    min-width: 0;
    width: auto;
    min-height: 126px;
}
.install-master-section,
.install-process {
    margin-top: 18px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-soft);
}
.install-section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.install-section-heading strong { color: var(--text); font-size: 1rem; }
.install-section-heading small { color: var(--muted); white-space: nowrap; }
.install-master-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
    gap: 10px;
}
.install-master-item {
    min-width: 0;
    padding: 12px 13px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: #fff;
}
.install-master-item strong,
.install-master-item small { display: block; overflow-wrap: anywhere; }
.install-master-item strong { color: var(--text); line-height: 1.45; }
.install-master-item small { margin-top: 4px; color: var(--muted); font-size: .76rem; }
.install-master-item.is-more { display: grid; place-items: center; text-align: center; background: var(--primary-softer); }
.install-stepper {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.install-stepper li {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: #fff;
}
.install-stepper b {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    color: var(--on-primary);
    background: var(--primary);
}
.install-stepper span { min-width: 0; line-height: 1.45; overflow-wrap: anywhere; }

/* Builder: two-column focus layout. Preview is now an on-demand drawer so
   the editor owns the reading width instead of permanently sharing it. */
.assessment-builder-grid {
    grid-template-columns: minmax(250px, .58fr) minmax(0, 1.72fr) !important;
    gap: 18px !important;
}
.builder-categories-panel,
.builder-questions-panel { min-width: 0; }
.builder-categories-panel {
    position: sticky;
    top: 84px;
    max-height: calc(100dvh - 104px);
    overflow: auto;
}
.builder-category-list { gap: 9px; }
.builder-category-card {
    grid-template-columns: 44px minmax(0,1fr) auto !important;
    min-height: 72px;
    padding: 11px 12px !important;
    gap: 11px !important;
}
.builder-category-card .builder-drag-handle { display: none; }
.builder-category-icon { width: 44px !important; height: 44px !important; }
.builder-category-copy strong { font-size: .9rem !important; line-height: 1.35; }
.builder-category-copy small { display: none !important; }
.builder-category-count { font-size: .74rem !important; white-space: nowrap; }
.builder-category-edit { grid-column: 3; }

.builder-questions-panel {
    padding: clamp(18px, 2vw, 26px) !important;
}
.builder-panel-heading h2 { font-size: clamp(1.08rem, 1.5vw, 1.3rem); }
.builder-panel-heading p { font-size: .82rem; }
.builder-question-tabs {
    display: flex;
    gap: 8px;
    margin: 14px 0 16px;
    padding: 4px 0 8px;
    overflow-x: auto;
    scrollbar-width: thin;
}
.builder-question-tab {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-soft);
    background: #f4f6fa;
    font: inherit;
    font-size: .84rem;
    font-weight: 800;
    cursor: pointer;
}
.builder-question-tab:hover { border-color: var(--primary-border); background: var(--primary-softer); }
.builder-question-tab.is-active {
    color: var(--on-primary);
    border-color: var(--primary);
    background: var(--primary);
    box-shadow: 0 6px 16px rgba(var(--primary-rgb), .18);
}
.builder-question-card { display: none; }
.builder-question-card.is-active {
    display: block;
    padding: clamp(16px, 2.1vw, 24px) !important;
    border-radius: 18px !important;
    box-shadow: var(--shadow-xs);
}
.builder-question-head { margin-bottom: 15px !important; }
.builder-question-head > strong { font-size: .9rem !important; }
.builder-question-text textarea {
    min-height: 92px !important;
    padding: 14px 15px !important;
    border-radius: 12px !important;
    font-size: 1rem !important;
    line-height: 1.58 !important;
}
.builder-field-label { margin: 18px 0 9px !important; font-size: .82rem !important; }
.builder-answer-options {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
}
.builder-answer-option {
    min-height: 52px;
    padding: 9px 11px !important;
    border-radius: 12px !important;
}
.builder-answer-option input { font-size: .86rem !important; line-height: 1.4 !important; }
.builder-question-settings {
    display: grid !important;
    grid-template-columns: minmax(0, .85fr) minmax(280px, 1.15fr);
    align-items: stretch !important;
    gap: 12px !important;
    margin-top: 16px !important;
}
.builder-weight-field,
.builder-toggle {
    min-width: 0;
    padding: 14px !important;
    border: 1px solid var(--border) !important;
    border-radius: 13px;
    background: var(--surface-soft);
}
.builder-weight-field {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0,1fr));
    gap: 7px !important;
}
.builder-weight-field legend {
    grid-column: 1 / -1;
    float: none !important;
    margin: 0 0 4px !important;
    font-size: .8rem !important;
}
.builder-weight-field label span { padding: 9px 8px !important; text-align: center; font-size: .76rem !important; }
.builder-toggle {
    display: grid !important;
    grid-template-columns: 42px minmax(0,1fr);
    align-content: center;
    justify-content: start !important;
    white-space: normal !important;
    line-height: 1.45;
    font-size: .8rem !important;
}
.builder-critical-rules {
    margin-top: 12px !important;
    padding: 12px !important;
    gap: 9px !important;
    border-radius: 13px !important;
}
.builder-critical-rules > div {
    grid-template-columns: minmax(0,1fr) minmax(150px, .55fr) !important;
    gap: 10px !important;
    padding: 5px !important;
}
.critical-option-label {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    font-size: .78rem !important;
    line-height: 1.45;
}
.builder-critical-rules select { min-height: 38px !important; font-size: .76rem !important; }
.builder-question-more { margin-top: 14px !important; padding-top: 12px !important; }
.builder-question-more summary { font-size: .78rem !important; }
.builder-add-question { margin-top: 14px !important; min-height: 46px; }

/* Preview drawer */
.builder-preview-panel {
    position: fixed !important;
    top: 0 !important;
    right: 0;
    z-index: 95;
    width: min(420px, 94vw);
    height: 100dvh;
    overflow-y: auto;
    padding: 18px !important;
    border: 0 !important;
    border-left: 1px solid var(--border) !important;
    border-radius: 0 !important;
    background: #fff;
    box-shadow: -22px 0 55px rgba(15,23,42,.18) !important;
    transform: translateX(104%);
    transition: transform .22s ease;
}
.builder-preview-panel.is-open { transform: translateX(0); }
.builder-preview-panel .builder-panel-heading {
    position: sticky;
    top: -18px;
    z-index: 2;
    margin: -18px -18px 14px;
    padding: 18px;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.builder-preview-close {
    width: 38px;
    height: 38px;
    min-height: 38px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 11px;
    color: var(--text-soft);
    background: #fff;
    font-size: 1.35rem;
    cursor: pointer;
}
.builder-preview-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: none;
    background: rgba(15,23,42,.42);
    backdrop-filter: blur(2px);
}
.builder-preview-backdrop.is-open { display: block; }
body.builder-preview-open { overflow: hidden; }
.builder-preview-panel .student-preview-card { margin-top: 6px; }
.builder-preview-panel .builder-advanced-card,
.builder-preview-panel .builder-tip-card { margin-top: 14px; }

@media (max-width: 980px) {
    .installer-container { width: min(100% - 28px, 920px); }
    .install-stepper { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .assessment-builder-grid { grid-template-columns: 1fr !important; }
    .builder-categories-panel { position: static; max-height: none; }
    .builder-category-list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0,1fr));
    }
}
@media (max-width: 680px) {
    .installer-container { width: min(100% - 18px, 680px); }
    .install-metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)) !important; }
    .install-stepper { grid-template-columns: 1fr; }
    .install-master-grid { grid-template-columns: 1fr; }
    .builder-category-list { grid-template-columns: 1fr; }
    .builder-question-settings { grid-template-columns: 1fr; }
    .builder-answer-options { grid-template-columns: 1fr !important; }
    .builder-critical-rules > div { grid-template-columns: 1fr !important; }
    .builder-preview-panel { width: 100vw; max-width: 100vw; }
}
@media (max-width: 430px) {
    .install-metric-grid { grid-template-columns: 1fr !important; }
    .install-section-heading { align-items: flex-start; flex-direction: column; gap: 3px; }
    .builder-question-card.is-active { padding: 15px 13px !important; }
    .builder-question-tabs { margin-inline: -4px; }
    .builder-weight-field { grid-template-columns: 1fr !important; }
    .builder-weight-field legend { grid-column: auto; }
}

/* =========================================================
   v3.4.1 — Classic v3.1 UI Restore compatibility fixes
   Keep the v3.1 visual language while preserving the later
   Admin Users responsive/table fixes discovered in production.
   ========================================================= */
.data-table td .code-note {
    overflow-wrap: normal;
    word-break: normal;
    white-space: nowrap;
}
.data-table .panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: max-content;
}
.data-table .button-small { white-space: nowrap; }

.users-layout { grid-template-columns: minmax(0,1fr) !important; }
.users-layout > .panel:last-child { max-width: 760px; }
.users-table { min-width: 1120px !important; }
.users-table th:nth-child(1) { min-width: 150px; }
.users-table th:nth-child(2) { min-width: 120px; }
.users-table th:nth-child(3) { min-width: 190px; }
.users-table th:nth-child(4) { min-width: 170px; }
.users-table th:nth-child(5) { min-width: 135px; }
.users-table th:nth-child(6) { min-width: 105px; }
.users-table th:nth-child(7) { min-width: 190px; }

@media (max-width: 760px) {
    .users-table { min-width: 0 !important; border-collapse: separate !important; }
    .users-table thead { display: none; }
    .users-table tbody { display: grid; gap: 10px; padding: 10px; }
    .users-table tr {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0;
        overflow: hidden;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        background: var(--surface);
    }
    .users-table td {
        display: grid;
        grid-template-columns: minmax(112px, 34%) minmax(0, 1fr);
        gap: 10px;
        align-items: start;
        padding: 10px 12px;
        border-bottom: 1px solid var(--border);
    }
    .users-table td:last-child { border-bottom: 0; }
    .users-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: .76rem;
        font-weight: 600;
        line-height: 1.45;
    }
    .users-table td.empty-cell { display: block; }
    .users-table td.empty-cell::before { display: none; }
    .users-table .panel-actions { min-width: 0; justify-content: flex-start; }
    .users-table .panel-actions form { width: auto; }
    .users-table .button-small { white-space: normal; }
}
@media (max-width: 520px) {
    .users-table td { grid-template-columns: 1fr; gap: 5px; }
}


/* =========================================================
   v3.4.2 — Friendly Validation, Toasts, Confirm & Password Strength
   ========================================================= */
.form-field-error {
    display: block;
    margin-top: 2px;
    color: #a52d3b !important;
    font-size: .79rem !important;
    font-weight: 750;
    line-height: 1.45 !important;
}
.field.has-error > input:not([type="radio"]):not([type="checkbox"]),
.field.has-error > select,
.field.has-error > textarea,
.field.has-error > .password-input-wrap > input,
.question-card.has-error,
fieldset.has-error {
    border-color: #df7180 !important;
}
.field.has-error > input:not([type="radio"]):not([type="checkbox"]),
.field.has-error > select,
.field.has-error > textarea,
.field.has-error > .password-input-wrap > input {
    background: #fffafb !important;
    box-shadow: 0 0 0 3px rgba(196, 58, 78, .08) !important;
}
.question-card.has-error,
fieldset.has-error {
    position: relative;
    border-radius: 14px;
    background: #fffafb;
    box-shadow: 0 0 0 3px rgba(196, 58, 78, .055);
}
.question-card.has-error { padding-inline: 14px; }
.validation-pulse { animation: validationPulse .52s ease-out; }
@keyframes validationPulse {
    0% { box-shadow: 0 0 0 0 rgba(196,58,78,.22); }
    100% { box-shadow: 0 0 0 8px rgba(196,58,78,0); }
}

.app-toast-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 2100;
    display: grid;
    gap: 10px;
    width: min(390px, calc(100vw - 28px));
    pointer-events: none;
}
.app-toast {
    display: grid;
    grid-template-columns: 30px minmax(0,1fr) 28px;
    gap: 10px;
    align-items: center;
    padding: 12px 12px 12px 13px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255,255,255,.98);
    box-shadow: 0 14px 36px rgba(23,33,58,.14);
    opacity: 0;
    transform: translateY(-8px) scale(.985);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: auto;
}
.app-toast.is-visible { opacity: 1; transform: translateY(0) scale(1); }
.app-toast-icon {
    width: 30px; height: 30px; display: grid; place-items: center;
    border-radius: 9px; background: var(--primary-soft); color: var(--primary-deep); font-weight: 900;
}
.app-toast-warning .app-toast-icon { background: var(--amber-soft); color: #815000; }
.app-toast-danger .app-toast-icon { background: var(--red-soft); color: #8f2534; }
.app-toast-success .app-toast-icon { background: var(--mint); color: #12623e; }
.app-toast-text { color: var(--text); font-size: .87rem; font-weight: 700; line-height: 1.45; }
.app-toast-close { border: 0; background: transparent; color: var(--muted); font-size: 1.25rem; cursor: pointer; padding: 2px; }

.app-confirm-layer { position: fixed; inset: 0; z-index: 2200; display: grid; place-items: center; padding: 20px; }
.app-confirm-layer[hidden] { display: none; }
.app-confirm-backdrop { position: absolute; inset: 0; background: rgba(16,25,44,.46); backdrop-filter: blur(3px); opacity: 0; transition: opacity .16s ease; }
.app-confirm-dialog {
    position: relative;
    width: min(460px, 100%);
    display: grid;
    grid-template-columns: 46px minmax(0,1fr);
    gap: 15px;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(23,33,58,.24);
    opacity: 0;
    transform: translateY(8px) scale(.98);
    transition: opacity .16s ease, transform .16s ease;
}
.app-confirm-layer.is-open .app-confirm-backdrop { opacity: 1; }
.app-confirm-layer.is-open .app-confirm-dialog { opacity: 1; transform: translateY(0) scale(1); }
.app-confirm-mark { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 14px; background: var(--primary-soft); color: var(--primary-deep); font-size: 1.15rem; font-weight: 900; }
.app-confirm-copy h2 { margin: 1px 0 7px; font-size: 1.08rem; }
.app-confirm-copy p { margin: 0; color: var(--text-soft); line-height: 1.6; }
.app-confirm-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 9px; margin-top: 4px; }
body.dialog-open { overflow: hidden; }

.password-strength { display: grid; gap: 7px; margin-top: 2px; }
.password-strength-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; font-size: .78rem; color: var(--muted); }
.password-strength-head strong { font-size: .79rem; color: var(--text-soft); }
.password-strength-track { height: 6px; overflow: hidden; border-radius: 999px; background: #e9edf3; }
.password-strength-track > span { display: block; height: 100%; width: 0; border-radius: inherit; background: #aab3c1; transition: width .2s ease, background .2s ease; }
.password-strength.is-weak .password-strength-head strong { color: #a52d3b; }
.password-strength.is-weak .password-strength-track > span { background: #d95a6a; }
.password-strength.is-medium .password-strength-head strong { color: #9b6500; }
.password-strength.is-medium .password-strength-track > span { background: #e5a62f; }
.password-strength.is-strong .password-strength-head strong { color: #14714a; }
.password-strength.is-strong .password-strength-track > span { background: #2c9a68; }
.password-strength-rules { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: .72rem; line-height: 1.45; }
.password-strength-rules span { color: var(--muted); }
.password-strength-rules .is-ok { color: #14714a; }
.password-match-message { min-height: 1.15em; margin-top: 1px; font-size: .76rem !important; font-weight: 750; }
.password-match-message.is-match { color: #14714a !important; }
.password-match-message.is-mismatch { color: #a52d3b !important; }

@media (max-width: 620px) {
    .app-toast-stack { top: 10px; right: 10px; width: calc(100vw - 20px); }
    .app-confirm-layer { padding: 12px; }
    .app-confirm-dialog { grid-template-columns: 40px minmax(0,1fr); padding: 18px; border-radius: 16px; }
    .app-confirm-mark { width: 40px; height: 40px; border-radius: 12px; }
    .app-confirm-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .password-strength-head { align-items: flex-start; }
    .password-strength-rules { display: grid; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
    .app-toast, .app-confirm-backdrop, .app-confirm-dialog, .password-strength-track > span { transition: none !important; }
    .validation-pulse { animation: none !important; }
}

/* =========================================================
   Student Care v3.4.4 — Contextual Case Workspace
   ========================================================= */
.case-context-bar {
    position: sticky;
    top: 72px;
    z-index: 17;
    width: 100%;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(16px) saturate(1.08);
    box-shadow: 0 8px 22px rgba(23,33,58,.05);
}
.case-context-inner {
    width: 100%;
    max-width: var(--content-max);
    min-height: 76px;
    margin: 0 auto;
    padding: 10px clamp(16px,3vw,38px);
    display: grid;
    grid-template-columns: minmax(220px,.95fr) minmax(300px,1.35fr) auto;
    align-items: center;
    gap: 14px 18px;
}
.case-context-identity { min-width: 0; display: grid; gap: 2px; }
.case-context-identity strong {
    min-width: 0;
    overflow: hidden;
    color: var(--text);
    font-size: 1.02rem;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.case-context-identity span {
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: .73rem;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.case-context-badges { min-width: 0; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.context-priority-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 28px;
    padding: 5px 9px;
    border: 1px solid var(--border);
    border-radius: 9px;
    font-size: .72rem;
    font-weight: 900;
    line-height: 1.25;
    white-space: nowrap;
    background: #fff;
}
.context-priority-badge.priority-p1 { color:#8f1832; border-color:#f1a9b9; background:#fff4f6; }
.context-priority-badge.priority-p2 { color:#8a4d00; border-color:#f0c17e; background:#fff8ec; }
.context-priority-badge.priority-p3 { color:#6d5700; border-color:#e7d275; background:#fffced; }
.context-priority-badge.priority-p4 { color:#3156a5; border-color:#bed0f4; background:#f5f8ff; }
.context-priority-badge.priority-p5 { color:#246545; border-color:#b9ddc8; background:#f4fbf6; }
.case-context-actions { display: flex; align-items: center; justify-content: flex-end; }
.case-context-primary { min-width: 118px; justify-content: center; white-space: nowrap; }
.case-context-readonly { color: var(--muted); font-size: .76rem; font-weight: 800; white-space: nowrap; }
.case-page-notice { margin-bottom: 18px; }

/* Layer order: Case modal 1500 < Toast 2100 < Confirm 2200.
   Feedback must never be hidden behind a workflow modal. */
.case-modal-layer {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: grid;
    place-items: center;
    padding: 18px;
}
.case-modal-layer[hidden] { display: none; }
.case-modal-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(16,25,44,.5);
    backdrop-filter: blur(4px);
    cursor: default;
    opacity: 0;
    transition: opacity .18s ease;
}
.case-modal {
    position: relative;
    z-index: 1;
    width: min(680px, 100%);
    max-height: min(820px, calc(100dvh - 36px));
    overflow: auto;
    padding: clamp(20px,3vw,30px);
    border: 1px solid var(--border);
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 26px 70px rgba(16,25,44,.22);
    opacity: 0;
    transform: translateY(14px) scale(.985);
    transition: opacity .18s ease, transform .18s ease;
}
.case-modal-layer.is-open .case-modal-backdrop { opacity: 1; }
.case-modal-layer.is-open .case-modal { opacity: 1; transform: translateY(0) scale(1); }
.case-modal-header {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    align-items: start;
    gap: 16px;
    margin-bottom: 14px;
}
.case-modal-header h2 { margin: 2px 0 5px; font-size: clamp(1.25rem,2.1vw,1.55rem); }
.case-modal-header p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.case-modal-close {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 11px;
    color: var(--text-soft);
    background: var(--surface-soft);
    font: inherit;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
}
.case-modal-close:hover { border-color: var(--primary-border); color: var(--primary); background: var(--primary-softer); }
.case-modal-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.case-modal-owner {
    display: grid;
    gap: 3px;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface-soft);
}
.case-modal-owner span, .case-modal-owner small { color: var(--muted); font-size: .74rem; }
.case-modal-owner strong { color: var(--text); font-size: .92rem; }
.case-modal-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 2px; }
body.case-modal-open { overflow: hidden; }

/* The opening form now lives in the contextual modal. Keep the active-work
   panel for real case activity only. */
.case-command-panel:target { scroll-margin-top: 172px; }

@media (max-width: 1120px) {
    .case-context-inner { grid-template-columns: minmax(220px,1fr) auto; }
    .case-context-badges { grid-column: 1 / -1; grid-row: 2; }
    .case-context-actions { grid-column: 2; grid-row: 1; }
}
@media (max-width: 760px) {
    .case-context-bar { top: 64px; }
    .case-context-inner {
        min-height: 0;
        grid-template-columns: minmax(0,1fr) auto;
        gap: 9px 10px;
        padding: 9px 11px 10px;
    }
    .case-context-identity strong { font-size: .93rem; }
    .case-context-identity span { font-size: .68rem; }
    .case-context-badges {
        grid-column: 1 / -1;
        gap: 5px;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 1px;
        scrollbar-width: none;
    }
    .case-context-badges::-webkit-scrollbar { display: none; }
    .case-context-badges > * { flex: 0 0 auto; }
    .case-context-primary { min-width: 92px; padding-inline: 11px; font-size: .78rem; }
    .case-modal-layer { padding: 10px; align-items: end; }
    .case-modal {
        width: 100%;
        max-height: calc(100dvh - 20px);
        padding: 20px 16px;
        border-radius: 18px 18px 12px 12px;
    }
    .case-modal-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .case-modal-actions .button { width: 100%; }
    .case-command-panel:target { scroll-margin-top: 156px; }
}
@media (max-width: 430px) {
    .case-context-inner { grid-template-columns: minmax(0,1fr); }
    .case-context-actions { grid-column: 1; grid-row: 3; }
    .case-context-primary { width: 100%; }
    .case-context-readonly { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .case-modal-backdrop, .case-modal { transition: none !important; }
}


/* v3.4.5 — all active case work stays inside a modal workspace. */
.case-modal-work { width: min(920px, 100%); padding-bottom: 0; }
.case-modal-work .case-modal-header,
.case-modal-work .case-modal-badges,
.case-modal-work .case-modal-current-task,
.case-modal-work .case-form-section { margin-inline: 0; }
.case-modal-current-task {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    gap: 14px;
    align-items: center;
    margin-bottom: 18px;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface-soft);
}
.case-modal-current-task div { display: grid; gap: 3px; min-width: 0; }
.case-modal-current-task span { color: var(--muted); font-size: .74rem; font-weight: 800; }
.case-modal-current-task strong { color: var(--text); font-size: .9rem; overflow-wrap: anywhere; }
.case-modal-current-task time { color: var(--text-soft); font-size: .78rem; font-weight: 800; white-space: nowrap; }
.case-modal-current-task.is-overdue { border-color: #efb5bf; background: #fff5f6; }
.case-modal-actions-sticky {
    position: sticky;
    bottom: 0;
    z-index: 3;
    margin: 8px -30px 0;
    padding: 14px 30px 18px;
    border-top: 1px solid var(--border);
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(10px);
}
.case-command-panel .case-work-details { display: none !important; }
@media (max-width: 760px) {
    .case-modal-current-task { grid-template-columns: 1fr; }
    .case-modal-current-task time { white-space: normal; }
    .case-modal-actions-sticky { margin-inline: -16px; padding: 12px 16px 14px; }
}
