/* ATLAS PSU - ui2-foundation.css
   UI2 layer 1 of 3. Owner: Jestone (lane J, branch ui2/jestone).
   Loads after main-style.css and the page's own stylesheet, before ui2-pages.css and ui2-polish.css.
   Rule: every selector starts with html.ui2 (dark: html.ui2[data-theme="dark"]).
   Colors come from tokens, font sizes in rem. No gradient, no shadow, no side-accent border.
   Guarded by tests/test_ui2_layers.py. */

/* S1 tokens
   J-02: tokens and type from the Figma foundations (picture 03) and FEEDBACK.md section 1 (decision D-9).
   The full table with light and night values and contrast ratios is docs/ui2/TOKENS.md.
   Existing tokens from main-style.css are reused by name; only values the proposal changes are restated here.
   Cascade note: html.ui2 outranks [data-theme="dark"], so every color restated here is restated again
   under html.ui2[data-theme="dark"]. Department blocks ([data-dept]) set none of these names.
   scripts/check_contrast.py reads both blocks below. Keep each value a plain hex, rgba or var(). */
html.ui2 {
  /* Text and borders (D-9) */
  --text-muted: #564c43;           /* was #6e6358; 7.5 to 1 on the page */
  --border-input: #8f857b;         /* inputs, selects, checkboxes, radios, switch outlines: 3 to 1 or more */
  --input-border: var(--border-input);
  --border-decor: var(--border-subtle);   /* cards and table lines keep the light decorative rule */

  /* Brand */
  --brand: #c0440a;                /* filled buttons, with --on-accent text (5.1 to 1) */
  --brand-text: #c0440a;           /* links, active nav labels, any orange text */
  --brand-hover: #9a3608;          /* hover fill of filled buttons, white text 7.2 to 1 (J-03) */

  /* Capacity: neutral within, amber above, danger for a hard violation. Never teal or orange. */
  --cap-within: var(--chart-ok);
  --cap-above: #b45309;
  --cap-hard: var(--ui-danger-fg);

  /* Class type: teal means Lecture, orange means Lab, nothing else. Always paired with the word. */
  --type-lecture: var(--ok);
  --type-lecture-soft: var(--ok-soft);
  --type-lab: #9a3608;
  --type-lab-soft: #fff3ee;

  /* Semantic status: text (fg), soft background (bg), border (bd). Always paired with text and an icon. */
  --ui-success-bd: #3d8a5a;
  --ui-warning-bd: #a8741f;
  --ui-danger-bd:  #c4554a;
  --ui-info-bd:    #3a8a91;

  /* Radius */
  --r-badge: 6px;
  --r-control: 8px;
  --r-card: 12px;

  /* Control height and page gutter (phone values first, wider screens below) */
  --ctl-h: 2.5rem;
  --gutter: var(--space-4);        /* 1rem phone */

  /* Spacing scale in rem: 0.25, 0.5, 0.75, 1, 1.5, 2, 3 (same names as main-style.css) */
  --sp-1: var(--space-1);
  --sp-2: var(--space-2);
  --sp-3: var(--space-3);
  --sp-4: var(--space-4);
  --sp-5: var(--space-5);
  --sp-6: var(--space-6);
  --sp-7: var(--space-7);

  /* Sidebar (decision D-1) */
  --side-w: 16.5rem;   /* U6-01: was 15rem; "Room Capacity Analytics" must fit on one row (one token, both shells) */
  --side-w-c: 4.25rem;
  /* U6-02: one content column for every shell. --page-max is the column box (padding included), centered beside the sidebar */
  --page-max: 1280px;
  --page-pad: var(--space-6);
  /* U4-10: undo toast colors. Same surface as .toast-notif: --clr-gray-900 is the dark warm neutral in light mode and the light
     neutral in dark mode, so the toast stands out in both. The action text is a primary tint that passes 4.5 to 1 on it. */
  --undo-bg: var(--clr-gray-900);
  --undo-fg: var(--text-inverse);
  --undo-action: var(--clr-primary-300);
  --undo-bar: var(--clr-primary-400);

  /* Focus ring: 2 px solid brand, 2 px offset. Used as outline, never as a shadow.
     main-style.css already owns --focus-ring as a box-shadow value used by ten rules, so the outline
     ring lives under these names and --focus-ring is left untouched. */
  --focus-ring-width: 2px;
  --focus-ring-offset: 2px;
  --focus-ring-color: var(--clr-primary-500);
  --focus-outline: var(--focus-ring-width) solid var(--focus-ring-color);

  /* Type roles, DM Sans. The root size is 14px (main-style.css), so 1rem is 14px.
     Body is 1rem (14px floor), nothing is smaller than 0.875rem (about 12px). */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fs-title: 1.75rem;             /* page title, 600 */
  --fs-section: 1.25rem;           /* section heading, 600 */
  --fs-body: 1rem;                 /* body, 400 */
  --lh-body: 1.6;
  --fs-label: 0.875rem;            /* label, 600 */
  --fs-small: 0.875rem;            /* the smallest size anywhere */
  --fs-kpi: 2.125rem;              /* KPI metric, 600 (no 700 face is shipped) */
  --fw-title: var(--fw-semibold);
  --fw-section: var(--fw-semibold);
  --fw-body: var(--fw-regular);
  --fw-label: var(--fw-semibold);
  --fw-kpi: var(--fw-semibold);
  --lh-tight: 1.25;
}

html.ui2[data-theme="dark"] {
  --text-muted: #a99d90;
  --border-input: #8f857b;         /* 4.1 to 1 or more on every night surface, no lighter step needed */
  --input-border: var(--border-input);
  --brand: #c0440a;
  --brand-text: #e8763f;
  --brand-hover: #9a3608;
  --cap-within: var(--chart-ok);
  --cap-above: #f0b97a;
  --type-lab: #f08a5d;
  --type-lab-soft: #3a2218;
  --ui-success-bd: #4fae74;
  --ui-warning-bd: #c98f3a;
  --ui-danger-bd:  #e07a6f;
  --ui-info-bd:    #4fa3aa;
}

@media (max-width: 900px) {
  html.ui2 { --ctl-h: max(2.75rem, 44px); }
}
@media (min-width: 768px) {
  html.ui2 { --gutter: var(--space-5); }
}
@media (min-width: 1024px) {
  html.ui2 { --gutter: var(--space-6); }
}

/* Placeholder text uses the muted token and is never lighter (FEEDBACK.md section 1, step 5). */
html.ui2 ::placeholder { color: var(--text-muted); opacity: 1; }

/* S2 components
   J-03: shared components from the Figma component specimens (picture 03) and FEEDBACK.md sections 2, 3, 4,
   7, 8, 11 and 13. Existing classes are restyled first (.btn and its variants, .ui-chip, .status-chip,
   .stat-card, .ui-card, form fields, .toast-notif, .ui-state, .ui-skeleton, .empty-state-msg, .ui-sheet),
   so every old page picks the look up without markup changes. New classes exist only for patterns the
   proposal introduces. The living reference is docs/ui2/specimen.html (dev only), checked by
   tests/test_ui2_components.py.

   Icons: the status, chevron and menu icons below are 24 px, stroke 2, round caps, used as masks so they
   take currentColor (the colour always comes from a token). They are inline because this step may only
   edit this file; a request to move them to assets/images/icons is logged in PROGRESS-UI.md.
   A native select cannot take a mask, so its chevron is a background picture drawn in the
   --text-secondary value of each theme (#524840 light, #cfc4b8 night). */
html.ui2:root {
  --ic-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
  --ic-alert: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z'/%3E%3Cline x1='12' y1='9' x2='12' y2='13'/%3E%3Cline x1='12' y1='17' x2='12.01' y2='17'/%3E%3C/svg%3E");
  --ic-error: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='15' y1='9' x2='9' y2='15'/%3E%3Cline x1='9' y1='9' x2='15' y2='15'/%3E%3C/svg%3E");
  --ic-info: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='16' x2='12' y2='12'/%3E%3Cline x1='12' y1='8' x2='12.01' y2='8'/%3E%3C/svg%3E");
  --ic-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  --ic-more: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='5' cy='12' r='1'/%3E%3Ccircle cx='12' cy='12' r='1'/%3E%3Ccircle cx='19' cy='12' r='1'/%3E%3C/svg%3E");
  --ic-empty: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='22 12 16 12 14 15 10 15 8 12 2 12'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E");
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23524840' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  --ctl-min: max(var(--ctl-h), var(--control-h));   /* 40 px laptop, 44 px phone (the 2.5rem token alone is 35 px) */
}
html.ui2[data-theme="dark"]:root {
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23cfc4b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

/* Focus: one ring everywhere, an outline never a shadow. Hover never replaces it. */
html.ui2 a[href]:focus-visible,
html.ui2 button:focus-visible,
html.ui2 input:focus-visible,
html.ui2 select:focus-visible,
html.ui2 textarea:focus-visible,
html.ui2 summary:focus-visible,
html.ui2 [tabindex]:not([tabindex="-1"]):focus-visible {
  outline: var(--focus-outline);
  outline-offset: var(--focus-ring-offset);
  box-shadow:none;
}
html.ui2 input:focus,
html.ui2 select:focus,
html.ui2 textarea:focus { box-shadow:none; border-color: var(--focus-ring-color); }

/* Buttons. Plain .btn keeps its main-style colours; the variants below set theirs. */
html.ui2 .btn {
  min-height: var(--ctl-min);
  padding: 0 var(--sp-4);
  border-width: 1px;
  border-style: solid;
  border-radius: var(--r-control);
  font-size: var(--fs-body);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  box-shadow:none;
}
html.ui2 .btn-primary,
html.ui2 .btn-hero { background: var(--brand); color: var(--on-accent); border-color: var(--brand); }
html.ui2 .btn-primary:hover,
html.ui2 .btn-hero:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--on-accent); }

html.ui2 .btn-secondary,
html.ui2 .btn-outline { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-input); }
html.ui2 .btn-secondary:hover,
html.ui2 .btn-outline:hover { background: var(--bg-surface-2); border-color: var(--text-secondary); color: var(--text-primary); }

