/* ==========================================================================
   style.css - the EDITOR chrome (app bar, sidebar, form, buttons, toasts,
   modal). The generated cover page itself is styled by themes.css, and the
   PDF is drawn straight from `state` by pdf.js - nothing in here can affect
   either one.

   Design system: "My design system" (DESIGN.md) - dark surface ladder
   (#10131a -> #31353c), electric-blue primary (#1275e2 / #4090fe),
   Inter for UI type, rounded shape language (0.5 / 0.75 / 1 / 1.5rem).

   Responsive strategy (mobile-first, and NOT width-only):
     1. base ............ single-column shell; the editor is a full-screen
                          drawer. Correct for phones AND for short viewports
                          (landscape phones, squat laptop windows, split
                          screens) where a fixed sidebar would leave no room.
     2. >= 560px ........ app bar regains its spec pill / brand subtitle.
     3. >= 768px AND >= 560px tall ...  persistent sidebar beside the stage,
                          with a fluid --sidebar-w so the split flexes
                          continuously instead of stepping between sizes.
     4. height queries .. compact the chrome when vertical space is scarce.
   The stage itself needs no width logic: preview.js always fits the sheet to
   whatever box it is given.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* The `hidden` attribute must always win. Several rules below target an id
   or class with the same or higher specificity than the UA's `[hidden]`
   rule (e.g. `#logo-preview-wrap{display:flex}`, `.field-hint{display:block}`),
   which would otherwise silently defeat it. One rule, top of the cascade,
   fixes every current and future case instead of patching each selector. */
[hidden] { display: none !important; }

:root {
  /* -------------------------------------------------— design-system tokens */
  --surface: #10131a;
  --surface-dim: #10131a;
  --surface-container-lowest: #0b0e14;
  --surface-container-low: #181c22;
  --surface-container: #1c2026;
  --surface-container-high: #272a31;
  --surface-container-highest: #31353c;
  --on-surface: #e0e2eb;
  --on-surface-variant: #c1c6d5;
  --outline: #8b919f;
  --outline-variant: #414753;
  --primary: #1275e2;
  --primary-container: #4090fe;
  --primary-fixed-dim: #aac7ff;
  --on-primary: #ffffff;
  --secondary: #aec7f7;
  --secondary-container: #2d476f;
  --on-secondary-container: #9db6e4;
  --tertiary: #a957c6;
  --error: #ffb4ab;
  --on-error: #690005;
  --error-container: #93000a;

  /* rounded shape language */
  --radius-sm: .5rem;
  --radius: .75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;

  /* --------------------------------------------- semantic aliases (internal) */
  --bg: var(--surface);
  --panel: var(--surface-container-low);
  --panel-2: var(--surface-container);
  --panel-3: var(--surface-container-high);
  --border: color-mix(in srgb, var(--outline-variant) 62%, transparent);
  --border-strong: var(--outline-variant);
  --accent: var(--primary);
  --accent-strong: #0e63bd;
  --accent-soft: rgba(18, 117, 226, .16);
  --accent-ink: var(--primary-fixed-dim);
  --text: var(--on-surface);
  --muted: var(--on-surface-variant);
  --muted-2: #8f99ac;
  --input-bg: var(--surface-container-lowest);
  --input-border: color-mix(in srgb, var(--outline-variant) 82%, transparent);
  --danger: var(--error);
  --success: #4ade9b;
  --info: var(--primary-fixed-dim);
  --warn: #fbbf24;

  --app-bar-h: 60px;
  --sidebar-w: 404px;

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
}

html { color-scheme: dark; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font-family: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary-container); outline-offset: 2px; }

.icon {
  width: 18px; height: 18px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon-sm { width: 15px; height: 15px; }
#icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* =========================================================== app shell ==== */
#app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* sidebar becomes a drawer (base) */
  min-height: 0;
}

/* ------------------------------------------------------------ site footer */
/* Minimal one-line credit bar. It is the app-shell grid's third row, so the
   sidebar/stage row keeps its min-height:0 flexing; it drops out entirely on
   short viewports (see max-height queries below) and in print, so the A4
   sheet keeps every pixel and the PDF output is untouched. */
