/* CareCanvas — Really Flexible Care Ltd Design System
   Extracted from reallyflexiblecare1.netlify.app and reallyflexiblecare.co.uk
   Accessible typography: Manrope (headings/brand) & Atkinson Hyperlegible (body/UI)
   Colour system: Deep Navy (#12313F), Deep Teal (#176B6A), Warm Cream (#FAF3E7),
   Soft Sage (#E8F1EA), Logo Orange (#F89020) and Accessible Charcoal (#1F2933) */
/* Fully air-gapped typography (zero external CDN dependency) */
:root {
  /* Really Flexible Care Brand Tokens */
  --rfc-deep-navy: #12313F;
  --rfc-deep-teal: #176B6A;
  --rfc-dark-teal: #0E4F4F;
  --rfc-warm-cream: #FAF3E7;
  --rfc-soft-sage: #E8F1EA;
  --rfc-light-mist: #F4F6F7;
  --rfc-charcoal: #1F2933;
  --rfc-text-secondary: #4A5568;
  --rfc-muted-gold: #85681A;
  --rfc-logo-orange: #F89020;
  --rfc-burnt-orange: #B85C16;
  --rfc-error-red: #B42318;
  --rfc-white: #FFFFFF;
  --rfc-border: #D8DFE4;

  /* CareCanvas Interface Palette */
  --cc-primary: var(--rfc-deep-teal);
  --cc-primary-hover: var(--rfc-dark-teal);
  --cc-primary-light: #E0EDEC;
  --cc-secondary: var(--rfc-deep-navy);
  --cc-accent: var(--rfc-logo-orange);
  --cc-bg: #F4F7F5;
  --cc-surface: var(--rfc-white);
  --cc-text: var(--rfc-charcoal);
  --cc-muted: var(--rfc-text-secondary);
  --cc-border: var(--rfc-border);

  /* Legacy variable aliases for studio component compatibility */
  --rfc-orange: var(--rfc-deep-teal);
  --rfc-orange-hover: var(--rfc-dark-teal);
  --rfc-ink: var(--rfc-white);
  --rfc-deep: var(--rfc-deep-teal);
  --rfc-soft: var(--rfc-soft-sage);
  --rfc-pale: var(--rfc-light-mist);
  --rfc-text: var(--rfc-charcoal);
  --rfc-muted: var(--rfc-text-secondary);
  --green: var(--rfc-deep-teal);
  --accent: var(--rfc-logo-orange);
  --muted: var(--rfc-text-secondary);
  --line: var(--rfc-border);

  /* Accessible Typography */
  --font-heading: 'Manrope', system-ui, -apple-system, sans-serif;
  --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, sans-serif;
  --ui-heading: 700 18px/1.4 var(--font-body);
  --ui-label: 600 14px/1.4 var(--font-body);
  --ui-text: 400 14px/1.5 var(--font-body);
  --ui-help: 400 13px/1.5 var(--font-body);

  font-family: var(--font-body);
  color: var(--rfc-text);
  background: var(--cc-bg);
}

body {
  font-family: var(--font-body);
  color: var(--rfc-text);
  background-color: var(--cc-bg);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

h1, h2, h3, h4, h5, h6, .brand, .panel-heading, .modal-head h2, .nav-button {
  font-family: var(--font-heading);
}

button:focus-visible, a:focus-visible {
  outline: 3px solid var(--rfc-burnt-orange) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06) !important;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--rfc-deep-teal) !important;
  border-color: var(--rfc-deep-teal) !important;
}

input[type=checkbox], input[type=radio] {
  accent-color: var(--rfc-deep-teal);
}

::placeholder, input::placeholder, textarea::placeholder {
  color: var(--rfc-text-secondary);
  opacity: 1;
}

/* Polish Browser Surfaces: Scrollbars & Selection */
* {
  scrollbar-color: var(--rfc-border) transparent;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--rfc-border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--rfc-text-secondary);
}

::selection {
  background: var(--rfc-soft-sage);
  color: var(--rfc-deep-navy);
}


/* App Header & Branding — Consolidated 56px Single Header */
.app-header {
  height: 56px !important;
  min-height: 56px !important;
  padding: 0 16px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 12px !important;
  background: var(--rfc-deep-navy) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: var(--rfc-white);
  box-sizing: border-box;
}

.brand {
  color: var(--rfc-white) !important;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand small {
  color: rgba(255, 255, 255, 0.72) !important;
  font-weight: 600;
  letter-spacing: 0.06em;
  font-size: 10px;
}

/* CareCanvas Brand Flourish Heart Icon — Official Really Flexible Care Emblem */
.brand-icon {
  background: transparent !important;
  width: 36px !important;
  height: 36px !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  background-image: url('./rfc_heart.png') !important;
  background-size: contain !important;
  background-repeat: no-repeat !important;
  background-position: center !important;
  border-radius: 0 !important;
  flex-shrink: 0;
}

.brand-icon i {
  display: none !important;
}

.beta {
  background: rgba(248, 144, 32, 0.2) !important;
  color: #FFA726 !important;
  border: 1px solid rgba(248, 144, 32, 0.4) !important;
  font-weight: 700;
  font-size: 11px;
}

.count {
  background: var(--rfc-soft-sage) !important;
  color: var(--rfc-deep-teal) !important;
  font-weight: 700;
}

/* Navigation items in Header */
.nav-button {
  color: rgba(255, 255, 255, 0.8) !important;
  font-weight: 600;
  transition: all 0.2s ease;
}

.nav-button:hover {
  color: var(--rfc-white) !important;
  background: rgba(255, 255, 255, 0.08) !important;
}

.nav-button.active {
  border-bottom: 3px solid var(--rfc-logo-orange) !important;
  color: var(--rfc-white) !important;
  background: rgba(255, 255, 255, 0.06) !important;
}

.help-button {
  color: rgba(255, 255, 255, 0.8) !important;
  border-color: rgba(255, 255, 255, 0.25) !important;
  min-height: 44px !important;
  min-width: 44px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.help-button:hover {
  color: var(--rfc-white) !important;
  border-color: var(--rfc-white) !important;
}

/* Document Bar & Action Controls */
.document-bar {
  background: var(--rfc-white) !important;
  border-bottom: 1px solid var(--rfc-border) !important;
}

.document-title input {
  color: var(--rfc-charcoal) !important;
  font-family: var(--font-heading);
  font-weight: 700;
}

.document-glyph {
  background: var(--rfc-soft-sage) !important;
  color: var(--rfc-deep-teal) !important;
}

.button {
  border-color: var(--rfc-border);
  color: var(--rfc-charcoal);
  font-family: var(--font-body);
  font-weight: 600;
  border-radius: 8px;
}

.button.primary {
  background: var(--rfc-deep-teal) !important;
  border-color: var(--rfc-deep-teal) !important;
  color: var(--rfc-white) !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12) !important;
}

.button.primary span {
  color: var(--rfc-white) !important;
}

.button.primary:hover:not(:disabled) {
  background: var(--rfc-dark-teal) !important;
  border-color: var(--rfc-dark-teal) !important;
  transform: translateY(-1px);
}

.button.danger, .quiet.danger {
  color: var(--rfc-error-red) !important;
}

/* Workspace Canvas & Paper Stage */
.paper-stage {
  background: var(--rfc-warm-cream) !important;
}

/* Panels */
.library-panel, .library-footer, .settings-panel {
  background: var(--rfc-white) !important;
  border-color: var(--rfc-border) !important;
}

.panel-heading {
  color: var(--rfc-deep-navy) !important;
  font-weight: 700;
}

.editor-toolbar {
  background: #FFFFFF !important;
  border-color: var(--rfc-border) !important;
}

.toolbar-divider {
  background: var(--rfc-border) !important;
}

.toolbar-button {
  color: var(--rfc-charcoal) !important;
  font-weight: 600;
}

.toolbar-button:hover, .search-clear {
  color: var(--rfc-deep-teal) !important;
}

.search-box, .category, .symbol-choice, .photo-choice {
  border-color: var(--rfc-border);
}

.search-box:focus-within {
  border-color: var(--rfc-deep-teal) !important;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08) !important;
}