html.ui2 .btn-tertiary {
  background: transparent; color: var(--brand-text); border-color: transparent;
  padding: 0 var(--sp-2); text-decoration: underline; text-underline-offset: 0.2em;
}
html.ui2 .btn-tertiary:hover { background: var(--bg-surface-2); color: var(--brand-text); text-decoration-thickness: 2px; }

html.ui2 .btn-ghost { background: transparent; color: var(--text-primary); border-color: transparent; }
html.ui2 .btn-ghost:hover { background: var(--bg-surface-2); color: var(--text-primary); }

/* Destructive: filled for the confirm button, outline for row actions such as Delete */
html.ui2 .btn-danger { background: var(--ui-danger-fg); color: var(--bg-surface); border-color: var(--ui-danger-fg); }
html.ui2 .btn-danger:hover { background: var(--ui-danger-fg); color: var(--bg-surface); text-decoration: underline; text-underline-offset: 0.2em; }
html.ui2 .btn-delete {
  min-height: var(--ctl-min); padding: 0 var(--sp-4); border-radius: var(--r-control);
  background: var(--bg-surface); color: var(--ui-danger-fg); border: 1px solid var(--ui-danger-bd);
  font-size: var(--fs-body); font-weight: var(--fw-semibold);
}
html.ui2 .btn-delete:hover { background: var(--ui-danger-bg); color: var(--ui-danger-fg); border-color: var(--ui-danger-fg); }

/* Disabled: a quiet fill instead of a faded button, and a reason next to it (.btn-note) */
html.ui2 .btn:disabled,
html.ui2 .btn[aria-disabled="true"],
html.ui2 .btn-delete:disabled,
html.ui2 .btn-delete[aria-disabled="true"] {
  background: var(--bg-surface-2); color: var(--text-muted); border-color: var(--border-subtle);
  opacity: 1; cursor: not-allowed; transform: none; text-decoration: none;
}
html.ui2 .btn-note { margin: var(--sp-1) 0 0; color: var(--text-secondary); font-size: var(--fs-small); line-height: var(--lh-body); }

/* Hero: the one large action of a view (Run Optimization, decision D-9) */
html.ui2 .btn-hero {
  min-height: 3.5rem; min-width: 16rem; padding: 0 var(--sp-6);
  font-size: var(--fs-section); gap: var(--sp-3);
}
html.ui2 .btn-hero[aria-busy="true"] { cursor: progress; }
html.ui2 .btn-hero[aria-busy="true"]:disabled,
html.ui2 .btn-hero[aria-busy="true"][aria-disabled="true"] { background: var(--brand); color: var(--on-accent); border-color: var(--brand); cursor: progress; }
html.ui2 .btn-hero[aria-busy="true"]::before {
  content: ""; flex-shrink: 0; width: 1.125rem; height: 1.125rem; box-sizing: border-box;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  animation: ui2-spin 0.8s linear infinite;
}
@keyframes ui2-spin { to { transform: rotate(360deg); } }
@media (max-width: 900px) {
  html.ui2 .btn-hero { width: 100%; min-width: 0; min-height: max(3.5rem, 44px); }
}
@media (prefers-reduced-motion: reduce) {
  html.ui2 .btn-hero[aria-busy="true"]::before { animation: none; }
}
html.ui2[data-motion="reduce"] .btn-hero[aria-busy="true"]::before { animation: none; }

/* Badges: text always, icon for status, colour never alone */
html.ui2 .ui-chip,
html.ui2 .status-chip {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  min-height: 1.5rem; padding: 0.125rem var(--sp-2);
  border: 1px solid var(--border-subtle); border-radius: var(--r-badge);
  background: var(--bg-surface-2); color: var(--text-secondary);
  font-size: var(--fs-small); font-weight: var(--fw-medium); line-height: var(--lh-tight); white-space: nowrap;
}
html.ui2 .ui-chip.is-success,
html.ui2 .ui-chip.is-done,
html.ui2 .status-chip { background: var(--ui-success-bg); color: var(--ui-success-fg); border-color: var(--ui-success-bd); }
html.ui2 .ui-chip.is-warning { background: var(--ui-warning-bg); color: var(--ui-warning-fg); border-color: var(--ui-warning-bd); }
html.ui2 .ui-chip.is-danger { background: var(--ui-danger-bg); color: var(--ui-danger-fg); border-color: var(--ui-danger-bd); }
html.ui2 .ui-chip.is-info,
html.ui2 .ui-chip.is-current { background: var(--ui-info-bg); color: var(--ui-info-fg); border-color: var(--ui-info-bd); }
html.ui2 .ui-chip.is-next { background: var(--bg-surface); color: var(--text-secondary); border-color: var(--border-input); }
html.ui2 .ui-chip.is-success::before,
html.ui2 .ui-chip.is-done::before,
html.ui2 .ui-chip.is-warning::before,
html.ui2 .ui-chip.is-danger::before,
html.ui2 .ui-chip.is-info::before,
html.ui2 .ui-chip.is-current::before,
html.ui2 .status-chip::before {
  content: ""; display: inline-block; flex-shrink: 0; width: 0.875rem; height: 0.875rem; border-radius: 0;
  background: currentColor; -webkit-mask: var(--ic-check) center / contain no-repeat; mask: var(--ic-check) center / contain no-repeat;
}
html.ui2 .ui-chip.is-warning::before { -webkit-mask-image: var(--ic-alert); mask-image: var(--ic-alert); }
html.ui2 .ui-chip.is-danger::before { -webkit-mask-image: var(--ic-error); mask-image: var(--ic-error); }
html.ui2 .ui-chip.is-info::before,
html.ui2 .ui-chip.is-current::before { -webkit-mask-image: var(--ic-info); mask-image: var(--ic-info); }
/* Class type: teal is Lecture, orange is Lab, neutral is Elective; the word is always printed */
html.ui2 .ui-chip.is-lecture { background: var(--type-lecture-soft); color: var(--type-lecture); border-color: var(--type-lecture); }
html.ui2 .ui-chip.is-lab { background: var(--type-lab-soft); color: var(--type-lab); border-color: var(--type-lab); }
html.ui2 .ui-chip.is-elective { background: var(--bg-surface); color: var(--text-secondary); border-color: var(--border-input); }

/* Cards and KPI tiles: 12 px radius, 1 px rule, no shadow, no lift on hover */
html.ui2 .ui-card,
html.ui2 .stat-card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--r-card);
  box-shadow:none;
}
html.ui2 .ui-card { padding: var(--sp-4) var(--sp-5); }
html.ui2 .ui-card:hover,
html.ui2 .stat-card:hover { box-shadow:none; transform: none; }
html.ui2 .stat-card .stat-label {
  color: var(--text-secondary); font-size: var(--fs-label); font-weight: var(--fw-label);
  text-transform: none; letter-spacing: 0;
}
html.ui2 .stat-card .stat-value { font-size: var(--fs-kpi); font-weight: var(--fw-kpi); line-height: var(--lh-tight); color: var(--text-primary); }
html.ui2 .stat-card .stat-sub { color: var(--text-secondary); font-size: var(--fs-small); }

/* Form fields: label above, helper text, error text with icon and words */
html.ui2 input[aria-invalid="true"],
html.ui2 select[aria-invalid="true"],
html.ui2 textarea[aria-invalid="true"] { border-color: var(--ui-danger-fg); }
html.ui2 .field { display: grid; gap: var(--sp-1); min-width: 0; margin-bottom: var(--sp-4); }
html.ui2 .field > label,
html.ui2 .field-label { color: var(--text-primary); font-size: var(--fs-label); font-weight: var(--fw-label); }
html.ui2 .field-req { color: var(--ui-danger-fg); }
html.ui2 .field input:not([type="checkbox"]):not([type="radio"]),
html.ui2 .field select,
html.ui2 .field textarea {
  min-height: var(--ctl-min); width: 100%; box-sizing: border-box;
  border: 1px solid var(--border-input); border-radius: var(--r-control);
  background: var(--input-bg); color: var(--text-primary); font-size: var(--fs-body);
}
html.ui2 .field textarea { min-height: 5rem; padding-top: var(--sp-2); }
html.ui2 .field-help { margin: 0; color: var(--text-secondary); font-size: var(--fs-small); line-height: var(--lh-body); }
html.ui2 .field-error {
  display: flex; align-items: flex-start; gap: var(--sp-1); margin: 0;
  color: var(--ui-danger-fg); font-size: var(--fs-small); font-weight: var(--fw-medium); line-height: var(--lh-body);
}
html.ui2 .field-error::before {
  content: ""; flex-shrink: 0; width: 1rem; height: 1rem; margin-top: 0.125rem;
  background: currentColor; -webkit-mask: var(--ic-error) center / contain no-repeat; mask: var(--ic-error) center / contain no-repeat;
}
html.ui2 .field-error[hidden] { display: none; }
/* A text button at the right inside a field, for example Show password (FEEDBACK section 4) */
html.ui2 .field-control { position: relative; display: block; min-width: 0; }
html.ui2 .field-control > input,
html.ui2 .field-control > select { padding-right: 8.5rem; }
html.ui2 .field-toggle {
  position: absolute; top: 0; bottom: 0; right: 1px; min-width: 24px; min-height: 24px;
  padding: 0 var(--sp-3); border: 0; border-radius: var(--r-control);
  background: transparent; color: var(--brand-text);
  font-size: var(--fs-small); font-weight: var(--fw-semibold); cursor: pointer; transform: none;
}
html.ui2 .field-toggle:hover { background: var(--bg-surface-2); color: var(--brand-text); }
html.ui2 .field-toggle:active { transform: none; }
@media (max-width: 900px) {
  html.ui2 .field-toggle { min-height: 44px; min-width: 44px; }
}
/* Errors collected at the top of a form after a failed submit; each item links to its field */
html.ui2 .field-error-summary {
  margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--ui-danger-bd); border-radius: var(--r-control);
  background: var(--ui-danger-bg); color: var(--ui-danger-fg);
}
html.ui2 .field-error-summary h2,
html.ui2 .field-error-summary .field-error-summary-title { margin: 0 0 var(--sp-1); font-size: var(--fs-body); font-weight: var(--fw-semibold); color: var(--ui-danger-fg); }
html.ui2 .field-error-summary ul { margin: 0; padding-left: var(--sp-5); }
html.ui2 .field-error-summary a { color: var(--ui-danger-fg); text-decoration: underline; }