#site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 14px;
  padding-bottom: max(5px, env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-top: 1px solid var(--border);
}
.site-footer-credit {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .8px;
  color: var(--muted-2);
  white-space: nowrap;
}
.hero-credit { color: var(--muted-2); }

/* ------------------------------------------------------------------ app bar */
#app-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: var(--app-bar-h);
  padding: 10px max(14px, env(safe-area-inset-right, 0px)) 10px max(14px, env(safe-area-inset-left, 0px));
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .35);
  z-index: 60;
}

#brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
#brand-mark {
  width: 38px; height: 38px; flex-shrink: 0; border-radius: var(--radius);
  background: linear-gradient(160deg, #ffffff 0%, #dfe5ef 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .35);
}
#brand-mark img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
#brand-text { display: flex; flex-direction: column; min-width: 0; }

/* Just the acronym beside the crest - no product chip, no subtitle. */
#brand-title {
  font-size: 17px; font-weight: 800; letter-spacing: .5px;
  color: #fff; line-height: 1.1;
}

#app-bar-meta { margin-left: auto; display: none; align-items: center; gap: 10px; }

.spec-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  background: var(--surface-container); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; white-space: nowrap;
}
.spec-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--success);
  animation: dotPulse 2.4s ease-in-out infinite;
}
@keyframes dotPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 155, .55); }
  50% { box-shadow: 0 0 0 5px rgba(74, 222, 155, 0); }
}

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .7px; text-transform: uppercase;
  border-radius: 999px; padding: 5px 10px; white-space: nowrap;
}
.chip-live { background: var(--accent-soft); color: var(--accent-ink); border: 1px solid rgba(64, 144, 254, .35); }
.chip-quiet { background: var(--surface-container); color: var(--muted); border: 1px solid var(--border); }
.chip-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--primary-container);
  animation: dotPulseBlue 2.2s ease-in-out infinite;
}
@keyframes dotPulseBlue {
  0%, 100% { box-shadow: 0 0 0 0 rgba(64, 144, 254, .6); }
  50% { box-shadow: 0 0 0 5px rgba(64, 144, 254, 0); }
}

/* ------------------------------------------------------------------ sidebar */
#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  overflow: hidden;
  /* base = full-screen drawer */
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 100%;
  transform: translateX(-100%);
  transition: transform .3s cubic-bezier(.4, 0, .2, 1);
  z-index: 80;
}
#sidebar.open { transform: translateX(0); }

#sidebar-header {
  flex-shrink: 0;
  padding: 18px 20px 16px;
  padding-top: max(18px, env(safe-area-inset-top, 0px));
  background:
    radial-gradient(120% 130% at 0% 0%, rgba(64, 144, 254, .16) 0%, rgba(64, 144, 254, 0) 58%),
    linear-gradient(180deg, var(--surface-container) 0%, var(--surface-container-low) 100%);
  border-bottom: 1px solid var(--border);
}
#sidebar-header-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
/* The official name is the eyebrow; the product name is the display line.
   Sizes are em-based so the compact-height rules scale both together. */
#sidebar-header h1 {
  font-family: var(--font-serif); font-size: 21px; font-weight: 700;
  margin: 0; color: #fff; line-height: 1.22; letter-spacing: -.2px;
}
#sidebar-header h1 .h1-eyebrow {
  display: block; font-family: var(--font-ui);
  font-size: .54em; font-weight: 600; line-height: 1.4;
  letter-spacing: .07em; text-transform: uppercase; color: var(--muted-2);
  margin-bottom: .3em;
}
#sidebar-header h1 .h1-title { display: block; }
#sidebar-header h1 em { font-style: italic; color: var(--accent-ink); }
#sidebar-header p { font-size: 12.5px; line-height: 1.5; color: var(--muted); margin: 8px 0 0; }

#close-sidebar-btn {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 12px;
  background: color-mix(in srgb, var(--on-surface) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--on-surface) 22%, transparent);
  color: #fff; border-radius: var(--radius-sm); padding: 9px 14px;
  font-size: 12.5px; font-weight: 600; cursor: pointer; min-height: 40px;
}