.categories {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 185px;
  overflow-y: auto;
  overflow-x: hidden;
  align-content: flex-start;
  scrollbar-width: thin;
  margin: 12px 0;
  padding: 2px 2px 6px;
  -webkit-overflow-scrolling: touch;
}

.category {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border: 1px solid var(--rfc-border);
  border-radius: 16px;
  background: var(--rfc-white);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--rfc-charcoal);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  line-height: 1.3;
}

.category:hover {
  background: var(--rfc-soft-sage);
  border-color: var(--rfc-deep-teal);
  color: var(--rfc-deep-teal);
}

.category.active {
  background: var(--rfc-deep-teal) !important;
  border-color: var(--rfc-deep-teal) !important;
  color: var(--rfc-white) !important;
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(23, 107, 106, 0.25);
}

.category .cat-icon {
  font-size: 13px;
  line-height: 1;
  display: inline-block;
}

.symbol-choice:hover {
  border-color: var(--rfc-deep-teal) !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
}

.symbol-choice span {
  color: var(--rfc-charcoal);
  font-family: var(--font-body);
}

.panel-intro, .library-hint, .library-footer p, .search-summary, .search-box, 
.canvas-meta, .page-controls, .workspace-note, .settings-section h3, 
.settings-section label, .small, .empty-small, .library-empty, .loading, .fit-note, .blank-hint {
  color: var(--rfc-text-secondary);
}

.local-dot {
  background: var(--rfc-logo-orange);
}

.settings-section input:not([type=checkbox]):not([type=color]), 
.settings-section select, .settings-section textarea, 
.settings-panel input[type=number], .settings-panel input[type=color], .colour-row input {
  border-color: var(--rfc-border);
  color: var(--rfc-charcoal);
}

.add-page-button {
  border-color: var(--rfc-deep-teal) !important;
  background: var(--rfc-soft-sage) !important;
  color: var(--rfc-deep-teal) !important;
}

.selection-bar, .design-toolbar {
  background: var(--rfc-soft-sage) !important;
  border-color: #B5D2CB !important;
  color: var(--rfc-deep-teal) !important;
}

#selectTilesBtn[aria-pressed=true] {
  background: var(--rfc-deep-teal) !important;
  color: var(--rfc-white) !important;
}

.tile-check {
  border-color: var(--rfc-deep-teal);
}

.tile-check.checked {
  background: var(--rfc-deep-teal) !important;
  border-color: var(--rfc-deep-teal) !important;
}

dialog {
  background: var(--rfc-white);
  color: var(--rfc-charcoal);
  border: 0 !important;
  border-radius: 14px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.16), 0 4px 12px rgba(0, 0, 0, 0.06);
}

dialog::backdrop {
  background: rgba(18, 49, 63, 0.6) !important;
  backdrop-filter: blur(2px) !important;
}

.template-card:hover {
  border-color: var(--rfc-deep-teal);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.template-preview {
  background: var(--rfc-light-mist);
}

#toast {
  background: var(--rfc-deep-navy);
  color: var(--rfc-white);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
  bottom: max(24px, env(safe-area-inset-bottom));
}

.comm-board-exit {
  top: max(16px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
}

.activity-option:hover {
  border-color: var(--rfc-deep-teal);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.activity-mark {
  background: var(--rfc-soft-sage);
  color: var(--rfc-deep-teal);
}

.activity-open {
  color: var(--rfc-deep-teal);
}

.save-location-bar {
  background: var(--rfc-soft-sage) !important;
  border-color: #BBD7D0 !important;
  color: var(--rfc-deep-teal) !important;
}

.save-location-bar small {
  color: var(--rfc-text-secondary) !important;
}

.care-section-head h3, .care-account a {
  color: var(--rfc-deep-navy);
}

.care-folder:hover {
  background: var(--rfc-soft-sage);
}

.care-folder-icon {
  color: var(--rfc-deep-teal);
}

/* CareCanvas Account Menu & Avatar ("CC") */
.account-menu-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  border: 2px solid rgba(255, 255, 255, 0.35) !important;
  width: 40px !important;
  height: 40px !important;
  padding: 0;
  background: var(--rfc-logo-orange) !important;
  color: var(--rfc-deep-navy) !important;
  font-family: var(--font-heading) !important;
  font-weight: 800 !important;
  font-size: 13px !important;
  letter-spacing: 0.05em;
  border-radius: 50% !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.avatar:hover {
  transform: scale(1.05);
}

.avatar[aria-expanded=true] {
  box-shadow: 0 0 0 3px rgba(248, 144, 32, 0.5) !important;
}

.account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 12px);
  width: 230px;
  z-index: 110;
  background: var(--rfc-white);
  border: 1px solid var(--rfc-border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
}

.account-menu[hidden] {
  display: none;
}

.account-menu > strong {
  display: block;
  padding: 10px 12px 12px;
  font-size: 12px;
  font-family: var(--font-heading);
  color: var(--rfc-deep-navy);
  border-bottom: 1px solid var(--rfc-border);
  margin-bottom: 6px;
}

.account-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: var(--rfc-white);
  padding: 11px 12px;
  text-align: left;
  color: var(--rfc-charcoal);
  font-size: 13px;
  font-weight: 500;
  min-height: 42px;
}

.account-menu button:hover, .account-menu button:focus-visible {
  background: var(--rfc-soft-sage);
  color: var(--rfc-deep-teal);
}

/* CareCanvas Login Screen Styling — see login.css for dedicated styling */
.login-layout {
  --rfc-card-surface: var(--rfc-white);
}

/* Responsive Mobile & Diverse Device Adaptations */
@media (max-width: 768px) {
  .app-header {
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .app-header nav {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 48px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 2px 4px 6px;
  }

  .app-header nav::-webkit-scrollbar {
    display: none;
  }

  .nav-button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    white-space: nowrap;
    padding: 0 10px;
  }

  .comm-board-mode .cards {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)) !important;
    gap: 12px !important;
  }

  .comm-board-mode .board-card {
    min-height: 120px !important;
    padding: 16px 10px !important;
  }

  .comm-board-mode .board-card .card-image {
    width: 70px !important;
    height: 70px !important;
  }

  .comm-board-mode .board-card .card-label {
    font-size: 18px !important;
  }
}

/* iOS Safari Form Zoom Prevention */
@media (max-width: 730px), (pointer: coarse) {
  .search-box input,
  .settings-section input:not([type=checkbox]):not([type=color]),
  .settings-section select,
  .settings-section textarea,
  .document-title input {
    font-size: 16px !important;
  }
}