/* Every select shows a chevron with room so the text never touches it (FEEDBACK section 7) */
html.ui2 select:not([multiple]):not([size]) {
  -webkit-appearance: none; appearance: none;
  background-image: var(--select-chevron); background-repeat: no-repeat;
  background-position: right 0.75rem center; background-size: 1rem 1rem;
  padding-right: 2.5rem; text-overflow: ellipsis;
}

/* Selected row: tint plus a leading dot and bold first cell; the row also carries aria-selected */
html.ui2 .row-selected { background: var(--bg-surface-3); }
html.ui2 .row-selected > :first-child { font-weight: var(--fw-semibold); color: var(--text-primary); }
html.ui2 .row-selected > :first-child::before {
  content: ""; display: inline-block; width: 0.5rem; height: 0.5rem; margin-right: var(--sp-2);
  border-radius: 50%; background: var(--text-primary); vertical-align: middle;
}

/* Page header: title, one line of subtitle, actions at the right; stacks on phones */
html.ui2 .pg-head {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-3) var(--sp-5); margin: 0 0 var(--sp-5); min-width: 0;
}
html.ui2 .pg-head-text { flex: 1 1 18rem; min-width: 0; }
html.ui2 .pg-title { margin: 0; color: var(--text-primary); font-size: var(--fs-title); font-weight: var(--fw-title); line-height: var(--lh-tight); }
html.ui2 .pg-sub { margin: var(--sp-1) 0 0; color: var(--text-secondary); font-size: var(--fs-body); line-height: var(--lh-body); }
html.ui2 .pg-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); min-width: 0; }
@media (max-width: 900px) {
  html.ui2 .pg-head { flex-direction: column; align-items: stretch; }
  html.ui2 .pg-head-text { flex-basis: auto; }
  html.ui2 .pg-actions > .btn { flex: 1 1 auto; }
}

/* Tab strip: text tabs, underline on the active one, scrolls inside itself, never the page */
html.ui2 .tab-strip {
  display: flex; gap: var(--sp-5); max-width: 100%; min-width: 0;
  margin: 0 0 var(--sp-4); padding: 0; list-style: none;
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: thin;
}
html.ui2 .tab-strip > a,
html.ui2 .tab-strip > button,
html.ui2 .tab-strip > [role="tab"] {
  flex: 0 0 auto; display: inline-flex; align-items: center;
  min-height: var(--ctl-min); padding: 0 var(--sp-1); margin: 0;
  border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  background: transparent; color: var(--text-secondary);
  font-size: var(--fs-body); font-weight: var(--fw-medium); white-space: nowrap; text-decoration: none; transform: none;
}
html.ui2 .tab-strip > a:hover,
html.ui2 .tab-strip > button:hover,
html.ui2 .tab-strip > [role="tab"]:hover { background: transparent; color: var(--text-primary); border-bottom-color: var(--border-input); }
html.ui2 .tab-strip > [aria-selected="true"],
html.ui2 .tab-strip > [aria-current="page"],
html.ui2 .tab-strip > .is-active {
  color: var(--text-primary); font-weight: var(--fw-semibold); border-bottom-color: var(--brand);
}
html.ui2 .tab-strip > a:focus-visible,
html.ui2 .tab-strip > button:focus-visible,
html.ui2 .tab-strip > [role="tab"]:focus-visible { outline-offset: -2px; }

/* Banner: info, success, warning, error, each with an icon and words */
html.ui2 .banner {
  display: flex; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap;
  margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--ui-info-bd); border-radius: var(--r-control);
  background: var(--ui-info-bg); color: var(--ui-info-fg); font-size: var(--fs-body); line-height: var(--lh-body);
}
html.ui2 .banner::before {
  content: ""; flex-shrink: 0; width: 1.25rem; height: 1.25rem; margin-top: 0.125rem;
  background: currentColor; -webkit-mask: var(--ic-info) center / contain no-repeat; mask: var(--ic-info) center / contain no-repeat;
}
html.ui2 .banner.is-success { border-color: var(--ui-success-bd); background: var(--ui-success-bg); color: var(--ui-success-fg); }
html.ui2 .banner.is-success::before { -webkit-mask-image: var(--ic-check); mask-image: var(--ic-check); }
html.ui2 .banner.is-warning { border-color: var(--ui-warning-bd); background: var(--ui-warning-bg); color: var(--ui-warning-fg); }
html.ui2 .banner.is-warning::before { -webkit-mask-image: var(--ic-alert); mask-image: var(--ic-alert); }
html.ui2 .banner.is-error { border-color: var(--ui-danger-bd); background: var(--ui-danger-bg); color: var(--ui-danger-fg); }
html.ui2 .banner.is-error::before { -webkit-mask-image: var(--ic-error); mask-image: var(--ic-error); }
html.ui2 .banner-body { flex: 1 1 14rem; min-width: 0; }
html.ui2 .banner-title { margin: 0; font-weight: var(--fw-semibold); }
html.ui2 .banner-body p { margin: 0; }
html.ui2 .banner-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }

/* Four step stepper (Inputs, Run, Review, Approve): Workload Optimization only (decision D-10) */
html.ui2 .step-strip {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-2);
  margin: 0 0 var(--sp-5); padding: 0; list-style: none; counter-reset: ui2-step;
}
html.ui2 .step-strip > li {
  counter-increment: ui2-step; display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-1);
  min-width: 0; padding: var(--sp-3); border: 1px solid var(--border-subtle); border-radius: var(--r-control);
  background: var(--bg-surface);
}
html.ui2 .step-strip > li[aria-current="step"] { border-color: var(--brand); background: var(--bg-surface-2); }
html.ui2 .step-strip-name { color: var(--text-primary); font-weight: var(--fw-semibold); font-size: var(--fs-body); }
html.ui2 .step-strip-name::before { content: counter(ui2-step) ". "; color: var(--text-secondary); }
@media (max-width: 600px) {
  html.ui2 .step-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Other pages show one small chip that links to Optimization */
html.ui2 .next-chip {
  display: inline-flex; align-items: center; gap: var(--sp-2); max-width: 100%;
  min-height: 2rem; padding: 0 var(--sp-3);
  border: 1px solid var(--border-input); border-radius: 999px;
  background: var(--bg-surface); color: var(--text-primary);
  font-size: var(--fs-small); font-weight: var(--fw-medium); text-decoration: none;
}
html.ui2 .next-chip::after {
  content: ""; flex-shrink: 0; width: 1rem; height: 1rem; transform: rotate(-90deg);
  background: currentColor; -webkit-mask: var(--ic-chevron) center / contain no-repeat; mask: var(--ic-chevron) center / contain no-repeat;
}
html.ui2 .next-chip:hover { background: var(--bg-surface-2); color: var(--text-primary); }
@media (max-width: 900px) {
  html.ui2 .next-chip { min-height: 44px; }
}

/* Info tip: a small i button that opens a short definition (FEEDBACK section 8). The click path is
   the required one; Escape and an outside click close it and focus returns to the button. */
html.ui2 .info-tip { position: relative; display: inline-flex; vertical-align: middle; }
html.ui2 .info-tip-btn {
  display: inline-grid; place-items: center; min-width: 24px; min-height: 24px; padding: 0; margin: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--text-secondary); cursor: pointer; transform: none;
}
html.ui2 .info-tip-btn > span {
  display: inline-grid; place-items: center; width: 1.25rem; height: 1.25rem; box-sizing: border-box;
  border: 1px solid var(--border-input); border-radius: 50%; background: var(--bg-surface);
  font-size: var(--fs-small); font-weight: var(--fw-semibold); font-style: normal; line-height: 1;
}
html.ui2 .info-tip-btn:hover { background: transparent; color: var(--text-primary); }
html.ui2 .info-tip-btn:hover > span,
html.ui2 .info-tip-btn[aria-expanded="true"] > span { border-color: var(--text-primary); color: var(--text-primary); }
html.ui2 .info-tip-btn:active { transform: none; }
html.ui2 .info-tip-pop {
  position: absolute; z-index: 60; top: calc(100% + var(--sp-1)); left: 0;
  width: max-content; max-width: min(18rem, calc(100vw - 2rem)); box-sizing: border-box;
  margin: 0; padding: var(--sp-3);
  border: 1px solid var(--border-input); border-radius: var(--r-control);
  background: var(--bg-surface); color: var(--text-primary);
  font-size: var(--fs-body); font-weight: var(--fw-regular); line-height: var(--lh-body); text-align: left; white-space: normal;
}
html.ui2 .info-tip-pop[hidden] { display: none; }
@media (max-width: 900px) {
  html.ui2 .info-tip-btn { min-width: 44px; min-height: 44px; }
}

/* Disclosure: a button with aria-expanded and a region that is hidden (so not focusable) while closed */
html.ui2 .disclosure {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  min-height: var(--ctl-min); padding: 0 var(--sp-2); margin: 0;
  border: 0; border-radius: var(--r-control); background: transparent; color: var(--brand-text);
  font-size: var(--fs-body); font-weight: var(--fw-semibold); cursor: pointer; transform: none;
  max-width: 100%; white-space: normal; text-align: left;
}
html.ui2 .disclosure::after {
  content: ""; flex-shrink: 0; width: 1rem; height: 1rem; transition: transform 150ms ease;
  background: currentColor; -webkit-mask: var(--ic-chevron) center / contain no-repeat; mask: var(--ic-chevron) center / contain no-repeat;
}
html.ui2 .disclosure[aria-expanded="true"]::after { transform: rotate(180deg); }
html.ui2 .disclosure:hover { background: var(--bg-surface-2); color: var(--brand-text); }
html.ui2 .disclosure:active { transform: none; }
html.ui2 .disclosure-body { margin: var(--sp-2) 0 0; }
html.ui2 .disclosure-body[hidden] { display: none; }