/* segmented tab switcher */
#sidebar-tabs {
  display: flex; gap: 4px; flex-shrink: 0;
  margin: 12px 14px; padding: 4px;
  background: var(--surface-container-lowest);
  border: 1px solid var(--border); border-radius: var(--radius);
  position: sticky; top: 0;
}
#sidebar-tabs [role="tab"] {
  flex: 1; min-height: 38px; display: flex; align-items: center; justify-content: center; gap: 7px;
  background: transparent; border: none; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 12.5px; font-weight: 600; letter-spacing: .2px; color: var(--muted);
  transition: background .16s, color .16s;
}
#sidebar-tabs [role="tab"]:hover { color: var(--text); background: var(--surface-container); }
#sidebar-tabs [role="tab"][aria-selected="true"] {
  background: var(--primary); color: var(--on-primary);
  box-shadow: 0 2px 10px rgba(18, 117, 226, .38);
}

#form-scroll {
  flex: 1; overflow-y: auto; padding: 4px 16px 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
}
#form-scroll::-webkit-scrollbar { width: 8px; }
#form-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
#form-scroll::-webkit-scrollbar-track { background: transparent; }

.side-section { margin: 0 0 22px; }

.section-label {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: 1.3px; text-transform: uppercase; color: var(--accent-ink);
  margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

/* ------------------------------------------------------------------- fields */
.field { position: relative; margin-bottom: 13px; }
.input-row { display: flex; gap: 12px; margin-bottom: 13px; }
.input-row .field { flex: 1; margin-bottom: 0; min-width: 0; }

.field label {
  display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted-2); margin-bottom: 6px;
}
.field-hint { display: block; font-size: 11.5px; color: var(--warn); margin-top: 5px; line-height: 1.4; }
.field-warning {
  font-size: 11.5px; color: var(--warn); background: rgba(251, 191, 36, .1);
  border: 1px solid rgba(251, 191, 36, .3); border-radius: var(--radius-sm);
  padding: 9px 11px; margin: 10px 0 0; line-height: 1.45;
}

.field input[type="text"], .field input[type="date"], .field input:not([type]), .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--input-bg); border: 1px solid var(--input-border); border-radius: var(--radius);
  color: var(--text); font-size: 15px; outline: none;
  transition: border-color .16s, box-shadow .16s, background .16s;
  -webkit-appearance: none; appearance: none;
}
.field input::placeholder { color: #5c6577; }
.field input:hover, .field select:hover { border-color: var(--outline); }
.field input:focus, .field select:focus {
  border-color: var(--primary-container); background: var(--surface-container-lowest);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field select {
  padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23c1c6d5' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 15px;
}
select option { background: var(--input-bg); color: var(--text); }

/* ------------------------------------------------------------------ toggles */
/* Scoped as .toggle-grid .toggle on purpose: `.field label` (a block label
   with its own type styling) has higher specificity than a bare `.toggle`,
   and the switch markup is a <label> inside a .field. */
/* auto-fit + minmax collapses to one column on narrow sidebars; without it a
   2-column track would be forced wider than the sidebar by its labels. */
.toggle-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 8px; }
.toggle-grid .toggle {
  display: flex; flex-direction: row; align-items: center; justify-content: space-between;
  gap: 10px; min-height: 46px; padding: 9px 11px; cursor: pointer;
  background: var(--input-bg); border: 1px solid var(--input-border); border-radius: var(--radius);
  font-size: 13px; font-weight: 500; letter-spacing: normal; text-transform: none; color: var(--text);
  transition: border-color .16s, background .16s;
}
.toggle-grid .toggle:hover { border-color: var(--outline); background: var(--surface-container); }
.toggle-grid .toggle:focus-within { border-color: var(--primary-container); box-shadow: 0 0 0 3px var(--accent-soft); }
.toggle-grid .toggle input {
  -webkit-appearance: none; appearance: none; margin: 0; flex-shrink: 0;
  width: 40px; height: 22px; min-height: 0; padding: 0; border-radius: 999px;
  position: relative; cursor: pointer;
  background: var(--surface-container-highest); border: 1px solid var(--border-strong);
  transition: background .18s, border-color .18s;
}
.toggle-grid .toggle input::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: #aab3c6;
  transition: transform .18s cubic-bezier(.4, 0, .2, 1), background .18s;
}
.toggle-grid .toggle input:checked { background: var(--primary); border-color: var(--primary-container); }
.toggle-grid .toggle input:checked::after { transform: translateX(18px); background: #fff; }
.toggle-grid .toggle span {
  min-width: 0; order: -1; /* label first, switch on the right */
  /* Wrapping (not nowrap) keeps every label's min-content small, so the grid
     can shrink and the switch never gets pushed out of the card. */
  overflow-wrap: break-word; line-height: 1.25;
}

/* ------------------------------------------------------------------ swatches */
.swatch-row {
  display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 10px;
  padding: 11px; background: var(--input-bg);
  border: 1px solid var(--input-border); border-radius: var(--radius);
}
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
  padding: 0; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
  transition: transform .14s, box-shadow .14s;
}
.swatch:hover { transform: scale(1.08); }
.swatch.active {
  border-color: #fff; transform: scale(1.04);
  box-shadow: 0 0 0 2px var(--input-bg), 0 0 0 4px var(--primary-container);
}
.swatch-custom { display: flex; align-items: center; gap: 10px; }
#accent-custom {
  width: 48px; height: 36px; padding: 2px; cursor: pointer;
  background: var(--input-bg); border: 1px solid var(--input-border); border-radius: var(--radius-sm);
}
.swatch-custom-hint { font-size: 12.5px; color: var(--muted-2); }