/* Touch Pointer Adaptation */
@media (pointer: coarse) {
  .category,
  .source-filter {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
  }

  .toolbar-button {
    min-height: 44px;
    padding: 8px 12px;
    font-size: 12px;
  }

  .symbol-choice {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  button,
  .button,
  .symbol-choice,
  .board-card,
  .nav-button,
  .category,
  .source-filter,
  .template-card {
    -webkit-tap-highlight-color: transparent;
  }

  button:active:not(:disabled),
  .button:active:not(:disabled),
  .symbol-choice:active,
  .board-card:active,
  .nav-button:active,
  .category:active,
  .source-filter:active,
  .template-card:active {
    transform: scale(0.97);
    opacity: 0.92;
  }
}

/* Motion Sensitivity & Vestibular Disorders */
@media (prefers-reduced-motion: reduce) {
  html, body {
    scroll-behavior: auto !important;
  }

  *,
  *::before,
  *::after {
    /* Respect vestibular disorders: disable movement animations and continuous pulsing */
    animation-iteration-count: 1 !important;
    transition-duration: 0.05s !important;
    scroll-behavior: auto !important;
  }

  /* Disable transitions on transforms and large movement */
  *,
  *::before,
  *::after {
    transition-property: background-color, border-color, color, opacity, box-shadow !important;
  }

  /* Disable movement on hover, focus, and animated states */
  .button.primary:hover:not(:disabled),
  .avatar:hover,
  .symbol-choice:hover,
  .template-card:hover,
  .word-token.speech-highlight,
  body.comm-board-mode .board-card:hover,
  body.comm-board-mode .board-card:focus-visible,
  .welcome-pictures > div {
    transform: none !important;
  }

  #toast, #toast.visible {
    transform: translateX(-50%) !important;
  }
}

/* ==========================================================================
   CareCanvas Brand System: Care Home UI Simplification Styling
   ========================================================================== */

/* 1. Body Modes: Simple Mode (Default) & Advanced Mode */
body.mode-simple .document-bar,
body.mode-simple .save-location-bar,
body.mode-simple #designModeBtn,
body.mode-simple #selectTilesBtn,
body.mode-simple #newBtn,
body.mode-simple #selectionBar,
body.mode-simple .source-filters,
body.mode-simple .panel-heading .count,
body.mode-simple #secondaryLanguageSelect,
body.mode-simple label[for="secondaryLanguageSelect"],
body.mode-simple label[for="grammarColourCoding"],
body.mode-simple #advancedAccordion,
body.mode-simple #cardAlternatives,
body.mode-simple .voice-banking-section,
body.mode-simple #symbolRecolorSection,
body.mode-simple .library-footer .field-row {
  display: none !important;
}

body.mode-simple .workspace {
  min-height: calc(100vh - 56px);
}

body.mode-simple .library-panel {
  height: calc(100vh - 56px);
}

/* 2. Inline Document Title & Save Status in App Header */
.header-doc-group,
.header-title-zone,
.app-header .document-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
  max-width: 360px;
}

.header-doc-group input,
.header-title-zone input,
.app-header .document-title input,
.app-header input#documentName {
  background: rgba(255, 255, 255, 0.08) !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--rfc-white) !important;
  font-family: var(--font-heading);
  width: 100%;
  max-width: 220px;
  text-overflow: ellipsis;
  outline: none;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.header-doc-group input:hover,
.header-title-zone input:hover,
.app-header .document-title input:hover,
.app-header input#documentName:hover {
  background: rgba(255, 255, 255, 0.14) !important;
  border-color: rgba(255, 255, 255, 0.35) !important;
}

.header-doc-group input:focus,
.header-title-zone input:focus,
.app-header .document-title input:focus,
.app-header input#documentName:focus {
  background: var(--rfc-white) !important;
  color: var(--rfc-charcoal) !important;
  border-color: var(--rfc-deep-teal) !important;
  outline: 2px solid var(--rfc-deep-teal) !important;
}

.header-doc-group #saveStatus,
.header-title-zone #saveStatus,
.app-header #saveStatus,
.header-save-status {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.75) !important;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0;
}

.header-doc-group #saveStatus::before,
.header-title-zone #saveStatus::before,
.app-header #saveStatus::before,
.header-save-status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80; /* green status dot */
  flex-shrink: 0;
}

.header-doc-group #saveStatus.unsaved::before,
.header-title-zone #saveStatus.unsaved::before,
.app-header #saveStatus.unsaved::before,
.header-save-status.unsaved::before {
  background: var(--rfc-logo-orange, #F89020);
}

.header-doc-group #saveStatus.unsaved,
.header-title-zone #saveStatus.unsaved,
.app-header #saveStatus.unsaved,
.header-save-status.unsaved {
  color: #FFA726 !important;
}

/* 4. Mode Toggle Button (Friendly Pill Toggle) */
.mode-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 20px;
  padding: 5px 12px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--rfc-white);
  cursor: pointer;
  white-space: nowrap;
  min-height: 34px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  user-select: none;
  flex-shrink: 0;
}

body.mode-simple .mode-toggle-btn {
  background: rgba(34, 197, 94, 0.18) !important;
  border: 1.5px solid rgba(34, 197, 94, 0.55) !important;
  color: #FFFFFF !important;
}

body.mode-simple .mode-toggle-btn:hover {
  background: rgba(34, 197, 94, 0.28) !important;
  border-color: rgba(34, 197, 94, 0.8) !important;
  transform: translateY(-1px);
}

body.mode-advanced .mode-toggle-btn {
  background: rgba(56, 189, 248, 0.22) !important;
  border: 1.5px solid rgba(56, 189, 248, 0.65) !important;
  color: #FFFFFF !important;
}

body.mode-advanced .mode-toggle-btn:hover {
  background: rgba(56, 189, 248, 0.32) !important;
  border-color: rgba(56, 189, 248, 0.9) !important;
  transform: translateY(-1px);
}

.mode-toggle-btn:focus-visible {
  outline: 3px solid var(--rfc-burnt-orange) !important;
  outline-offset: 2px !important;
}

.mode-toggle-btn:active {
  transform: translateY(0);
}

.mode-toggle-btn .mode-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  border: 1px solid rgba(255, 255, 255, 0.4);
  flex-shrink: 0;
}

body.mode-advanced .mode-toggle-btn .mode-dot {
  background: #38bdf8;
  border-color: transparent;
}

/* Action Button Cluster in Header */
.header-actions,
.app-header-actions,
.header-action-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.app-header #printBtn,
.app-header .btn-print-primary {
  background: var(--rfc-deep-teal) !important;
  border: 1px solid rgba(255, 255, 255, 0.25) !important;
  color: var(--rfc-white) !important;
  font-weight: 700;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 38px;
  white-space: nowrap;
}

.app-header #printBtn:hover,
.app-header .btn-print-primary:hover {
  background: var(--rfc-dark-teal) !important;
  border-color: rgba(255, 255, 255, 0.45) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.app-header #printBtn span,
.app-header .btn-print-primary span {
  color: #d3e9b3 !important;
}

.app-header .button,
.app-header .header-btn {
  background: rgba(255, 255, 255, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  color: var(--rfc-white) !important;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.app-header .button:hover,
.app-header .header-btn:hover {
  background: rgba(255, 255, 255, 0.2) !important;
  border-color: rgba(255, 255, 255, 0.4) !important;
  color: var(--rfc-white) !important;
}

.app-header .more-btn,
.app-header #moreActionsBtn {
  font-weight: 700;
  letter-spacing: 1px;
}

/* 3. More Actions Menu Dropdown */
.more-actions-wrap,
.more-menu-wrap {
  position: relative;
  display: inline-block;
}

.more-actions-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  background: var(--rfc-white);
  border: 1px solid var(--rfc-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  padding: 8px;
  z-index: 1000;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.more-actions-menu[hidden] {
  display: none !important;
}

.more-actions-menu .menu-item-btn,
.more-actions-menu .menu-item,
.more-actions-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--rfc-charcoal);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  min-height: 38px;
  box-sizing: border-box;
}

.more-actions-menu .menu-item-btn:hover,
.more-actions-menu .menu-item:hover,
.more-actions-menu button:hover {
  background: var(--rfc-soft-sage);
  color: var(--rfc-deep-teal);
}

.more-actions-menu .menu-item-btn:focus-visible,
.more-actions-menu .menu-item:focus-visible,
.more-actions-menu button:focus-visible {
  outline: 2px solid var(--rfc-deep-teal) !important;
  outline-offset: 1px !important;
  background: var(--rfc-soft-sage);
}

.more-actions-menu .menu-divider {
  height: 1px;
  background: var(--rfc-border);
  margin: 4px 0;
}

/* 5. Quick-Start Welcome Hub Empty-State */
#quickStartHub {
  max-width: 620px;
  margin: 32px auto;
  padding: 32px;
  text-align: left;
  background: var(--cc-surface);
  border: 1px solid var(--cc-border);
  border-radius: 8px;
  font-family: var(--font-body);
}