/* Menu: three dots button, list of actions; Escape and outside click close it, arrows move */
html.ui2 .menu { position: relative; display: inline-block; }
html.ui2 .menu-btn {
  display: inline-grid; place-items: center; min-width: var(--ctl-min); min-height: var(--ctl-min); padding: 0; margin: 0;
  border: 1px solid transparent; border-radius: var(--r-control); background: transparent; color: var(--text-primary);
  cursor: pointer; transform: none;
}
html.ui2 .menu-btn::before {
  content: ""; width: 1.25rem; height: 1.25rem;
  background: currentColor; -webkit-mask: var(--ic-more) center / contain no-repeat; mask: var(--ic-more) center / contain no-repeat;
}
html.ui2 .menu-btn:hover,
html.ui2 .menu-btn[aria-expanded="true"] { background: var(--bg-surface-2); border-color: var(--border-subtle); color: var(--text-primary); }
html.ui2 .menu-btn:active { transform: none; }
html.ui2 .menu-list {
  position: absolute; z-index: 60; right: 0; top: calc(100% + var(--sp-1));
  min-width: 13rem; max-width: calc(100vw - 2rem); box-sizing: border-box;
  margin: 0; padding: var(--sp-1); list-style: none;
  border: 1px solid var(--border-input); border-radius: var(--r-control); background: var(--bg-surface);
}
html.ui2 .menu-list[hidden] { display: none; }
html.ui2 .menu-item {
  display: flex; align-items: center; width: 100%; min-height: var(--ctl-min); padding: 0 var(--sp-3); margin: 0;
  border: 0; border-radius: var(--r-badge); background: transparent; color: var(--text-primary);
  font-size: var(--fs-body); font-weight: var(--fw-regular); text-align: left; white-space: nowrap; cursor: pointer; transform: none;
}
html.ui2 .menu-item:hover,
html.ui2 .menu-item:focus-visible { background: var(--bg-surface-2); color: var(--text-primary); }
html.ui2 .menu-item:focus-visible { outline-offset: -2px; }
html.ui2 .menu-item.is-danger { color: var(--ui-danger-fg); }
html.ui2 .menu-item.is-danger:hover { background: var(--ui-danger-bg); color: var(--ui-danger-fg); }
html.ui2 .menu-item:disabled { background: transparent; color: var(--text-muted); cursor: not-allowed; opacity: 1; }
html.ui2 .menu-note { margin: 0; padding: 0 var(--sp-3) var(--sp-2); color: var(--text-secondary); font-size: var(--fs-small); white-space: normal; }

/* States from atlasUI.state: loading skeleton, empty (icon, title, one sentence), error (keeps values, Retry) */
html.ui2 .ui-state {
  align-items: center; gap: var(--sp-2); padding: var(--sp-6) var(--sp-4);
  color: var(--text-secondary); font-size: var(--fs-body); line-height: var(--lh-body); text-align: center;
}
html.ui2 .ui-state::before {
  content: ""; width: 2.5rem; height: 2.5rem;
  background: var(--text-secondary); -webkit-mask: var(--ic-empty) center / contain no-repeat; mask: var(--ic-empty) center / contain no-repeat;
}
html.ui2 .ui-state-title { margin: 0; color: var(--text-primary); font-size: var(--fs-section); font-weight: var(--fw-section); }
html.ui2 .ui-state.is-error {
  align-items: flex-start; text-align: left; padding: var(--sp-4);
  border: 1px solid var(--ui-danger-bd); border-radius: var(--r-card);
  background: var(--ui-danger-bg); color: var(--ui-danger-fg);
}
html.ui2 .ui-state.is-error::before {
  width: 1.25rem; height: 1.25rem; background: currentColor;
  -webkit-mask-image: var(--ic-error); mask-image: var(--ic-error);
}
html.ui2 .ui-skeleton { gap: var(--sp-3); padding: var(--sp-4); }
html.ui2 .ui-skeleton span { height: 0.875rem; border-radius: var(--r-badge); background: var(--bg-surface-3); }
html.ui2 .empty-state-msg { color: var(--text-secondary); font-style: normal; font-size: var(--fs-body); }

/* Toast: the single stack from BF-01, flat with a rule */
html.ui2 .toast-notif {
  max-width: min(28rem, calc(100vw - 2rem)); padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border-strong); border-radius: var(--r-control); box-shadow:none;
  font-size: var(--fs-body); line-height: var(--lh-body);
}

/* Sheets and atlasDialog dialogs: no shadow, a rule instead; footer row for actions */
html.ui2 .ui-sheet,
html.ui2 .ui2-dialog { box-shadow:none; border: 1px solid var(--border-subtle); }
html.ui2 .ui-sheet-head { padding: var(--sp-4) var(--sp-5); }
html.ui2 .ui-sheet-title { font-size: var(--fs-section); font-weight: var(--fw-section); line-height: var(--lh-tight); }
html.ui2 .ui-sheet-body { padding: var(--sp-4) var(--sp-5); font-size: var(--fs-body); line-height: var(--lh-body); }
html.ui2 .ui-sheet-foot { display: flex; flex-wrap: wrap; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border-subtle); }
/* Centered dialog used for confirmations (the sheet stays the side panel) */
html.ui2 .ui2-dialog {
  position: fixed; z-index: 2147483001; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(28rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow: auto; box-sizing: border-box;
  border-radius: var(--r-card); background: var(--bg-surface); color: var(--text-primary);
}
html.ui2 .ui2-dialog[hidden] { display: none; }
/* Danger confirm (FEEDBACK section 11): the title names the item, the safe button comes first and has
   default focus, the destructive button is set apart at the far end and has an action label. */
html.ui2 .confirm-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }
html.ui2 .confirm-actions > .btn-danger,
html.ui2 .confirm-actions > .is-destructive { margin-left: auto; }
@media (max-width: 600px) {
  html.ui2 .confirm-actions { flex-direction: column; align-items: stretch; }
  html.ui2 .confirm-actions > .btn-danger,
  html.ui2 .confirm-actions > .is-destructive { margin-left: 0; margin-top: var(--sp-4); }
}

/* S3 shell
   J-04: desktop shell markup from picture 01. .app-shell is a two column grid: the sidebar (.side-nav) on the
   left, .app-main on the right holding the slim top bar and the existing .panels-wrapper. The top bar is in the
   flow (sticky) instead of fixed, so the panels keep their old height of the viewport minus --nav-h and no
   second scrollbar appears. Every old hook (.nav-item[data-panel], navMenu2, navMenu3, #navTitle, #navBack,
   .nav-menu-btn, #userMenu, #navUserLabel, .nav-logo-mobile) is kept. Group behavior, collapse and the
   Timetable entry are J-05; this step shows the Inputs group expanded and static.
   At 900 px and below (PHONE_MQ) the sidebar is hidden, the two wrappers take no box, and the old phone
   top bar rules in main-style.css apply untouched. */

/* Icons new in this step: 24 px viewBox, stroke 2, round caps (assets/images/icons) */
html.ui2 .ic-timetable { -webkit-mask-image: url("../images/icons/timetable.svg"); mask-image: url("../images/icons/timetable.svg"); }
html.ui2 .ic-preferences { -webkit-mask-image: url("../images/icons/preferences.svg"); mask-image: url("../images/icons/preferences.svg"); }
html.ui2 .ic-subjects { -webkit-mask-image: url("../images/icons/subjects.svg"); mask-image: url("../images/icons/subjects.svg"); }
html.ui2 .ic-blocks { -webkit-mask-image: url("../images/icons/blocks.svg"); mask-image: url("../images/icons/blocks.svg"); }

html.ui2 .top-dept[hidden] { display: none; }

@media (max-width: 900px) {
  html.ui2 .side-nav { display: none; }
  html.ui2 .app-shell,
  html.ui2 .app-main { display: contents; }
  html.ui2 .top-dept,
  html.ui2 .top-period { display: none; }
}