/* ----------------------------------------------------------- template grid */
.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.template-card {
  position: relative; display: flex; flex-direction: column; gap: 8px;
  /* Explicit stretch: the UA stylesheet gives <button> align-items:flex-start,
     which would shrink-wrap the thumbnail instead of filling the card. */
  align-items: stretch; justify-content: flex-start;
  padding: 10px; cursor: pointer; text-align: left; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  transition: border-color .16s, transform .12s, box-shadow .16s, background .16s;
}
.template-card:hover { border-color: var(--outline); background: var(--panel-3); transform: translateY(-1px); }
.template-card:active { transform: scale(.985); }
.template-card.active {
  border-color: var(--primary-container);
  box-shadow: 0 0 0 1px var(--primary-container), 0 10px 24px rgba(18, 117, 226, .26);
}
/* CSS-drawn "selected" badge (no icon font, no extra markup) */
.template-card.active::after {
  content: ''; position: absolute; top: 8px; right: 8px;
  width: 18px; height: 18px; border-radius: 50%; background: var(--primary-container);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
}
.template-card.active::before {
  content: ''; position: absolute; top: 11px; right: 15px; z-index: 1;
  width: 4px; height: 8px; border: solid var(--on-primary); border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.template-card-name { font-size: 13px; font-weight: 700; letter-spacing: -.1px; }
.template-card-desc { font-size: 11px; line-height: 1.4; color: var(--muted); }

.tpl-thumb {
  background: linear-gradient(180deg, #ffffff 0%, #f2f4f8 100%);
  border-radius: var(--radius-sm); height: 58px; padding: 9px 10px;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .1);
}
.tpl-thumb span { display: block; background: #cfd3e0; height: 3px; border-radius: 2px; }
.tpl-thumb-classic { align-items: center; }
.tpl-thumb-classic span:nth-child(1) { width: 55%; }
.tpl-thumb-classic span:nth-child(2) { width: 75%; background: #7383a8; }
.tpl-thumb-classic span:nth-child(3) { width: 40%; }
.tpl-thumb-minimal span:nth-child(1) { width: 70%; background: #3457a6; height: 4px; }
.tpl-thumb-minimal span:nth-child(2) { width: 35%; }
.tpl-thumb-minimal span:nth-child(3) { width: 50%; }
.tpl-thumb-corporate { padding: 0; justify-content: flex-start; overflow: hidden; }
.tpl-thumb-corporate span:nth-child(1) { width: 100%; height: 14px; background: #1f5c4a; margin-bottom: 6px; }
.tpl-thumb-corporate span:nth-child(2) { width: 40%; margin-left: 10px; }
.tpl-thumb-corporate span:nth-child(3) { width: 60%; margin-left: 10px; background: #9fb8ae; }
.tpl-thumb-ivy { align-items: center; justify-content: center; }
.tpl-thumb-ivy span:nth-child(1) { width: 22%; height: 6px; border-radius: 50%; background: none; box-shadow: inset 0 0 0 1.5px #7a1f2b; }
.tpl-thumb-ivy span:nth-child(2) { width: 68%; margin-top: 2px; }
.tpl-thumb-ivy span:nth-child(3) { width: 34%; height: 2px; background: #7a1f2b; }
.tpl-thumb-modern-collegiate { padding: 0; justify-content: flex-start; overflow: hidden; }
.tpl-thumb-modern-collegiate span:nth-child(1) { width: 100%; height: 16px; background: #c2410c; margin-bottom: 7px; }
.tpl-thumb-modern-collegiate span:nth-child(2) { width: 45%; margin-left: 10px; background: #d99872; }
.tpl-thumb-modern-collegiate span:nth-child(3) { width: 55%; margin-left: 10px; }
.tpl-thumb-oxford-classic { align-items: center; }
.tpl-thumb-oxford-classic span:nth-child(1) { width: 70%; }
.tpl-thumb-oxford-classic span:nth-child(2) { width: 84%; height: 2.5px; background: #002147; box-shadow: 0 4px 0 -1px #002147; margin-bottom: 3px; }
.tpl-thumb-oxford-classic span:nth-child(3) { width: 46%; }
.tpl-thumb-institute-technical { align-items: flex-start; }
.tpl-thumb-institute-technical span:nth-child(1) { width: 76%; height: 5px; background: #3a3f4a; }
.tpl-thumb-institute-technical span:nth-child(2) { width: 100%; height: 3px; background: #a31f34; }
.tpl-thumb-institute-technical span:nth-child(3) { width: 58%; }

/* the last archetype reads as a wide "banner" card */
.template-grid .template-card[data-template="institute-technical"] {
  grid-column: 1 / -1;
  display: grid; align-items: center;
  grid-template-columns: 86px minmax(0, 1fr);
  grid-template-areas: "thumb name" "thumb desc";
  gap: 2px 12px;
}
.template-card[data-template="institute-technical"] .tpl-thumb { grid-area: thumb; height: 58px; }
.template-card[data-template="institute-technical"] .template-card-name { grid-area: name; }
.template-card[data-template="institute-technical"] .template-card-desc { grid-area: desc; }

/* -------------------------------------------------------------------- logo */
.dropzone {
  border: 1.5px dashed var(--input-border); border-radius: var(--radius-lg);
  padding: 16px; text-align: center; cursor: pointer; margin-bottom: 12px;
  background: var(--surface-container-low);
  transition: border-color .16s, background .16s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary-container); background: var(--accent-soft); }
.dropzone p { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); }

#logo-preview-wrap { display: flex; align-items: center; gap: 12px; }
#logo-preview-img {
  width: 60px; height: 60px; object-fit: contain; background: #fff;
  border-radius: var(--radius-sm); padding: 4px; box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
}
#logo-remove-btn {
  background: transparent; border: 1px solid color-mix(in srgb, var(--error) 50%, transparent); color: var(--danger);
  border-radius: var(--radius-sm); padding: 8px 14px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; min-height: 40px;
}
#logo-remove-btn:hover { background: color-mix(in srgb, var(--error) 14%, transparent); }

#logo-browse-btn, #btn-pust-logo {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel-3); border: 1px solid var(--border-strong); color: var(--text);
  border-radius: var(--radius); padding: 10px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; min-height: 42px;
  transition: border-color .16s, background .16s, color .16s;
}
#logo-browse-btn:hover, #btn-pust-logo:hover { border-color: var(--primary-container); color: #fff; background: var(--surface-container-highest); }
#btn-pust-logo { width: 100%; }

/* ------------------------------------------------------------------ footer */
#sidebar-footer {
  flex-shrink: 0; padding: 14px max(16px, env(safe-area-inset-left, 0px));
  padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .28);
}
#footer-actions-row { display: flex; gap: 7px; margin-bottom: 10px; }
#footer-actions-row button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 9px 6px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--muted); font-size: 12px; font-weight: 600;
  transition: border-color .16s, color .16s, background .16s;
}
#footer-actions-row button:hover { border-color: var(--primary-container); color: #fff; background: var(--panel-3); }

#btn-pdf {
  position: relative; overflow: hidden; width: 100%; min-height: 52px; padding: 14px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  background: linear-gradient(120deg, var(--primary-container) 0%, var(--primary) 100%);
  color: var(--on-primary); border: none; border-radius: var(--radius); cursor: pointer;
  font-size: 15px; font-weight: 700; letter-spacing: .2px;
  box-shadow: 0 10px 24px rgba(18, 117, 226, .34);
  transition: filter .18s, transform .1s;
}
#btn-pdf:hover:not(:disabled) { filter: brightness(1.08); }
#btn-pdf:active:not(:disabled) { transform: scale(.99); }
#btn-pdf:disabled { opacity: .72; cursor: default; }
.btn-tag {
  font-family: var(--font-mono); font-size: 10px; font-weight: 600; letter-spacing: .7px;
  padding: 3px 7px; border-radius: 5px; background: rgba(0, 0, 0, .26);
  border: 1px solid rgba(255, 255, 255, .24);
}
.btn-sheen {
  position: absolute; top: 0; left: 0; width: 42%; height: 100%; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .3), transparent);
  animation: sheen 6.5s cubic-bezier(.4, 0, .2, 1) infinite;
}
@keyframes sheen {
  0%, 72% { transform: translateX(-160%) skewX(-18deg); }
  92%, 100% { transform: translateX(320%) skewX(-18deg); }
}

#autosave-note {
  display: flex; align-items: center; gap: 7px; justify-content: center;
  margin: 10px 0 0; font-size: 11.5px; color: var(--muted-2);
}

/* -------------------------------------------------------------------- stage */
#stage {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0; min-width: 0;
  background:
    radial-gradient(70% 55% at 50% 0%, rgba(64, 144, 254, .07) 0%, rgba(64, 144, 254, 0) 70%),
    var(--surface-container-lowest);
}