#quickStartHub[hidden] {
  display: none !important;
}

#quickStartHub h2,
#quickStartHub .quick-start-title {
  font-family: var(--font-heading);
  font-size: 28px;
  font-weight: 700;
  color: var(--rfc-deep-navy);
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

#quickStartHub p,
#quickStartHub .quick-start-desc {
  font-size: 14px;
  color: var(--rfc-text-secondary);
  margin: 0 0 24px;
  line-height: 1.5;
}

.quick-start-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 24px;
}

.quick-start-card {
  background: var(--rfc-white);
  border: 0;
  border-top: 1px solid var(--cc-border);
  border-radius: 0;
  padding: 16px 8px;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 16px;
  align-items: center;
  column-gap: 16px;
  row-gap: 3px;
  font-family: inherit;
  color: inherit;
  box-shadow: none;
  min-height: 76px;
}

.quick-start-card:hover,
.quick-start-card:focus-visible {
  transform: none;
  background: var(--rfc-soft-sage);
  box-shadow: none;
}

.quick-start-card:focus-visible {
  outline: 3px solid var(--rfc-burnt-orange) !important;
  outline-offset: 2px !important;
}

.quick-start-card .qs-icon {
  grid-row: 1 / 3;
  width: 28px;
  height: 28px;
  color: var(--rfc-deep-teal);
  margin: 0;
}

.quick-start-card::after {
  content: '';
  grid-column: 3;
  grid-row: 1 / 3;
  width: 7px;
  height: 7px;
  border-top: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
  transform: rotate(45deg);
}

.quick-start-card strong, .quick-start-card small {
  grid-column: 2;
}

.quick-start-card strong {
  font-size: 15px;
  color: var(--rfc-charcoal);
  font-weight: 700;
  font-family: var(--font-heading);
}

.quick-start-card small {
  font-size: 12px;
  color: var(--rfc-text-secondary);
  line-height: 1.4;
}

/* 6. Advanced Accordion Disclosures in Settings Panel */
.advanced-accordion {
  margin-top: 14px;
  border-radius: 8px;
}

.advanced-accordion .accordion-summary,
details.advanced-accordion > summary {
  cursor: pointer;
  padding: 10px 12px;
  background: #f4f7f4;
  border: 1px solid #dce5d6;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12px;
  color: var(--rfc-deep-teal);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.advanced-accordion .accordion-summary::-webkit-details-marker,
details.advanced-accordion > summary::-webkit-details-marker {
  display: none;
}

.advanced-accordion .accordion-summary:hover,
details.advanced-accordion > summary:hover {
  background: var(--rfc-soft-sage);
  border-color: #c2d8c0;
}

.advanced-accordion .accordion-summary:focus-visible,
details.advanced-accordion > summary:focus-visible {
  outline: 2px solid var(--rfc-deep-teal) !important;
  outline-offset: 2px !important;
}

.advanced-accordion .accordion-chevron,
.advanced-accordion .accordion-summary::after,
details.advanced-accordion > summary::after {
  content: "▸";
  margin-left: auto;
  font-size: 12px;
  transition: transform 0.2s ease;
  display: inline-block;
}

.advanced-accordion[open] .accordion-chevron,
details.advanced-accordion[open] > summary::after {
  transform: rotate(90deg);
}

.advanced-accordion .accordion-inner {
  padding: 12px 4px 4px;
}

/* Touch targets ergonomics (>= 44px) */
@media (pointer: coarse) {
  .mode-toggle-btn,
  .more-actions-menu .menu-item-btn,
  .more-actions-menu button,
  .advanced-accordion .accordion-summary,
  details.advanced-accordion > summary,
  .app-header .button,
  .app-header .header-btn,
  .app-header #printBtn {
    min-height: 44px;
  }
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .app-header {
    height: auto !important;
    min-height: 56px !important;
    padding: max(8px, env(safe-area-inset-top)) 12px 8px !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .header-doc-group,
  .header-title-zone,
  .app-header .document-title {
    order: 3;
    max-width: 100%;
    width: 100%;
  }

  .header-actions,
  .app-header-actions {
    margin-left: auto;
  }

  .quick-start-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
  }

  .quick-start-card {
    padding: 16px 12px;
  }
}

/* Preserve comm-board-mode and print invariants */
body.comm-board-mode #quickStartHub,
body.comm-board-mode .mode-toggle-btn,
body.comm-board-mode .more-actions-menu {
  display: none !important;
}

@media print {
  #quickStartHub,
  .mode-toggle-btn,
  .more-actions-menu,
  .advanced-accordion summary {
    display: none !important;
  }
  .advanced-accordion[open] .accordion-inner {
    padding: 0;
  }
}