@media (min-width: 901px) {
  html.ui2 .app-shell {
    display: grid;
    grid-template-columns: var(--side-w) minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
  }
  html.ui2 .app-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

  /* Sidebar: full height, sticky, scrolls on its own only if the window is very short */
  html.ui2 .side-nav {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    height: 100vh;
    height: 100dvh;
    min-width: 0;
    overflow-y: auto;
    scrollbar-width: none;            /* U4-08b: no visible scrollbar; the sidebar still scrolls on a very short window */
    -ms-overflow-style: none;
    padding: var(--sp-4) var(--sp-2);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-default);
  }
  html.ui2 .side-nav::-webkit-scrollbar { display: none; width: 0; height: 0; }
  html.ui2 .side-brand { gap: var(--sp-2); min-height: 2.75rem; padding: 0 var(--sp-2); }
  html.ui2 .side-brand .psu-logo { width: 32px; height: 32px; }
  html.ui2 .side-brand .brand { font-size: var(--text-md); font-weight: var(--fw-semibold); color: var(--brand-text); }


  /* Items: one look for the old .nav-item (div and button) and the new entries, so the old size checks hold */
  html.ui2 .side-nav .nav-menu {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-1);
    overflow: visible;
    justify-self: auto;
  }
  html.ui2 .side-nav .nav-item,
  html.ui2 .side-nav .side-item,
  html.ui2 .side-nav .side-sub-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: var(--sp-2);
    width: 100%;
    min-height: 2.75rem;
    margin: 0;
    padding: 0 var(--sp-3);
    border: 0;
    border-radius: var(--r-control);
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--fs-body);
    font-weight: var(--fw-medium);
    line-height: var(--lh-tight);
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    flex-wrap: wrap;                  /* U5-02: a trailing chip that cannot fit drops under the label instead of being clipped */
    row-gap: 0;
  }
  /* U5-02: labels give way with an ellipsis (the row carries a title tooltip), icons and chips never shrink */
  html.ui2 .side-nav .nav-item > span:not(.nav-ic),
  html.ui2 .side-nav .side-item > span:not(.nav-ic):not(.side-new),
  html.ui2 .side-nav .side-sub-item > span:not(.nav-ic) { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  html.ui2 .side-nav .nav-ic { flex-shrink: 0; }
  html.ui2 .side-nav .side-sub-item { min-height: 2.5rem; padding-left: var(--sp-6); }
  html.ui2 .side-nav .nav-item:hover,
  html.ui2 .side-nav .side-item:hover,
  html.ui2 .side-nav .side-sub-item:hover { background: var(--bg-surface-3); color: var(--text-primary); }
  html.ui2 .side-nav .nav-item.active { background: var(--clr-primary-50); color: var(--clr-primary-600); font-weight: var(--fw-semibold); }
  html.ui2 .side-nav .nav-ic { width: 20px; height: 20px; }
  html.ui2 .side-group,
  html.ui2 .side-sub { display: flex; flex-direction: column; gap: var(--sp-1); }
  html.ui2 .side-foot { margin-top: auto; padding-top: var(--sp-3); border-top: 1px solid var(--border-default); }

  /* Top bar: department and university line on the left, period chip and Account on the right */
  html.ui2 .top-navbar {
    position: sticky;
    top: 0;
    left: auto;
    right: auto;
    display: flex;
    flex: 0 0 var(--nav-h);
    align-items: center;
    justify-content: flex-end;
    gap: var(--sp-4);
    height: var(--nav-h);
    padding: 0 var(--gutter);
  }
  html.ui2 .top-dept {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--sp-2);
    min-width: 0;
    margin-right: auto;
    line-height: var(--lh-tight);
  }
  html.ui2 .top-dept-ic { width: 20px; height: 20px; flex-shrink: 0; color: var(--clr-primary-600); }
  html.ui2 .top-dept-text { display: flex; flex-direction: column; min-width: 0; line-height: var(--lh-tight); }
  html.ui2 .top-dept-name { font-size: var(--fs-body); font-weight: var(--fw-semibold); color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  html.ui2 .top-dept-label { font-size: var(--fs-small); font-weight: var(--fw-label); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }

  /* Panels: same height as before (viewport minus the top bar); the top bar is in the flow, so no margin */
  html.ui2 .panels-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    margin-top: 0;
    height: calc(100vh - var(--nav-h));
    height: calc(100dvh - var(--nav-h));
  }
}

/* S3 shell, J-05: sidebar behavior
   html[data-side="expanded" | "collapsed"] is set by section-nav.js (default expanded at 1280 px and up, collapsed
   from 901 to 1279 px, the user's choice kept in localStorage atlasSide). Collapsed: seal, icons and the department
   badge only; labels stay in the DOM (visually hidden) and every item carries an aria-label. While collapsed a mouse
   hover adds .is-peek: the rail is drawn at full width over the content (position absolute), the grid column keeps
   the rail width, so the content column never moves. Transitions are width and opacity only, 150 ms. */
html.ui2 { --ic-side: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='2'/%3E%3Cline x1='9' y1='4' x2='9' y2='20'/%3E%3C/svg%3E"); }
html.ui2 .side-sub[hidden],
html.ui2 .side-tip[hidden] { display: none; }
html.ui2 .side-toggle { display: none; }

/* Text tooltip for the icon rail (one element in body, placed by section-nav.js next to the item) */
html.ui2 .side-tip {
  position: fixed;
  z-index: 1200;
  max-width: 16rem;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-control);
  background: var(--text-primary);
  color: var(--bg-surface);
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  line-height: var(--lh-tight);
  white-space: nowrap;
  pointer-events: none;
}

@media (min-width: 901px) {
  html.ui2 .app-shell { position: relative; }
  html.ui2 .app-main { grid-column: 2; }
  html.ui2[data-side="collapsed"] .app-shell { grid-template-columns: var(--side-w-c) minmax(0, 1fr); }

  html.ui2 .side-nav {
    z-index: 1001;
    width: var(--side-w);
    overflow-x: hidden;
    transition: width 150ms ease;
  }
  html.ui2[data-side="collapsed"] .side-nav { width: var(--side-w-c); }
  html.ui2[data-side="collapsed"] .side-nav.is-peek {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1100;
    width: var(--side-w);
  }

  /* Brand row: collapse button at the left, then seal and name (UI3 P-04) */
  html.ui2 .side-brand { display: flex; align-items: center; gap: var(--sp-2); }
  html.ui2 .side-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2.75rem;
    height: 2.75rem;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--r-control);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
  }
  html.ui2 .side-toggle:hover { background: var(--bg-surface-3); color: var(--text-primary); }
  html.ui2 .side-toggle-ic {
    width: 20px;
    height: 20px;
    background: currentColor;
    -webkit-mask: var(--ic-side) center / contain no-repeat;
    mask: var(--ic-side) center / contain no-repeat;
  }

  /* Inputs and Reports group buttons (U4-07): the same chevron, turned while the group is open. Both buttons only fold or unfold their list. */
  html.ui2 #sideGroupInputs > .nav-item::after,
  html.ui2 #sideGroupReports > .nav-item::after {
    content: "";
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    margin-left: auto;
    background: currentColor;
    -webkit-mask: var(--ic-chevron) center / contain no-repeat;
    mask: var(--ic-chevron) center / contain no-repeat;
    transition: transform 200ms var(--ease-ui, cubic-bezier(0.4, 0, 0.2, 1));
  }
  html.ui2 #sideGroupInputs > .nav-item[aria-expanded="false"]::after,
  html.ui2 #sideGroupReports > .nav-item[aria-expanded="false"]::after { transform: rotate(-90deg); }
  @media (prefers-reduced-motion: reduce) {
    html.ui2 #sideGroupInputs > .nav-item::after,
    html.ui2 #sideGroupReports > .nav-item::after { transition: none; }
  }
  html.ui2[data-motion="reduce"] #sideGroupInputs > .nav-item::after,
  html.ui2[data-motion="reduce"] #sideGroupReports > .nav-item::after { transition: none; }
  html.ui2 #sideGroupInputs > .nav-item.active,
  html.ui2 #sideGroupReports > .nav-item.active { background: transparent; color: var(--brand-text); }

  /* Active entry: tint and brand text, same as the top level items */
  html.ui2 .side-nav .side-item.active,
  html.ui2 .side-nav .side-sub-item.active { background: var(--clr-primary-50); color: var(--clr-primary-600); font-weight: var(--fw-semibold); }

  /* Labels fade, never slide */
  html.ui2 .side-nav .brand,
  html.ui2 .side-nav .nav-item > span:not(.nav-ic),
  html.ui2 .side-nav .side-item > span:not(.nav-ic),
  html.ui2 .side-nav .side-sub-item > span:not(.nav-ic) { transition: opacity 150ms ease; }

  /* Collapsed rail (not peeking): icons centred, labels visually hidden but still read */
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) { padding-left: var(--sp-2); padding-right: var(--sp-2); }
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .side-brand { flex-direction: column; gap: var(--sp-1); padding: 0; }
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .side-toggle { margin: 0; }
  /* UI3 P-04: with a mouse the rail opens on hover, so the toggle is hidden at rest (clip, still focusable; shown on keyboard focus). Touch keeps it visible. */
  @media (hover: hover) and (pointer: fine) {
    html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .side-brand { justify-content: center; padding: 0; }
    html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .side-toggle:not(:focus-visible) {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
      opacity: 0;
    }
  }
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .brand,
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .nav-item > span:not(.nav-ic),
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .side-item > span:not(.nav-ic),
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .side-sub-item > span:not(.nav-ic) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    opacity: 0;
  }
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .nav-item,
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .side-item,
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) .side-sub-item { justify-content: center; min-height: 2.75rem; padding: 0; }
  /* U4-08b: on the rail the Inputs and Reports buttons stay (icon only) and their section icons show only while the group is open */
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) #sideGroupInputs > .nav-item::after,
  html.ui2[data-side="collapsed"] .side-nav:not(.is-peek) #sideGroupReports > .nav-item::after { display: none; }
}

@media (min-width: 901px) and (prefers-reduced-motion: reduce) {
  html.ui2 .side-nav,
  html.ui2 .side-nav * { transition: none; }
}
@media (min-width: 901px) {
  html.ui2[data-motion="reduce"] .side-nav,
  html.ui2[data-motion="reduce"] .side-nav * { transition: none; }
}

/* S3 shell, J-06: account button, account menu, period pill, page header on phones
   Phone (900 px and below): the account button (.nav-account, chairperson page) stays the 44 px menu icon; avatar, label and chevron are hidden.
   Desktop: avatar circle, the user label filled by main-script.js (applyDeptLabels) and a chevron.
   The menu is text only so the seven entries line up (the old Settings and Help icon spans stay in the markup). */
html.ui2 .user-menu {
  min-width: 13rem; max-width: calc(100vw - 2rem); box-sizing: border-box; padding: var(--sp-1);
  border: 1px solid var(--border-input); border-radius: var(--r-control); background: var(--bg-surface);
  box-shadow:none;
}
html.ui2 .user-menu .ic { display: none; }
html.ui2 .user-menu [role="menuitem"] {
  justify-content: flex-start; min-height: var(--ctl-min); padding: 0 var(--sp-3); border-radius: var(--r-badge);
  color: var(--text-primary); font-size: var(--fs-body); font-weight: var(--fw-regular); text-align: left; white-space: nowrap;
}
html.ui2 .user-menu [role="menuitem"]:hover,
html.ui2 .user-menu [role="menuitem"]:focus-visible { background: var(--bg-surface-2); color: var(--text-primary); }
html.ui2 .user-menu [role="menuitem"]:focus-visible { outline: var(--focus-outline); outline-offset: -2px; }
html.ui2 .user-menu .um-sep { height: 0; margin: var(--sp-1) 0; border-top: 1px solid var(--border-subtle); }
html.ui2 .nav-avatar,
html.ui2 .nav-chev { display: none; }