#stage-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px max(14px, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(8px);
}
.stage-note {
  margin-left: auto; display: none; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--success);
}

#preview-area {
  min-height: 0; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  /* `safe` keeps a zoomed-in page scrollable instead of clipped off-screen;
     the plain `center` above is the fallback for engines without it. */
  align-items: safe center; justify-content: safe center;
  overflow: auto; padding: 14px; /* never exceed preview.js's 24px fit reserve */
  overscroll-behavior: contain;
}

/* ui.js parks the sheet in this box and keeps it exactly the size of the
   scaled page, so the centering above is honest (see setupStageZoom in
   js/ui.js). Scaling from the top-left corner makes the visual footprint
   line up with the box. */
.a4-stage-fit { position: relative; }
#preview-area .a4-scale-wrapper { transform-origin: top left; }

#stage-dock {
  display: none; justify-self: center; margin: 0 16px 16px;
  align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface-container) 94%, transparent);
  border: 1px solid var(--border-strong);
  box-shadow: 0 16px 36px rgba(0, 0, 0, .5);
  backdrop-filter: blur(10px);
}
#stage-dock button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 36px; padding: 6px 12px; cursor: pointer;
  background: transparent; border: none; border-radius: 999px;
  color: var(--muted); font-size: 12.5px; font-weight: 600;
  transition: background .16s, color .16s;
}
#stage-dock button:hover { background: var(--panel-3); color: #fff; }
#zoom-out, #zoom-in { padding: 6px 9px !important; }
#zoom-label {
  min-width: 48px; text-align: center;
  font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; color: var(--text);
}
.dock-sep { width: 1px; height: 18px; background: var(--border-strong); }
.dock-primary { background: var(--primary) !important; color: var(--on-primary) !important; }
.dock-primary:hover { background: var(--primary-container) !important; }