/* Care staff navigation: retain the established palette and make space for tasks. */
@media screen {
  .app-header { height: auto !important; min-height: 80px; flex-wrap: wrap !important; gap: 12px !important; padding: 16px 24px !important; }
  .app-header > * { min-width: 0; }
  .header-doc-title { flex: 1 1 240px; max-width: 420px; }
  .app-header input#documentName { width: 100% !important; min-width: 0 !important; }
  .app-header nav { order: 10; width: 100% !important; height: auto !important; flex-wrap: wrap; margin: 0 !important; overflow: visible !important; }
  .app-header .button, .mode-toggle-btn, .menu-item-btn { min-height: 44px; }
  body.mode-simple .app-header nav,
  body.mode-simple #standardPageSettings,
  body.mode-simple #standardAppearance,
  body.mode-simple #reuseLayoutSettings,
  body.mode-simple #wordlistsBtn,
  body.mode-simple #resourceLibraryBtn,
  body.mode-simple #cardSkinTone,
  body.mode-simple #cardHairColor,
  body.mode-simple #symbolRecolorSection { display: none !important; }
  body.mode-simple .selected-settings label:has(#cardSkinTone),
  body.mode-simple .selected-settings label:has(#cardHairColor) { display: none; }
  body.mode-simple .settings-panel > .panel-heading { display: none; }
  body.mode-simple .categories { max-height: 110px; overflow-y: auto; padding: 4px; gap: 8px; }
  body.mode-simple .symbol-choice { min-height: 108px; padding: 12px 6px; }
  .more-actions-menu { max-height: min(70dvh, 600px); overflow-y: auto; width: min(320px, calc(100vw - 32px)); }
  #modal { max-height: 88dvh; overflow: hidden; }
  #modalContent { max-height: 85dvh; display: flex; flex-direction: column; }
  .modal-head { position: sticky; top: 0; z-index: 3; flex-shrink: 0; background: var(--surface, #fff); gap: 16px; }
  .modal-head h2 { margin-top: 0; }
  .modal-navigation { display: flex; flex-wrap: wrap; gap: 8px; flex-shrink: 0; }
  .modal-body { overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
  .symbol-placeholder-badge { font-size: 12px !important; line-height: 1.4; white-space: normal; text-align: center; padding: 8px; }
  #paperStage[hidden] { display: none !important; }
  @media (min-width: 1100px) {
    body.mode-simple .workspace { grid-template-columns: 300px minmax(0, 1fr) 250px !important; }
  }
  @media (max-width: 760px) {
    .app-header { position: relative; padding: 12px !important; gap: 8px !important; }
    .more-menu-wrap { position: static !important; }
    .more-actions-menu { left: 12px; right: 12px; width: auto; min-width: 0; }
    .header-doc-title { flex-basis: 100%; max-width: none; order: 1; }
    .modal-head { flex-wrap: wrap; padding: 16px; }
    .modal-navigation { width: 100%; }
    .modal-navigation .button { flex: 1; }
    body.mode-simple .settings-panel { padding: 16px; }
  }
}

@media screen {
 .simple-category { display: none; }
 body.mode-simple .simple-category { display: grid; gap: 8px; margin: 16px 0; font-weight: 600; }
 body.mode-simple .simple-category select { width: 100%; min-height: 44px; padding: 10px; border: 1px solid var(--line, #cbd5e1); border-radius: 8px; background: #fff; font: inherit; }
 body.mode-simple #categories { display: none !important; }
 .symbol-choice { height: auto !important; min-height: 120px; }
 .symbol-choice .symbol-img { width: 64px !important; height: 64px !important; object-fit: contain; flex-shrink: 0; }
 .symbol-choice > span:last-child { max-width: 100%; overflow-wrap: anywhere; }
}

/* Main editing actions and the sentence writer stay clear at every viewport. */
@media screen {
  .editor-toolbar {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center;
    gap: 12px 24px; height: auto; min-height: 0; max-width: 2000px; margin: 0 auto;
    padding: 14px 24px; border-bottom: 1px solid #d8e2dd;
  }
  .editor-toolbar .toolbar-group { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; min-width: 0; }
  .editor-toolbar .editor-history { justify-content: flex-start; flex-wrap: nowrap; }
  .editor-toolbar .editor-view-actions { justify-content: flex-end; }
  .editor-toolbar .toolbar-button {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: 44px; padding: 10px 14px; border: 1px solid #b9cbc3;
    border-radius: 7px; background: #fff; color: #12313f !important; box-shadow: none;
    font: 600 14px/1.3 var(--font-body, system-ui, sans-serif); cursor: pointer;
  }
  .editor-toolbar .toolbar-icon { width: 17px; height: 17px; flex-shrink: 0; }
  .editor-toolbar button:hover:not(:disabled) { background: #edf4f0; border-color: #8da99b; filter: none; }
  .editor-toolbar .toolbar-delete:hover:not(:disabled) { background: #faf1ef; border-color: #b99085; }
  .editor-toolbar button:disabled { opacity: 1; background: #f6f8f7; color: #74837d !important; border-color: #dbe3df; cursor: not-allowed; }
  .editor-toolbar button:focus-visible { outline: 3px solid #176b6a; outline-offset: 3px; }
  .editor-toolbar .page-controls {
    grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
    gap: 14px 24px; margin: 0; padding: 12px 0 0; border: 0; border-top: 1px solid #e3eae6;
    border-radius: 0; background: transparent;
  }
  .editor-toolbar .page-navigation { flex-wrap: nowrap; }
  .editor-toolbar #pageCounter { min-width: 104px; text-align: center; color: #40584e; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
  @media (max-width: 760px) {
    .editor-toolbar { grid-template-columns: auto minmax(0, 1fr); gap: 12px; padding: 12px 16px; }
    .editor-toolbar .editor-view-actions { grid-column: 2; grid-row: 1; }
    .editor-toolbar .editor-create-actions { grid-column: 1 / -1; grid-row: 2; }
  }
  @media (max-width: 480px) {
    .editor-toolbar { padding: 12px; }
    .editor-toolbar .toolbar-button { padding: 10px 11px; font-size: 13px; }
    .editor-toolbar .page-edit-actions { width: 100%; }
    .editor-toolbar .page-edit-actions button { flex: 1 1 calc(50% - 8px); }
  }

  #modal.writer-dialog { width: min(1040px, 96vw); max-height: 92dvh; background: #fff; }
  .writer-dialog #modalContent { max-height: 92dvh; }
  .writer-dialog .modal-head { padding: 20px 24px; }
  .writer-dialog .modal-head p { font-size: 14px; }
  .writer-dialog .modal-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; padding: 24px; }
  .writer-main { min-width: 0; }
  .writer-label { display: block; margin-bottom: 8px; font-size: 16px; font-weight: 700; }
  .writer-dialog #sentenceInput { min-height: 108px; max-height: 180px; padding: 12px 14px; font-size: 17px; line-height: 1.6; border-color: #9eb8b2; }
  .writer-hint { margin: 8px 0 0; color: #405c59; font-size: 13px; line-height: 1.5; }
  .writer-dialog .writer-word-mode { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 12px 0 0; font-size: 15px; font-weight: 600; cursor: pointer; }
  .writer-word-mode input { width: 20px; height: 20px; margin: 0; accent-color: #176b6a; flex-shrink: 0; }
  .writer-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 24px; }
  .writer-dialog h3 { margin: 0; font-size: 17px; line-height: 1.4; }
  .writer-preview-head .speak-sentence-btn { margin: 0; min-height: 44px; padding: 10px 14px; font-size: 14px; }
  .writer-dialog .sentence-preview { align-content: flex-start; min-height: 140px; max-height: 280px; margin-top: 10px; padding: 12px; gap: 10px; border-color: #c1d2cc; background: #f8faf9; }
  .writer-dialog .sentence-preview .writer-token { min-width: 72px; margin: 0; padding: 12px 10px; gap: 8px; border-color: #b4c9c1; }
  .writer-dialog .sentence-preview .card-image { width: 56px; height: 56px; }
  .writer-dialog .sentence-preview .card-label { font-size: 15px; }
  .writer-dialog .writer-selected-word { border-color: #176b6a; background: #e2f0eb; outline: 2px solid #176b6a; outline-offset: 1px; }
  .writer-word-panel { align-self: start; min-width: 0; padding: 18px; border-radius: 9px; background: #edf4f1; }
  .writer-word-panel > h3 { margin-bottom: 12px; }
  .writer-word-chooser { position: static; inset: auto; min-width: 0; max-width: none; padding: 0; border: 0; box-shadow: none; background: transparent; }
  .writer-word-chooser .popover-header span { font-size: 16px; text-transform: none; overflow-wrap: anywhere; }
  .writer-word-chooser .popover-close { padding: 8px 12px; border: 1px solid #9eb8b2; border-radius: 7px; background: #fff; color: #12313f; font: 600 13px/1.3 var(--font-body, system-ui, sans-serif); }
  .writer-word-chooser .disambiguation-actions { flex-wrap: wrap; gap: 8px; padding: 8px 0 14px; }
  .writer-word-chooser .disambiguation-actions .button { flex-basis: 100%; min-height: 44px; padding: 10px 12px; font-size: 14px; }
  .writer-word-chooser .disambiguation-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-height: 260px; padding: 3px; }
  .writer-word-chooser .disambiguation-item { padding: 10px 6px; min-height: 98px; }
  .writer-word-chooser .item-thumb { width: 48px; height: 48px; }
  .writer-word-chooser .item-label, .writer-word-chooser .item-sense, .writer-word-chooser .item-cat { font-size: 12px; }
  .writer-footer { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 24px; border-top: 1px solid #cbdad3; background: #fff; }
  .writer-footer > .writer-hint { margin: 0; max-width: 36ch; }
  .writer-footer .modal-actions { margin: 0; flex-shrink: 0; }
  .writer-footer .button { min-height: 46px; padding: 12px 18px; font-size: 15px; }
  .writer-dialog [hidden] { display: none !important; }

  @media (max-width: 800px) {
    .writer-dialog .modal-body { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 18px; }
    .writer-word-chooser .disambiguation-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); max-height: 220px; }
    .writer-word-chooser .disambiguation-actions .button { flex-basis: auto; }
    .writer-footer { padding: 14px 18px; gap: 12px; }
    .writer-footer > .writer-hint { display: none; }
    .writer-footer .modal-actions { width: 100%; }
    .writer-footer .button { flex: 1; }
  }
  @media (max-width: 480px) {
    .writer-dialog .modal-head { padding: 16px; }
    .writer-preview-head { margin-top: 18px; }
  }
}

@media screen {
 .content-removal-actions { display: grid; gap: 8px; margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid #cbdad3; }
 .content-removal-actions .button { min-height: 44px; justify-content: center; font-size: 14px; }
 .content-removal-actions .small { margin: 0; color: #405c59; line-height: 1.5; }
}

@media screen {
 .comm-board-controls { display: none; }
 body.comm-board-mode .comm-board-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; position: sticky; top: 0; padding: 14px 20px; z-index: 1000; background: #12313f; color: #fff; }
 body.comm-board-mode .comm-board-controls .button { display: inline-flex !important; align-items: center; justify-content: center; min-height: 44px; position: static; margin: 0; border: 1px solid #c7ddd5; box-shadow: none; background: #fff; color: #12313f; }
 body.comm-board-mode .comm-board-controls .comm-board-exit { background: #176b6a; color: #fff; }
 #commBoardStatus { flex: 1 1 220px; font-size: 14px; line-height: 1.5; }
 body.comm-board-mode .design-canvas [data-drag] { display: none; }
}

@media print { .comm-board-controls { display: none !important; } }

/* A stable action group replaces independently wrapping header buttons. */
@media screen {
 .app-header {
  display: grid !important; grid-template-columns: minmax(0, 1fr) 44px;
  grid-template-areas: "brand account" "actions actions" "nav nav";
  align-items: center; gap: 12px !important;
 }
 .app-header > .brand { grid-area: brand; min-width: 0; }
 .app-header > .account-menu-wrap { grid-area: account; justify-self: end; }
 .app-header > nav { grid-area: nav; }
 .legacy-top-bars .document-bar { display: none; }
 .app-header > .header-actions {
  grid-area: actions; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: stretch; gap: 8px; width: 100%; min-width: 0; margin: 0;
 }
 .header-actions > .more-menu-wrap { min-width: 0; }
 .app-header .header-actions > button,
 .app-header .header-actions #moreActionsBtn {
  display: inline-flex !important; align-items: center; justify-content: center;
  width: 100% !important; height: 44px !important; min-height: 44px !important;
  padding: 0 10px !important; border-radius: 8px !important;
  font: var(--ui-label) !important;
  letter-spacing: normal !important; white-space: normal;
  box-shadow: none !important; transform: none !important;
 }
 @media (min-width: 1180px) {
  .app-header {
   grid-template-columns: minmax(230px, 1fr) minmax(690px, 880px) 44px;
   grid-template-areas: "brand actions account" "nav nav nav";
  }
 }
 @media (max-width: 760px) {
  .app-header > .header-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .app-header .brand { font-size: 20px; }
  .app-header .brand small { font-size: 9px; letter-spacing: .04em; }
 }
}

/* Pictures take the space; source and category controls are optional. */
@media screen {
 .library-panel .panel-heading h1, .settings-panel .panel-heading h2 { font: var(--ui-heading); }
 .library-filters > summary, .settings-panel h3,
 .settings-panel label, .library-panel .library-filter-fields label { font: var(--ui-label); letter-spacing: normal; }
 .library-panel input, .library-panel .library-filter-fields select,
 .settings-panel input, .settings-panel select, .settings-panel textarea { font: var(--ui-text); }
 .library-panel .search-box input { font: var(--ui-text) !important; }
 .library-panel .small, .library-panel .library-hint,
 .settings-panel .small, .settings-panel .selection-hint { font: var(--ui-help); }
 .library-panel .library-footer .button, .library-panel .library-filter-fields .button,
 .settings-panel .button { font: var(--ui-label); }
 body.mode-simple #designToolbar, body.mode-simple #designSettings,
 body.mode-simple #menuDesignBtn,
 body.mode-simple label[for="cardSecondaryText"] { display: none !important; }
 .workspace .library-panel {
  display: flex; flex-direction: column; position: sticky; top: 0; align-self: start;
  height: var(--library-panel-height, calc(100dvh - 100px)) !important;
  min-height: 0; padding: 14px 12px 12px; overflow: hidden;
 }
 .library-panel .panel-heading { margin: 0 0 10px; }
 .library-panel .search-box { flex-shrink: 0; margin: 0; }
 .library-filters { margin: 4px 0 8px; font-size: 13px; }
 .library-filters > summary { min-height: 36px; padding: 10px 2px; cursor: pointer; color: #31534d; }
 .library-filters > summary:focus-visible { outline: 3px solid #b85c16; outline-offset: 2px; }
 .library-filter-fields { display: grid; gap: 10px; padding: 4px 0 12px; }
 .library-filter-fields label { display: grid; gap: 5px; margin: 0; }
 .library-filter-fields select { width: 100%; min-height: 40px; padding: 8px; border: 1px solid #cbd5d1; border-radius: 6px; background: #fff; font: inherit; }
 .library-filter-fields .button { min-height: 40px; }
 .library-panel #symbolGrid {
  flex: 1 1 0; min-height: 0; max-height: none; height: auto;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 104px;
  align-content: start; gap: 8px; padding: 2px; overflow-y: auto; overscroll-behavior: contain;
 }
 #symbolGrid .symbol-choice {
  min-width: 0; width: 100%; height: 104px !important; min-height: 104px !important;
  padding: 6px !important; gap: 4px !important; border-radius: 8px;
 }
 #symbolGrid .symbol-choice svg, #symbolGrid .symbol-choice img {
  width: 56px !important; height: 56px !important; max-width: 100%; object-fit: contain; flex-shrink: 0;
 }
 #symbolGrid .symbol-choice > span:last-child {
  font-size: 12px; line-height: 14px; display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere;
 }
 #symbolGrid .library-empty { grid-column: 1 / -1; }
 .library-panel .library-footer { flex-shrink: 0; margin: 0; padding: 10px 0 0; }
 .library-panel .library-footer .button { min-height: 44px; }
 .library-panel .symbol-pagination { flex-shrink: 0; margin: 0; padding: 8px 0 0; }
 .library-panel .symbol-pagination .pagination-btn { min-height: 36px; }
 .library-panel .library-hint[hidden] { display: none; }
 @media (max-width: 768px) {
  .workspace .library-panel { position: static; align-self: stretch; height: min(640px, 85dvh) !important; }
  .library-panel .library-filter-fields select, .library-panel .search-box input { font-size: 16px !important; }
 }
}
/* Saved first-page previews use the same paper renderer as the editor. */
.document-preview{display:inline-flex;align-items:center;justify-content:center;width:132px;height:178px;max-width:100%;flex:none;overflow:hidden;border:1px solid #ccd9dc;border-radius:5px;background:#edf3f2;color:var(--rfc-text-secondary);vertical-align:middle;box-sizing:border-box}
.document-preview-landscape{width:152px;height:112px}
.document-preview-viewport{display:flex;align-items:center;justify-content:center;width:100%;height:100%;overflow:hidden}
.document-preview .paper{position:relative!important;inset:auto!important;flex:none;margin:0!important;box-shadow:none!important;transform:none!important;pointer-events:none;text-align:initial}
.document-preview-message{display:block;padding:12px;font-size:11px;line-height:1.5;text-align:center;font-weight:400}
.doc-row.document-row-preview{display:grid;grid-template-columns:148px minmax(0,1fr);align-items:start;gap:10px 18px;padding:16px}
.document-row-preview>.document-preview{grid-row:1 / span 2;align-self:center;justify-self:start}
.document-row-preview>.doc-row-copy{min-width:0;align-self:end;overflow-wrap:anywhere}
.document-row-preview>.doc-row-actions,.document-row-preview>button{grid-column:2;justify-self:start;align-self:start}
.document-row-preview>.doc-row-actions{display:flex;flex-wrap:wrap;justify-content:flex-start;gap:7px}
.care-folder:has(.document-preview){display:grid;grid-template-columns:114px minmax(0,1fr) auto;align-items:center;gap:14px;text-align:left}
.care-folder .document-preview{width:104px;height:140px}
.care-folder .document-preview-landscape{height:88px}
.saved-work-gallery{display:grid;grid-template-columns:repeat(auto-fit,minmax(155px,1fr));gap:12px;margin:8px 0 14px}
.saved-work-gallery:empty{display:none}
.saved-document-choice{display:flex;flex-direction:column;align-items:center;gap:8px;min-width:0;margin:0;padding:12px;border:1px solid #cbd9dd;border-radius:8px;background:#fff;color:var(--rfc-deep-navy);text-align:center}
button.saved-document-choice{cursor:pointer;min-height:44px}
button.saved-document-choice:hover{background:#f1f7f5;border-color:var(--rfc-deep-teal)}
button.saved-document-choice.selected{border:2px solid var(--rfc-deep-teal);padding:11px;background:#edf7f4}
.saved-document-choice strong{font-size:13px;line-height:1.4;overflow-wrap:anywhere}
.saved-document-choice small{font-size:11px;line-height:1.5;color:var(--rfc-text-secondary)}
.copy-current-preview{display:flex;align-items:center;gap:18px;margin:4px 0 16px}
.copy-current-preview p{line-height:1.7;margin:0}
.saved-preview-heading{font-size:15px;margin:8px 0 4px}
.version-preview-pair{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin:14px 0}
.version-preview-pair>div{display:flex;flex-direction:column;align-items:center;gap:10px}
@media(max-width:600px){.doc-row.document-row-preview{grid-template-columns:106px minmax(0,1fr);gap:10px 12px;padding:12px}.document-row-preview>.document-preview{width:100px;height:138px}.document-row-preview>.document-preview-landscape{height:80px}.document-row-preview>.doc-row-actions .button{font-size:11px;padding:9px 10px}.saved-work-gallery{grid-template-columns:repeat(2,minmax(0,1fr))}.saved-document-choice{padding:8px}.saved-document-choice .document-preview{width:100px;height:138px}.care-folder:has(.document-preview){grid-template-columns:94px minmax(0,1fr) auto;gap:10px}.care-folder .document-preview{width:90px;height:122px}.version-preview-pair{gap:10px}}

/* Save controls stay beside previews, within the desktop dialog viewport. */
.app-header #saveBtn{background:var(--rfc-deep-teal)!important;color:#fff!important;border:1px solid rgba(255,255,255,.35)!important;font-weight:700!important}
#modal:has(#saveCopyForm){width:min(1080px,calc(100vw - 32px));max-width:none;max-height:94dvh}
#modal:has(#saveCopyForm) #modalContent{max-height:94dvh}
#modal:has(#saveCopyForm) .modal-body{padding:20px 24px}
#saveCopyForm .removal-note{margin:0 0 16px;padding:10px 14px}
.save-copy-layout{display:grid;grid-template-columns:minmax(0,1fr) 360px;gap:28px;align-items:start}
.save-copy-options{background:var(--rfc-soft,#edf4f1);border-radius:10px;padding:20px;min-width:0}
.save-copy-options h3{margin:0 0 14px;font-size:17px}
.save-copy-options label{display:block;margin:0 0 12px;font-size:12px}
.save-copy-options input,.save-copy-options select{width:100%;margin-top:5px;min-height:44px}
.save-copy-options .preview-note{margin:8px 0 14px;line-height:1.5}
.save-copy-actions{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.save-copy-actions #confirmSaveCopy{grid-column:1/-1;min-height:44px}
.save-copy-actions #manageCopyFolders{grid-column:1/-1;font-size:12px}
.save-copy-actions #cancelSaveCopy{grid-column:1/-1}
.save-copy-previews{min-width:0}
.save-copy-previews .copy-current-preview{margin:0 0 12px}
.save-copy-previews .saved-preview-heading{margin:12px 0 10px}
.save-copy-previews .saved-work-gallery{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.save-copy-previews .document-preview{width:98px;height:132px}
.save-copy-previews .document-preview-landscape{width:132px;height:98px}
.save-copy-previews .saved-document-choice{padding:10px;gap:6px}
.save-copy-previews .saved-document-choice .document-preview{width:76px;height:102px}
.save-copy-previews .saved-document-choice .document-preview-landscape{width:102px;height:76px}
.save-copy-previews .saved-document-choice strong{font-size:13px;overflow-wrap:anywhere}
.preview-pagination{display:flex;justify-content:space-between;align-items:center;gap:8px;margin-top:12px;font-size:12px}
.preview-pagination[hidden]{display:none}
.preview-pagination .button{min-height:40px;padding:8px 12px}
@media(max-width:760px){
 #modal:has(#saveCopyForm) .modal-body{padding:12px}
 .save-copy-layout{grid-template-columns:1fr;gap:18px}
 .save-copy-options{grid-row:1;padding:14px}
 .save-copy-options h3{display:none}
 .save-copy-options label{margin-bottom:8px}
 .save-copy-actions #cancelSaveCopy{grid-column:2;grid-row:1}
 .save-copy-actions #confirmSaveCopy{grid-column:1;grid-row:1}
}

/* One dialog system: content at left, contextual actions at right. */
@media screen {
 .app-header>.header-actions{grid-template-columns:repeat(7,minmax(0,1fr))}
 #modal.unified-dialog,.audit-modal.unified-dialog{width:min(1120px,calc(100vw - 32px));max-width:none;max-height:94dvh}
 .unified-dialog #modalContent,.unified-dialog #auditModalContent{max-height:94dvh;display:flex;flex-direction:column}
 .unified-dialog .modal-head{padding:20px 24px}
 .unified-dialog .modal-body{padding:22px 24px}
 .dialog-split{display:grid;grid-template-columns:minmax(0,1fr) 280px;align-items:start;gap:24px;min-width:0}
 .dialog-main{min-width:0}
 .dialog-actions{position:sticky;top:0;min-width:0;padding:18px;background:#edf4f1;border-radius:10px;display:flex;flex-direction:column;gap:14px}
 .dialog-actions .modal-actions,.dialog-actions .resource-tools,.dialog-actions .care-actions,.dialog-actions .materials-actions{display:flex;flex-direction:column;gap:10px;margin:0;padding:0;border:0;align-items:stretch}
 .dialog-actions .button{width:100%;white-space:normal;min-height:44px;text-align:center;justify-content:center}
 .dialog-actions>.button[hidden]{display:none}
 .dialog-actions .modal-actions .primary{order:-1}
 .dialog-actions label{display:block;margin:0;font-size:13px}
 .dialog-actions select,.dialog-actions input:not([type=checkbox]){width:100%;min-height:44px;margin-top:6px}
 .dialog-actions .care-toolbar{display:flex;flex-direction:column;align-items:stretch;gap:14px;margin:0;padding:0;border:0}
 .dialog-actions .care-toolbar label{max-width:none}
 .dialog-actions .care-buttons{display:grid;gap:8px}
 .dialog-actions .care-account{margin:0;padding-top:16px;flex-direction:column;align-items:start}
 .directory-layout>.dialog-actions{max-height:calc(94dvh - 145px);overflow:auto}
 .directory-layout .care-folders{grid-template-columns:1fr}
 .directory-layout .doc-row.document-row-preview{grid-template-columns:110px minmax(0,1fr) 155px;gap:14px}
 .directory-layout .doc-row-actions{grid-column:3;grid-row:1;display:flex;flex-direction:column;align-items:stretch}
 .directory-layout .document-preview{width:100px;height:135px}
 .directory-layout .document-preview-landscape{height:80px}
 .open-file-layout{grid-template-columns:minmax(0,1fr) 340px}
 .open-file-layout .dialog-main{max-height:calc(94dvh - 210px);overflow:auto}
 .open-file-layout .saved-work-gallery:empty::before{content:'Choose a folder on the right to preview its files.';font-size:14px;color:#405c59;grid-column:1/-1;padding:24px 0}
 .writer-word-panel .writer-footer{display:flex;flex-direction:column;padding:16px 0 0;margin-top:20px;border-top:1px solid #c4d8d0;background:transparent;gap:16px;align-items:stretch}
 .writer-word-panel .writer-footer .modal-actions{display:flex;flex-direction:column;gap:10px}
 .writer-word-panel .writer-footer .button{width:100%;min-height:44px}
 .writer-word-panel .writer-footer .primary{order:-1}
 .help-layout{grid-template-columns:minmax(0,1fr) 260px}
 .help-layout .help-nav{grid-column:2;grid-row:1}
 .help-layout .help-reading{grid-column:1;grid-row:1}
 @media(min-width:1180px){.app-header{grid-template-columns:minmax(190px,1fr) minmax(760px,1000px) 44px}}
 @media(max-width:760px){
  .app-header>.header-actions{grid-template-columns:repeat(2,minmax(0,1fr))}
  .app-header #modeToggleBtn{grid-column:1/-1}
  .dialog-split,.open-file-layout{grid-template-columns:1fr;gap:16px}
  .unified-dialog .modal-body{padding:14px}
  .dialog-actions{position:static;padding:14px}
  .directory-layout>.dialog-actions{max-height:none;grid-row:1}
  .open-file-layout>.dialog-actions{grid-row:1}
  .directory-layout .doc-row.document-row-preview{grid-template-columns:90px minmax(0,1fr)}
  .directory-layout .doc-row-actions{grid-column:1/-1;grid-row:auto;flex-direction:row}
  .directory-layout .document-preview{width:84px;height:114px}
  .help-layout{display:flex;flex-direction:column}
 }
}

@media screen {
 .directory-layout{grid-template-columns:minmax(0,1fr) 320px}
 .directory-layout>.dialog-main{max-height:calc(94dvh - 150px);overflow:auto;padding-right:6px}
 .directory-layout .care-buttons,.directory-layout .dialog-actions .care-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
 .directory-layout .care-actions:has(>#residentMaterials){grid-template-columns:1fr}
 .directory-layout .dialog-actions{gap:12px}
 .directory-layout .dialog-actions .button{padding:8px;font-size:12px}
 .directory-home-options summary{cursor:pointer;font-weight:600;font-size:13px;padding:10px 0}
 .directory-home-options[open] summary{margin-bottom:8px}
 .directory-layout .care-account{padding-top:10px;gap:6px}
 .open-file-layout .dialog-actions{gap:10px}
 .open-file-layout .dialog-actions label{margin:0!important;gap:4px}
 .open-file-layout .dialog-actions select{margin:4px 0 0!important}
 .open-file-layout .dialog-actions .preview-note{margin:2px 0!important}
 .open-file-layout .dialog-actions .modal-actions{margin:0!important;gap:8px}
 @media(max-width:760px){.directory-layout{grid-template-columns:1fr}.directory-layout>.dialog-main{max-height:none;overflow:visible}.directory-layout .dialog-actions .care-actions{grid-template-columns:1fr 1fr}}
}

.dialog-main>.activity-builder{display:block}
.writer-dialog .writer-word-panel{max-height:calc(94dvh - 155px);overflow:auto;position:sticky;top:0}
.writer-word-panel .writer-footer{position:sticky;bottom:-18px;background:#edf4f1;padding-bottom:10px}
.dialog-actions>.activity-fields{padding:0;border:0;background:transparent}

.dialog-actions:has(>.activity-fields){max-height:calc(94dvh - 150px);overflow:hidden}
.dialog-actions>.activity-fields{min-height:0;overflow:auto;flex:1;padding-right:4px}
.dialog-actions>.modal-actions{flex-shrink:0}
.writer-dialog .writer-word-panel{display:flex;flex-direction:column;overflow:hidden}
.writer-word-panel>#writerWordEditor{min-height:0;overflow:auto;flex:1}
.writer-word-panel>.writer-footer{position:static;flex-shrink:0}

/* Screen controls use the brand palette without moving or distracting effects. */
@media screen {
 :root { color-scheme: light; }
 .app-header > .header-actions { grid-template-columns: repeat(7, minmax(0, 1fr)); }
 .app-header .header-actions > button, .app-header .header-actions #moreActionsBtn { font-size: 13px !important; }
 body.mode-simple .mode-toggle-btn, body.mode-advanced .mode-toggle-btn {
  background: #244550 !important; border: 1px solid #78929c !important; color: #fff !important;
 }
 body.mode-simple .mode-toggle-btn:hover, body.mode-advanced .mode-toggle-btn:hover { background: #355c66 !important; transform: none; }
 .button.primary:hover:not(:disabled), .app-header #printBtn:hover { transform: none; }
 .app-header :is(button, a):focus-visible { outline-color: #f89020 !important; box-shadow: none !important; }
 .editor-panel:focus { outline: 3px solid var(--rfc-deep-teal); outline-offset: -3px; }
 .editor-panel:has(#quickStartHub:not([hidden])) #blankHint { display: none; }
 .settings-panel h3 { text-transform: none; }
 .read-icon { width: 16px; height: 16px; flex-shrink: 0; }
 .speak-sentence-btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
 @media (min-width: 1180px) {
  .app-header { grid-template-columns: auto minmax(0, 1fr) 44px; }
  .app-header > .header-actions { grid-template-columns: repeat(7, max-content); justify-content: end; }
  .app-header .header-actions > button, .app-header .header-actions #moreActionsBtn { padding-inline: 14px !important; white-space: nowrap; }
 }
 @media (max-width: 760px) {
  .settings-panel button, .library-panel button, .settings-panel summary { min-height: 44px; }
  .settings-panel input:not([type=checkbox]):not([type=color]), .settings-panel textarea, .settings-panel select { font-size: 16px !important; }
 }
 @media (min-width: 761px) and (max-height: 600px) {
  .library-panel { position: static; height: auto !important; min-height: 500px !important; }
  .library-panel #symbolGrid { flex: 0 0 auto; height: 320px; min-height: 320px; }
 }
 @media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  button, a { transform: none !important; }
 }
}