@media (min-width: 901px) {
  html.ui2 .nav-account,
  html.ui2 .fs-shell .nav-menu-btn {
    width: auto; height: auto; min-height: var(--ctl-min); max-width: 18rem; gap: var(--sp-2);
    padding: 0 var(--sp-2) 0 var(--sp-1);
    border: 1px solid transparent; border-radius: var(--r-control);
    color: var(--text-primary); font-size: var(--fs-body); font-weight: var(--fw-medium);
  }
  html.ui2 .nav-account:hover,
  html.ui2 .fs-shell .nav-menu-btn:hover,
  html.ui2 .nav-account[aria-expanded="true"],
  html.ui2 .fs-shell .nav-menu-btn[aria-expanded="true"] { background: var(--bg-surface-2); border-color: var(--border-subtle); }
  html.ui2 .nav-account:focus-visible,
  html.ui2 .fs-shell .nav-menu-btn:focus-visible { outline: var(--focus-outline); outline-offset: 2px; }
  html.ui2 .nav-account > .ic-menu,
  html.ui2 .fs-shell .nav-menu-btn > .ic-menu { display: none; }
  html.ui2 .nav-avatar {
    display: inline-grid; place-items: center; flex-shrink: 0; width: 2rem; height: 2rem;
    border-radius: 50%; background: var(--bg-surface-3); color: var(--text-secondary);
  }
  html.ui2 .nav-avatar .ic { width: 1.125rem; height: 1.125rem; }
  /* The label is visible on desktop: undo .sr-only for this one element only */
  html.ui2 .nav-account .nav-user-label,
  html.ui2 .fs-shell .nav-menu-btn .nav-user-label {
    position: static; width: auto; height: auto; margin: 0; overflow: hidden; clip: auto;
    min-width: 0; text-overflow: ellipsis; white-space: nowrap;
  }
  html.ui2 .nav-chev {
    display: inline-block; flex-shrink: 0; width: 1rem; height: 1rem; background: currentColor;
    -webkit-mask: var(--ic-chevron) center / contain no-repeat; mask: var(--ic-chevron) center / contain no-repeat;
  }
  html.ui2 .nav-account[aria-expanded="true"] .nav-chev,
  html.ui2 .fs-shell .nav-menu-btn[aria-expanded="true"] .nav-chev { transform: rotate(180deg); }
  html.ui2 .nav-user .user-menu { top: calc(100% + var(--sp-1)); }

  /* Period chip as a quiet pill: same element, link and text as before */
  html.ui2 .top-period {
    flex: 0 1 auto; min-width: 0; min-height: 2rem; gap: var(--sp-2); padding: 0 var(--sp-3);
    border: 1px solid var(--border-subtle); border-radius: 999px; background: var(--bg-surface);
    color: var(--text-primary); font-size: var(--fs-small); font-weight: var(--fw-semibold); text-decoration: none;
  }
  html.ui2 .top-period .period-chip-change {
    padding-left: var(--sp-2); border-left: 1px solid var(--border-subtle);
    color: var(--brand-text); font-weight: var(--fw-medium); text-decoration: none;
  }
  html.ui2 .top-period:hover { background: var(--bg-surface-2); }
  html.ui2 .top-period:hover .period-chip-change { text-decoration: underline; }
  html.ui2 .top-period:focus-visible { outline: var(--focus-outline); outline-offset: 2px; }
}

/* Page header contract (SHELL.md): on phones the top bar carries the title, so the heading in .pg-head is
   kept for screen readers and hidden visually; the subtitle stays visible */
@media (max-width: 900px) {
  html.ui2 .pg-head .pg-title {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  html.ui2 .pg-head .pg-sub { margin-top: 0; }
}

/* S3 shell, J-07: phone top bar, five item bottom bar, Inputs hub cards (pictures 09 and 14, D-11, FEEDBACK 15 and 16)
   Top bar: seal left, panel title (#navTitle) centered in brand text, account button as a person icon at the right.
   The seal gives way to #navBack when that button is shown (its logic is in shared-ui.js and is unchanged).
   Bottom bar: Dashboard, Optimization, Timetable, Reports, Inputs. Five equal items, at least 64 px wide at 320 px
   and 48 px high, label always shown. The current item is a tinted rounded block with a semibold label (text
   weight plus tint, never colour alone). While the timetable is open the bar has .bn-tt and Timetable .is-current.
   One page title on phones: the top bar shows it, the heading in .page-header stays for screen readers only. */
@media (max-width: 900px) {
  html.ui2 .top-navbar { background: var(--bg-surface); border-bottom: 1px solid var(--border-subtle); }
  html.ui2 .nav-title { color: var(--brand-text); font-size: var(--fs-body); font-weight: var(--fw-semibold); }
  html.ui2 .top-navbar:has(> .nav-back:not(.is-hidden)) > .nav-logo-mobile { display: none; }

  html.ui2 .nav-account > .ic-menu,
  html.ui2 .fs-shell .nav-menu-btn > .ic-menu { display: none; }
  html.ui2 .nav-account .nav-avatar,
  html.ui2 .fs-shell .nav-menu-btn .nav-avatar {
    display: inline-grid; place-items: center; width: 2rem; height: 2rem;
    border-radius: 50%; background: var(--bg-surface-3); color: var(--text-primary);
  }
  html.ui2 .nav-account .nav-avatar .ic,
  html.ui2 .fs-shell .nav-menu-btn .nav-avatar .ic { width: 1.25rem; height: 1.25rem; }
  html.ui2 .nav-account:focus-visible,
  html.ui2 .fs-shell .nav-menu-btn:focus-visible { outline: var(--focus-outline); outline-offset: 2px; }

  html.ui2 .bottom-nav {
    gap: 0;
    padding: 0.125rem env(safe-area-inset-right, 0px) calc(0.125rem + env(safe-area-inset-bottom, 0px)) env(safe-area-inset-left, 0px);
    background: var(--bg-surface); border-top: 1px solid var(--border-subtle); box-shadow:none;
  }
  html.ui2 .bn-item {
    flex: 1 1 0; min-width: 0; min-height: 44px; margin: 0; padding: 0 0.125rem; gap: 0.125rem;
    border-radius: var(--r-control); color: var(--text-secondary);
    font-size: var(--text-xs); font-weight: var(--fw-regular); line-height: 1.2;
  }
  html.ui2 .bn-item .bn-ic { width: 1.375rem; height: 1.375rem; }
  html.ui2 .bn-item .bn-label { max-width: 100%; white-space: nowrap; letter-spacing: -0.01em; }
  html.ui2 .bn-item:hover { background: var(--bg-surface-2); color: var(--text-primary); }
  html.ui2 .bn-item:focus-visible { outline: var(--focus-outline); outline-offset: -2px; }
  html.ui2 .bn-item.active::before,
  html.ui2 .bn-item.is-current::before { content: none; }
  html.ui2 .bn-item.active,
  html.ui2 .bottom-nav .bn-item.bn-timetable.is-current {
    background: var(--clr-primary-50); color: var(--clr-primary-600); font-weight: var(--fw-semibold);
  }
  html.ui2 .bottom-nav.bn-tt .bn-item.active:not(.bn-timetable) {
    background: transparent; color: var(--text-secondary); font-weight: var(--fw-regular);
  }

  /* Inputs hub (and the Reports hub, same builder): icon tile, bold title, one line description, chevron */
  html.ui2 .section-card {
    gap: var(--sp-3); padding: var(--sp-3);
    border: 1px solid var(--border-subtle); border-radius: var(--r-card); background: var(--bg-surface);
  }
  html.ui2 .section-card:hover { background: var(--bg-surface-2); }
  html.ui2 .section-card:focus-visible { outline: var(--focus-outline); outline-offset: 2px; }
  html.ui2 .section-card-tile {
    flex: 0 0 auto; display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem;
    border-radius: var(--r-control); background: var(--clr-primary-50); color: var(--clr-primary-600);
  }
  html.ui2 .section-card-tile .section-card-ic { width: 1.375rem; height: 1.375rem; color: inherit; }
  html.ui2 .section-card-title { font-size: var(--fs-body); font-weight: var(--fw-semibold); color: var(--text-primary); }
  html.ui2 .section-card-desc { font-size: var(--fs-small); color: var(--text-secondary); }
  html.ui2 .section-card-chev { border-color: var(--text-secondary); }

  html.ui2 .page-header h2 {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  /* A header that holds only the heading (and the desktop section line) takes no space, so no empty rule is left */
  html.ui2 .page-header:not(:has(> :not(h2):not(.nav-section-now))) {
    min-height: 0; margin: 0; padding: 0; border: 0;
  }
}

/* S4 faculty and auth */

/* S4 faculty shell, J-08: faculty/dashboard.html (pictures 09 and 13, D-5, FEEDBACK 9 and 15)
   Desktop: the J-04 and J-05 sidebar and top bar rules apply unchanged (.app-shell.fs-shell, #sideNav, html[data-side]);
   the account button (class "nav-menu-btn" kept) shares the J-06 and J-07 .nav-account rules above (each lists
   html.ui2 .fs-shell .nav-menu-btn beside .nav-account). The content column is centred at a readable width. Phone: five item bar (My Schedule, My Week,
   All Faculty, Preferences, Help); the current item is drawn from .is-current (set by faculty-script.js markShell),
   .active from shared-ui.js is not drawn on this bar. Day chips: pills, today tinted with the word Today, the selected
   day filled brand, a dot under days with a class, no dates. Class cards: time in teal for Lecture and orange for
   Lab, the type in words, subject, section and room; no professor name on one's own schedule. */
html.ui2 .bn-item.bn-help { text-decoration: none; }

@media (min-width: 901px) {
  html.ui2 .fs-shell .panel > * { max-width: 60rem; margin-left: auto; margin-right: auto; }
}

@media (max-width: 900px) {
  html.ui2 .bottom-nav.bn-fs .bn-item.active:not(.is-current) {
    background: transparent; color: var(--text-secondary); font-weight: var(--fw-regular);
  }
  html.ui2 .bottom-nav.bn-fs .bn-item.is-current {
    background: var(--clr-primary-50); color: var(--clr-primary-600); font-weight: var(--fw-semibold);
  }
}

/* My Week: the grid from 768 px, the list by day below it */
@media (min-width: 768px) {
  html.ui2 .fs-week-list { display: none; }
}

/* In page tab strip (kept: tests and keyboard users switch views with it): no shadow, token hover */
html.ui2 .fs-tab:hover { background: var(--bg-surface-2); color: var(--text-primary); }
html.ui2 .fs-tab.active { box-shadow:none; background: var(--bg-surface); color: var(--clr-primary-600); outline: 1px solid var(--border-default); outline-offset: -1px; }
html.ui2 .fs-tab:focus-visible { outline: var(--focus-outline); outline-offset: 2px; }

/* Day chips */
html.ui2 .fs-weekstrip { gap: var(--sp-2); }
html.ui2 .fs-day-btn {
  min-height: 3.5rem; padding: var(--sp-1) 0; gap: 0.125rem;
  background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border-input); border-radius: 999px;
  font-size: var(--fs-small); font-weight: var(--fw-semibold); line-height: var(--lh-tight);
}
html.ui2 .fs-day-btn small { font-size: var(--fs-small); font-weight: var(--fw-semibold); color: inherit; }
/* the word Today uses the bar label size (--text-xs) so it fits a chip at 320 px */
html.ui2 .fs-day-btn .fs-day-today { font-size: var(--text-xs); font-weight: var(--fw-semibold); color: inherit; }
html.ui2 .fs-day-btn:hover { background: var(--bg-surface-2); }
html.ui2 .fs-day-btn:focus-visible { outline: var(--focus-outline); outline-offset: 2px; }
html.ui2 .fs-day-btn.today { background: var(--clr-primary-50); border-color: var(--clr-primary-600); color: var(--clr-primary-600); }
html.ui2 .fs-day-btn.selected { background: var(--clr-primary-500); border-color: var(--clr-primary-500); color: var(--on-accent); }
html.ui2 .fs-day-btn.selected small { color: var(--on-accent); }
html.ui2 .fs-day-btn.has-class::after { background: currentColor; }

/* Class cards in My Schedule and the phone My Week list */
html.ui2 #fsMineList .fs-class,
html.ui2 #fsWeekList .fs-class,
html.ui2 #fsMineList .fs-class:last-child,
html.ui2 #fsWeekList .fs-class:last-child {
  flex-direction: column; gap: var(--sp-1); margin-bottom: var(--sp-3); padding: var(--sp-4);
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--r-card);
}
html.ui2 #fsMineList .fs-class-time,
html.ui2 #fsWeekList .fs-class-time {
  flex: none; color: var(--type-lecture); font-size: var(--fs-small); font-weight: var(--fw-semibold);
}
html.ui2 #fsMineList .fs-class:has(.class-type-tag.lab) .fs-class-time,
html.ui2 #fsWeekList .fs-class:has(.class-type-tag.lab) .fs-class-time { color: var(--type-lab); }
html.ui2 #fsMineList .fs-class-time small,
html.ui2 #fsWeekList .fs-class-time small {
  display: inline; font-size: inherit; font-weight: inherit; color: inherit;
}
html.ui2 #fsMineList .fs-class-subject,
html.ui2 #fsWeekList .fs-class-subject { font-size: var(--fs-section); font-weight: var(--fw-semibold); line-height: var(--lh-tight); }
html.ui2 #fsMineList .class-type-tag,
html.ui2 #fsWeekList .class-type-tag { color: var(--type-lecture); }
html.ui2 #fsMineList .class-type-tag.lab,
html.ui2 #fsWeekList .class-type-tag.lab { color: var(--type-lab); }
html.ui2 #fsMineList .fs-room,
html.ui2 #fsWeekList .fs-room {
  padding: 0; background: transparent; color: var(--text-secondary); font-size: var(--fs-small); font-weight: var(--fw-regular);
}
html.ui2 #fsWeekList .fs-day h3 { margin: var(--sp-4) 0 var(--sp-2); }