/* drawer trigger: a row of #stage, so it can never cover the sheet */
#mobile-menu-btn {
  display: inline-flex; justify-self: center;
  align-items: center; justify-content: center; gap: 9px;
  margin: 0 14px max(14px, calc(env(safe-area-inset-bottom, 0px) + 10px));
  padding: 12px 20px; min-height: 48px; cursor: pointer;
  background: linear-gradient(120deg, var(--primary-container) 0%, var(--primary) 100%);
  color: var(--on-primary); border: none; border-radius: 999px;
  font-size: 14.5px; font-weight: 700;
  box-shadow: 0 10px 26px rgba(18, 117, 226, .42);
}
#mobile-menu-btn:active { transform: scale(.98); }
#mobile-menu-btn.is-hidden { display: none !important; }

/* ------------------------------------------------------------------ toasts */
#toast-region {
  position: fixed; left: 50%; bottom: max(24px, calc(env(safe-area-inset-bottom, 0px) + 16px));
  transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 420px); pointer-events: none;
}
.toast {
  background: var(--panel-3); border: 1px solid var(--border-strong); color: var(--text);
  padding: 12px 16px; border-radius: var(--radius); font-size: 13.5px; line-height: 1.45;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .45);
  opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-color: var(--success); }
.toast-error { border-color: var(--danger); }
.toast-info { border-color: var(--info); }