/* S4 auth, J-09: pages/login.html (pictures 08 and 10, FEEDBACK 4)
   Canvas background, one centered card (12 px radius, 1 px rule, no shadow), seal and name on top,
   labels above the fields, full width filled button, footer line under the card.
   Phones (600 px and below, the auth-style.css breakpoint): the card runs edge to edge with no border.
   Ids, names and the login-script.js hooks (.pw-toggle, data-target, aria-pressed) are unchanged. */
html.ui2 body.page-auth { background: var(--bg-page); }
html.ui2 .auth-shell { flex-direction: column; gap: var(--sp-4); padding: var(--sp-6) var(--gutter); }
html.ui2 .auth-card {
  max-width: 26rem; padding: var(--sp-5) var(--sp-5) var(--sp-5);
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--r-card); box-shadow:none;
}

/* Header: the seal and ATLAS PSU */
html.ui2 .auth-head { display: flex; align-items: center; gap: var(--sp-3); margin: 0 0 var(--sp-5); }
html.ui2 .auth-brand { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
html.ui2 .auth-seal { flex: 0 0 auto; width: 2rem; height: 2rem; }
html.ui2 .auth-brand-name { color: var(--brand-text); font-size: var(--fs-section); font-weight: var(--fw-semibold); line-height: var(--lh-tight); white-space: nowrap; }

/* Heading */
html.ui2 .auth-step h1 { margin: 0 0 var(--sp-1); text-align: left; font-size: var(--fs-title); font-weight: var(--fw-title); line-height: var(--lh-tight); color: var(--text-primary); }

/* Fields: label above, plain input, no leading icon (the svg stays in the markup, hidden here) */
html.ui2 .auth-field { margin-bottom: var(--sp-4); }
html.ui2 .auth-field > label { margin-bottom: var(--sp-1); padding-left: 0; font-size: var(--fs-label); font-weight: var(--fw-label); color: var(--text-primary); }
html.ui2 .auth-card .auth-ic { display: none; }
html.ui2 .auth-input {
  gap: var(--sp-1); min-height: var(--ctl-min); padding: 0 0 0 var(--sp-3);
  background: var(--input-bg); border: 1px solid var(--border-input); border-radius: var(--r-control); box-shadow:none;
}
html.ui2 .auth-card .auth-input input,
html.ui2 .auth-card .auth-input input:focus,
html.ui2 .auth-card .auth-input input:focus-visible {
  min-height: calc(var(--ctl-min) - 2px); padding: 0 var(--sp-3) 0 0; font-size: var(--fs-body);
  color: var(--text-primary); background: transparent; border: 0; box-shadow:none; outline: none;
}
html.ui2 .auth-card .auth-input input::placeholder { color: var(--text-muted); }
/* One focus ring on the whole field (outline, never a shadow); the toggle button keeps its own ring */
html.ui2 .auth-input:focus-within { border-color: var(--border-input); box-shadow:none; }
html.ui2 .auth-input:has(input:focus) { border-color: var(--focus-ring-color); outline: var(--focus-outline); outline-offset: var(--focus-ring-offset); }
/* Period dialog (outside .auth-card): the wrapper draws the one box, so the input and the select inside draw none (fixes the double box) */
html.ui2 .auth-modal .auth-input input,
html.ui2 .auth-modal .auth-input select,
html.ui2 .auth-modal .auth-input input:focus,
html.ui2 .auth-modal .auth-input select:focus,
html.ui2 .auth-modal .auth-input input:focus-visible,
html.ui2 .auth-modal .auth-input select:focus-visible {
  flex: 1; width: 100%; min-width: 0; min-height: calc(var(--ctl-min) - 2px); padding: 0 var(--sp-3) 0 0; font-family: inherit; font-size: var(--fs-body);
  color: var(--text-primary); background: transparent; border: 0; border-radius: 0; box-shadow:none; outline: none;
}
html.ui2 .auth-modal .auth-input select { cursor: pointer; text-overflow: ellipsis; }
html.ui2 .auth-modal .auth-input:has(select:focus-visible) { border-color: var(--focus-ring-color); outline: var(--focus-outline); outline-offset: var(--focus-ring-offset); }

/* Error state: invalid fields get the danger border, messages carry an icon and the code's own text */
html.ui2 .auth-field.invalid .auth-input,
html.ui2 .auth-input:has(input[aria-invalid="true"]) { border-color: var(--ui-danger-fg); }
html.ui2 .auth-error {
  display: flex; align-items: flex-start; gap: var(--sp-1); margin-top: var(--sp-1); padding-left: 0;
  font-size: var(--fs-small); font-weight: var(--fw-medium); line-height: var(--lh-body); color: var(--ui-danger-fg);
}
html.ui2 .auth-error::before {
  content: ""; flex-shrink: 0; width: 1rem; height: 1rem; margin-top: 0.125rem;
  background: currentColor; -webkit-mask: var(--ic-error) center / contain no-repeat; mask: var(--ic-error) center / contain no-repeat;
}
/* Empty error lines take no space but stay rendered, so the polite live region still announces */
html.ui2 .auth-error:empty { display: block; height: 0; margin: 0; overflow: hidden; }
html.ui2 .auth-error:empty::before { content: none; }
html.ui2 .auth-alert {
  display: flex; align-items: flex-start; gap: var(--sp-2); margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-body); font-weight: var(--fw-medium); line-height: var(--lh-body);
  background: var(--ui-danger-bg); color: var(--ui-danger-fg); border: 1px solid var(--ui-danger-bd); border-radius: var(--r-control);
}
html.ui2 .auth-alert::before {
  content: ""; flex-shrink: 0; width: 1.125rem; height: 1.125rem; margin-top: 0.125rem;
  background: currentColor; -webkit-mask: var(--ic-error) center / contain no-repeat; mask: var(--ic-error) center / contain no-repeat;
}
html.ui2 .auth-alert.info { background: var(--bg-surface-2); color: var(--text-primary); border-color: var(--border-default); }
html.ui2 .auth-alert.info::before { -webkit-mask-image: var(--ic-info); mask-image: var(--ic-info); }
html.ui2 .auth-alert[hidden] { display: none; }

/* Show or hide password (FEEDBACK 4): a text button inside the field, the label swaps with aria-pressed */
html.ui2 .auth-card .pw-toggle.field-toggle {
  position: static; flex: 0 0 auto; align-self: stretch; width: auto; height: auto; min-width: 2.75rem; min-height: 0; margin: 0;
  padding: 0 var(--sp-3); border: 0; border-radius: 0 var(--r-control) var(--r-control) 0;
  background: transparent; color: var(--brand-text); font-size: var(--fs-small); font-weight: var(--fw-semibold); white-space: nowrap;
}
html.ui2 .auth-card .pw-toggle.field-toggle:hover { background: var(--bg-surface-2); color: var(--brand-text); text-decoration: underline; }
html.ui2 .auth-card .pw-toggle.field-toggle:active { transform: none; }
html.ui2 .pw-toggle .pw-hide,
html.ui2 .pw-toggle[aria-pressed="true"] .pw-show { display: none; }
html.ui2 .pw-toggle[aria-pressed="true"] .pw-hide { display: inline; }
html.ui2 .auth-forgot { margin: var(--sp-1) 0 0; font-size: var(--fs-small); line-height: var(--lh-body); color: var(--text-secondary); }

/* One filled button per view: Log in */
html.ui2 .auth-card .auth-btn {
  min-height: var(--ctl-min); margin-top: var(--sp-2); padding: 0 var(--sp-4); font-size: var(--fs-body); font-weight: var(--fw-semibold);
  color: var(--on-accent); background: var(--brand); border: 1px solid var(--brand); border-radius: var(--r-control); box-shadow:none;
}
html.ui2 .auth-card .auth-btn:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--on-accent); }
html.ui2 .auth-card .auth-btn-google { color: var(--text-primary); background: var(--bg-surface); border-color: var(--border-input); }
html.ui2 .auth-card .auth-btn-google:hover { background: var(--bg-surface-2); border-color: var(--border-input); color: var(--text-primary); }
html.ui2 .auth-divider { font-size: var(--fs-small); color: var(--text-secondary); }

/* Fine print, privacy notice and footer */
html.ui2 .auth-fine { margin: var(--sp-4) 0 0; text-align: left; font-size: var(--fs-small); line-height: var(--lh-body); color: var(--text-secondary); }
html.ui2 .auth-privacy {
  margin-top: var(--sp-4); padding: var(--sp-2) var(--sp-3); font-size: var(--fs-small);
  background: transparent; border: 1px solid var(--border-subtle); border-radius: var(--r-control); color: var(--text-secondary);
}
html.ui2 .auth-privacy h2 { font-size: var(--fs-body); }
html.ui2 .auth-privacy-details summary::after { color: var(--brand-text); }
html.ui2 .auth-privacy-details summary:focus-visible { outline: var(--focus-outline); outline-offset: var(--focus-ring-offset); }
/* Offline demo note (added by demo-supabase.js with inline styles, so the layer needs !important) */
html.ui2 #demoNotice { border: 1px solid var(--border-subtle) !important; border-radius: var(--r-control) !important; font-size: var(--fs-small) !important; color: var(--text-secondary); }
html.ui2 #demoNotice strong { color: var(--text-primary); }
html.ui2 .auth-foot { margin: 0; text-align: center; font-size: var(--fs-small); color: var(--text-secondary); }

/* Phones: card edge to edge, no border, same order, 44 px controls */
@media (max-width: 600px) {
  html.ui2 .auth-shell { gap: 0; padding: 0; }
  html.ui2 .auth-card {
    max-width: none; min-height: 0; flex: 1 0 auto;
    padding: calc(var(--sp-4) + env(safe-area-inset-top, 0px)) var(--gutter) var(--sp-5);
    background: var(--bg-surface); border: 0; border-radius: 0;
  }
  html.ui2 .auth-input { min-height: 2.75rem; background: var(--input-bg); }
  html.ui2 .auth-card .auth-input input,
  html.ui2 .auth-card .auth-input input:focus,
  html.ui2 .auth-card .auth-input input:focus-visible { min-height: calc(2.75rem - 2px); }
  html.ui2 .auth-card .auth-btn { min-height: 2.75rem; }
  html.ui2 .auth-card .pw-toggle.field-toggle { min-height: 2.75rem; }
  html.ui2 .auth-foot { width: 100%; padding: var(--sp-4) var(--gutter) calc(var(--sp-4) + env(safe-area-inset-bottom, 0px)); background: var(--bg-surface); }
}

/* S3 shell, J-10: hardening
   Print: the sidebar, top bar, bottom bar, rail tooltip and account menu never print, and the shell grid
   falls back to normal flow so EXP-01 print views look as they did before UI2 (main-style.css section 34
   still hides .top-navbar; these rules cover the parts UI2 added). */
@media print {
  html.ui2 .side-nav,
  html.ui2 .side-tip,
  html.ui2 .top-navbar,
  html.ui2 .bottom-nav,
  html.ui2 .user-menu { display: none !important; }
  html.ui2 .app-shell,
  html.ui2 .app-main { display: block; height: auto; min-height: 0; }
  html.ui2 .panels-wrapper { height: auto; margin: 0; overflow: visible; }
  html.ui2 body { padding-bottom: 0; }
}

/* Full screen timetable (.sv-daypage from schedule-views.js, z-index 20010): it already sits above the
   sidebar (1001, peek 1100), the rail tooltip (1200), the top bar and the bottom bar. While it is open the
   page behind it does not scroll, on the body (phones) or in .panels-wrapper (desktop). */
html.ui2 body:has(> .sv-daypage) { overflow: hidden; }
html.ui2 body:has(> .sv-daypage) .panels-wrapper { overflow: hidden; }

/* The J-03 button rule (html.ui2 .btn) outranked main-style.css .edit-bar .btn { min-height: 44px }:
   the schedule edit bar (Undo, Redo, Reset) keeps its 44 px targets at every width (tests/test_ui5.py) */
html.ui2 .edit-bar .btn { min-height: max(var(--ctl-min), 2.75rem, 44px); }


/* ============================================================
   U5-01 ONE SCROLLBAR (D-U2). Tokens plus one rule set for html, body, .panel and every scrolling container.
   Chairperson and faculty scroll inside .panel, admin and app pages scroll the document: both now read these values.
   The thin list variants (.dropdown-content, .modal-assignment-list), the hidden rails (.side-nav, .nav-menu) and the
   phone (.panel scrollbar hidden in main-style.css) keep their own rules because they are more specific than the
   zero specificity :where() selectors below. Chromium ignores ::-webkit-scrollbar once scrollbar-width or
   scrollbar-color is set, so the standard properties are given to browsers without the webkit pseudo only (Firefox).
   ============================================================ */
html.ui2 {
  --sb-size: 16px;
  --sb-gap: 4px;                   /* thumb border: the thumb is 8px wide inside the 16px track */
  --sb-track: #f6f3f0;
  --sb-track-edge: var(--border-subtle);
  --sb-thumb: #aa9f93;
  --sb-thumb-hover: #7f746a;
  --sb-thumb-active: var(--clr-primary-600);
}
html.ui2[data-theme="dark"] {
  --sb-track: var(--bg-surface-2);
  --sb-thumb: #6b5e52;
  --sb-thumb-hover: #8a7c6f;
}
:where(html.ui2)::-webkit-scrollbar,
:where(html.ui2) ::-webkit-scrollbar { width: var(--sb-size); height: var(--sb-size); }
:where(html.ui2)::-webkit-scrollbar-track,
:where(html.ui2) ::-webkit-scrollbar-track { background: var(--sb-track); border-left: 1px solid var(--sb-track-edge); }
:where(html.ui2)::-webkit-scrollbar-thumb,
:where(html.ui2) ::-webkit-scrollbar-thumb {
  background: var(--sb-thumb); background-clip: padding-box; border: var(--sb-gap) solid var(--sb-track);
  border-radius: 999px; min-height: 48px; min-width: 48px;
}
:where(html.ui2)::-webkit-scrollbar-thumb:hover,
:where(html.ui2) ::-webkit-scrollbar-thumb:hover { background: var(--sb-thumb-hover); background-clip: padding-box; }
:where(html.ui2)::-webkit-scrollbar-thumb:active,
:where(html.ui2) ::-webkit-scrollbar-thumb:active { background: var(--sb-thumb-active); background-clip: padding-box; }
:where(html.ui2)::-webkit-scrollbar-corner,
:where(html.ui2) ::-webkit-scrollbar-corner { background: var(--sb-track); }
@supports not selector(::-webkit-scrollbar) {
  :where(html.ui2), :where(html.ui2) * { scrollbar-width: auto; scrollbar-color: var(--sb-thumb) var(--sb-track); }
}
/* a container that scrolls on its own and is not a .panel: add this class so the audit finds it */
html.ui2 .scroll-y { overflow-y: auto; }

/* U5-04 chart and monitor tokens (assets/js/live-chart.js reads them once with getComputedStyle).
   The Test Lab monitor is a dark instrument panel in light and in dark theme, so both blocks hold light on dark values.
   Contrast on --monitor-bg: text 13.5 to 14.3, series and bound lines 8.1 to 10.4, grid is decorative only. */
html.ui2 {
  --monitor-bg: #080a0d;   /* U6-03: near black, the same value in light and dark */
  --monitor-edge: #2b3a4d;
  --monitor-text: #d5e0ec;
  --monitor-muted: #9fb0c3;
  --chart-cpsat: #3fc1b8;
  --chart-ga: #f0a64a;
  --chart-bound: #9fb0c3;
  --monitor-grid: #2b3a4d;
  --chart-text: #d5e0ec;
  --monitor-ok: #6fdcaa;
  --monitor-bad: #ff9a8f;
  --monitor-warn: #f5c76a;
}
html.ui2[data-theme="dark"] {
  --monitor-bg: #080a0d;
  --monitor-edge: #2a384a;
  --monitor-text: #d5e0ec;
  --monitor-muted: #9fb0c3;
  --chart-cpsat: #45cdc4;
  --chart-ga: #f5b25a;
  --chart-bound: #a6b6c9;
  --monitor-grid: #2a384a;
  --chart-text: #d5e0ec;
  --monitor-ok: #6fdcaa;
  --monitor-bad: #ff9a8f;
  --monitor-warn: #f5c76a;
}