/* ------------------------------------------------------------------- modal */
#modal-overlay {
  position: fixed; inset: 0; z-index: 300; padding: 20px;
  background: rgba(6, 7, 12, .74); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
#modal-box {
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--radius-xl);
  padding: 24px; max-width: 400px; width: 100%; box-shadow: 0 30px 70px rgba(0, 0, 0, .6);
}
#modal-title { font-size: 17px; font-weight: 700; margin: 0 0 10px; }
#modal-body { font-size: 13.5px; color: var(--muted); line-height: 1.55; margin: 0 0 22px; }
#modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
#modal-actions button {
  padding: 11px 20px; border-radius: var(--radius); cursor: pointer;
  font-size: 13.5px; font-weight: 600; min-height: 44px;
}
#modal-cancel { background: transparent; border: 1px solid var(--border-strong); color: var(--text); }
#modal-cancel:hover { background: var(--panel-2); }
#modal-confirm { background: var(--danger); border: none; color: var(--on-error); }
#modal-confirm:hover { filter: brightness(1.06); }

/* ============================================================== combos ==== */
/* Searchable suggestion dropdowns attached to [data-combo] inputs. The field
   keeps its normal input styling; we only add wrapper + dropdown chrome. */
.combo-wrap { position: relative; display: block; }

.combo-list {
  position: absolute; top: calc(100% + 5px); left: 0; right: 0; z-index: 90;
  margin: 0; padding: 5px; list-style: none;
  background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 20px 48px rgba(0, 0, 0, .6); max-height: 268px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
}
.combo-list::-webkit-scrollbar { width: 8px; }
.combo-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

.combo-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px;
}
.combo-item:hover { background: var(--accent-soft); }
.combo-item.active { background: var(--primary); color: var(--on-primary); }
.combo-item-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-item-meta {
  flex-shrink: 0; font-family: var(--font-mono); font-size: 10px;
  letter-spacing: .5px; text-transform: uppercase; color: var(--muted-2);
}
.combo-item.active .combo-item-meta { color: var(--on-primary); opacity: .85; }

.combo-item-title { font-weight: 600; }
.combo-item-sub { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.combo-item.active .combo-item-sub { color: var(--on-primary); opacity: .85; }

/* Informational caption rows (e.g. "no teachers for this dept yet") */
.combo-item.combo-note { cursor: default; display: block; padding: 10px 12px; }
.combo-item.combo-note:hover { background: none; }
.combo-note-title { font-size: 12.5px; font-weight: 600; color: var(--text); line-height: 1.4; }
.combo-note-sub { display: block; font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.4; }

.combo-input-clear-wrap { position: relative; }
.combo-input-clear-wrap input { padding-right: 34px; }
.combo-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--panel-3); color: var(--muted); font-size: 14px; line-height: 1;
  padding: 0; display: none;
}
.combo-clear.show { display: block; }
.combo-clear:hover { color: #fff; background: var(--surface-container-highest); }

/* Staff dropdown option groups (designation select) */
optgroup[label] { font-style: normal; color: var(--muted); }

/* ======================================================== responsive ===== */
/* App bar: from 560px there is room for the A4 spec pill. */
@media (min-width: 560px) {
  #app-bar-meta { display: flex; }
}

/* Very narrow phones (320-359px): stack paired fields. */
@media (max-width: 359px) {
  .input-row { flex-direction: column; gap: 13px; }
  #brand-title { font-size: 15px; }
  #form-scroll { padding-left: 12px; padding-right: 12px; }
  #sidebar-header { padding-left: 14px; padding-right: 14px; }
}

/* Split view: needs BOTH width and height, so landscape phones and squat
   windows keep the drawer shell (where the form can scroll) instead of
   squeezing a sidebar into ~200px of leftover height. */
@media (min-width: 768px) and (min-height: 560px) {
  #workspace { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }

  #sidebar {
    position: static;
    transform: none;
    width: auto;
    max-width: none;
    border-right: 1px solid var(--border);
    z-index: 50;
  }
  #close-sidebar-btn { display: none; }
  #mobile-menu-btn { display: none; }
  #sidebar-tabs { position: static; }
  #stage-dock { display: flex; }
  .stage-note { display: inline-flex; }
  #preview-area { padding: 24px; }
  #sidebar-header h1 { font-size: 20px; }
}

/* Sidebar width scales with the viewport instead of stepping between sizes. */
@media (min-width: 768px) and (max-width: 1023px) and (min-height: 560px) {
  :root { --sidebar-w: clamp(320px, 42vw, 372px); }
}
@media (min-width: 1024px) and (min-height: 560px) {
  :root { --sidebar-w: clamp(352px, 28vw, 452px); }
}
@media (min-width: 1600px) and (min-height: 560px) {
  :root { --sidebar-w: 452px; }
  #app-bar { padding-left: 24px; padding-right: 24px; }
  #stage-bar { padding-left: 24px; padding-right: 24px; }
}

/* Landscape phones / kitchen-sink windows: keep the *controls* reachable by
   shrinking the decorative chrome first. */
@media (max-height: 700px) {
  #site-footer { display: none; }
  #sidebar-header { padding-top: max(12px, env(safe-area-inset-top, 0px)); padding-bottom: 12px; }
  #sidebar-header p { display: none; }
  #sidebar-header-meta { margin-bottom: 8px; }
  #sidebar-header h1 { font-size: 18px; }
  #autosave-note { display: none; }
  #sidebar-tabs { margin: 10px 14px; }
  .side-section { margin-bottom: 18px; }
}
@media (max-height: 560px) {
  #sidebar-header-meta { display: none; }
  #sidebar-header p { display: none; }
  #sidebar-header h1 { font-size: 16px; }
  #sidebar-tabs [role="tab"] { min-height: 34px; }
  #footer-actions-row button { min-height: 38px; }
  #btn-pdf { min-height: 46px; font-size: 14px; }

  /* Every pixel here goes straight into the sheet: preview.js sizes it from
     the stage's height, and its floor is 0.18 scale, so a short viewport
     needs the decorative chrome out of the way to fit the page at all. */
  #app-bar { min-height: 52px; padding-top: max(6px, env(safe-area-inset-top, 0px)); padding-bottom: 6px; }
  #stage-bar { display: none; }
  #preview-area { padding: 10px; }
  #mobile-menu-btn { min-height: 42px; padding: 10px 16px; margin: 0 12px max(10px, calc(env(safe-area-inset-bottom, 0px) + 8px)); }
  #stage-dock { margin-bottom: 10px; }
}

/* Tablets in portrait have plenty of width but a tall, narrow stage: give the
   sheet a little more room by tightening the page gutters. */
@media (min-width: 768px) and (max-width: 900px) and (min-height: 900px) {
  #preview-area { padding: 20px; }
}

/* ============================================================== a11y ====== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
