/* Memo - Talking Braille Organiser & Digital Notetaker */

:root, .theme-paige {
  --bg: #f4f6fc;
  --panel-bg: #ffffff;
  --ink: #171d1c;
  --muted: #5c6462;
  --line: #dbe0ea;
  --accent: #1d65b8;
  --accent-hover: #175398;
  --accent-text: #ffffff;
  --active-tab: #1d65b8;
  --led-off: #a8b0c0;
  --led-on: #10b981;
  --card-bg: #ffffff;
  --shadow: 0 4px 16px rgba(0,0,0,0.06);
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.theme-amber {
  --bg: #0c0a06;
  --panel-bg: #1a150d;
  --ink: #ffb703;
  --muted: #c78d00;
  --line: #3d3014;
  --accent: #fb8500;
  --accent-hover: #ffb703;
  --accent-text: #000000;
  --active-tab: #fb8500;
  --led-off: #473a1c;
  --led-on: #ffb703;
  --card-bg: #141009;
  --shadow: 0 4px 20px rgba(251,133,0,0.15);
}

.theme-contrast {
  --bg: #000000;
  --panel-bg: #0a0a0a;
  --ink: #ffff00;
  --muted: #d0d000;
  --line: #ffff00;
  --accent: #ffff00;
  --accent-hover: #ffffff;
  --accent-text: #000000;
  --active-tab: #ffff00;
  --led-off: #444400;
  --led-on: #ffff00;
  --card-bg: #111111;
  --shadow: none;
}

:root {
  --ui-scale: 1.0;
}

/* Aliases: the app panes use these names in inline styles. */
:root, .theme-paige, .theme-amber, .theme-contrast {
  --text: var(--ink);
  --subtext: var(--muted);
  --text-dim: var(--muted);
  --sub: var(--muted);
  --danger: #dc2626;
}

html {
  font-size: calc(16px * var(--ui-scale, 1.0));
  max-width: 100vw;
  overflow-x: hidden;
}

html.scale-normal, body.scale-normal { --ui-scale: 1.0; }
html.scale-large, body.scale-large { --ui-scale: 1.35; }
html.scale-xlarge, body.scale-xlarge { --ui-scale: 1.75; }
html.scale-jumbo, body.scale-jumbo { --ui-scale: 2.2; }

/* Enhanced Focus Accessibility */
:focus-visible {
  outline: 3px solid var(--accent) !important;
  outline-offset: 3px !important;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  max-width: 100vw;
  overflow-x: hidden;
}

header {
  background: var(--panel-bg);
  border-bottom: none;
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  max-width: 100vw;
}

.logo-group { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.app-title { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.braille-sub { font-family: 'APH Braille Shadows', monospace; font-size: 1.15rem; letter-spacing: 0.1em; opacity: 0.85; }

.header-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.talking-indicator { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.led { width: 10px; height: 10px; border-radius: 50%; background: var(--led-off); transition: all 0.2s ease; }
.led.active { background: var(--led-on); box-shadow: 0 0 10px var(--led-on); }

.app-tabs-nav {
  background: var(--panel-bg);
  border-bottom: 1px solid var(--line);
  padding: 6px 12px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab-btn {
  background: none;
  border: 1px solid transparent;
  padding: 6px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.tab-btn:hover { color: var(--ink); background: rgba(0,0,0,0.04); }
.tab-btn.active { background: var(--accent); color: var(--accent-text); }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  width: 100%;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
}

#appViewContainer {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.app-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* Music Player Styles */
.music-player-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.track-title { font-size: 1.4rem; font-weight: 700; color: var(--accent); }
.track-artist { color: var(--muted); font-size: 0.95rem; }

.visualizer-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 32px;
}

.vbar {
  width: 5px;
  height: 8px;
  background: var(--accent);
  border-radius: 3px;
  transition: height 0.2s ease;
}

.visualizer-bars.active .vbar:nth-child(1) { animation: vpulse 0.6s infinite ease-in-out alternate; }
.visualizer-bars.active .vbar:nth-child(2) { animation: vpulse 0.4s infinite ease-in-out 0.1s alternate; }
.visualizer-bars.active .vbar:nth-child(3) { animation: vpulse 0.8s infinite ease-in-out 0.2s alternate; }
.visualizer-bars.active .vbar:nth-child(4) { animation: vpulse 0.5s infinite ease-in-out 0.15s alternate; }
.visualizer-bars.active .vbar:nth-child(5) { animation: vpulse 0.7s infinite ease-in-out 0.3s alternate; }

@keyframes vpulse {
  0% { height: 6px; }
  100% { height: 28px; }
}

.scrub-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.track-scrubber {
  width: 100%;
  height: 8px;
  accent-color: var(--accent);
  cursor: pointer;
}

.time-readout {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.player-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.player-secondary-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.playlist-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
}

.playlist-item.active-track {
  border-color: var(--accent);
  background: rgba(42,125,225,0.06);
}

.track-num { font-weight: 700; color: var(--muted); width: 24px; }
.track-meta { flex: 1; }
.track-meta h4 { font-size: 1rem; }
.track-dur { font-weight: 600; color: var(--muted); font-size: 0.85rem; }

/* Camera Viewports (Colour / Scanner) */
.camera-viewport-card { display: flex; flex-direction: column; align-items: center; gap: 12px; overflow: hidden; }
.video-wrapper { position: relative; width: 100%; max-width: 440px; height: 280px; background: #000; border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.video-wrapper video { width: 100%; height: 100%; object-fit: cover; }
.crosshair-target { position: absolute; font-size: 2.5rem; color: #fff; text-shadow: 0 0 4px #000; pointer-events: none; }
.scanner-laser { position: absolute; left: 10%; right: 10%; height: 2px; background: #ef4444; box-shadow: 0 0 8px #ef4444; animation: laserScan 2s infinite ease-in-out; }
@keyframes laserScan { 0% { top: 15%; } 50% { top: 85%; } 100% { top: 15%; } }

.colour-swatch-bar { display: flex; align-items: center; gap: 16px; width: 100%; max-width: 440px; padding: 12px; background: var(--panel-bg); border: 1px solid var(--line); border-radius: 12px; }
.swatch-box { width: 54px; height: 54px; border-radius: 12px; border: 2px solid var(--line); }

/* Light Detector Meter */
.meter-bar-container { width: 100%; height: 32px; background: rgba(0,0,0,0.06); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; margin: 16px 0; }
.meter-fill { height: 100%; background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444); transition: width 0.1s ease-out; }
.level-digits { font-size: 2.5rem; font-weight: 700; text-align: center; color: var(--accent); }

/* D-Pad Remote */
.dpad-container { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 20px auto; }
.dpad-row { display: flex; gap: 8px; }
.dpad-btn { width: 64px; height: 64px; font-size: 1.2rem; font-weight: 700; border-radius: 16px; }
.dpad-btn.select { background: var(--accent); color: var(--accent-text); }
.media-controls-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }

/* Editor Panes */
.editor-panes { display: flex; gap: 14px; flex: 1; min-height: 320px; }
@media (max-width: 768px) { .editor-panes { flex-direction: column; } }

.editor-subpane { flex: 1; background: var(--panel-bg); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.text-editor { flex: 1; border: none; outline: none; padding: 12px; font: inherit; font-size: 1.35rem; line-height: 1.7; background: transparent; color: var(--ink); resize: none; caret-color: var(--accent); cursor: text; }
.theme-contrast .text-editor { caret-color: #ffff00; }
.theme-amber .text-editor { caret-color: #ffb703; }
.braille-viewer { flex: 1; padding: 12px; font-family: 'APH Braille Shadows', monospace; font-size: 1.5rem; line-height: 1.6; white-space: pre-wrap; word-break: break-all; overflow-y: auto; }

/* Virtual Perkins Touch Keyboard */
.perkins-keyboard-container { background: var(--panel-bg); border-top: 1px solid var(--line); padding: 10px 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.perkins-keys-row { display: flex; justify-content: center; align-items: center; gap: 8px; width: 100%; max-width: 600px; }
.p-dot-btn { width: 48px; height: 64px; border-radius: 24px; border: 2px solid var(--line); background: var(--card-bg); color: var(--ink); font-weight: 700; font-size: 1.1rem; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.p-dot-btn:active { background: var(--accent); color: var(--accent-text); transform: scale(0.95); }
.p-space-btn { flex: 1; height: 48px; max-width: 260px; border-radius: 12px; border: 2px solid var(--line); background: var(--card-bg); color: var(--ink); font-weight: 600; font-size: 0.9rem; cursor: pointer; }
.p-space-btn:active { background: var(--accent); color: var(--accent-text); }

/* Common Buttons & Cards */
.btn { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card-bg); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; transition: all 0.15s ease; }
.btn-large { padding: 12px 24px; font-size: 1.1rem; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-secondary { background: var(--card-bg); border-color: var(--line); }
.btn-accent { background: #047857; color: #ffffff; border-color: #047857; }
.btn-accent:hover { background: #065f46; }
.btn-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.card { background: var(--card-bg); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; background: rgba(0,0,0,0.06); }

.modal-dialog { margin: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--panel-bg); color: var(--ink); padding: 24px; max-width: 500px; width: 90%; box-shadow: 0 20px 40px rgba(0,0,0,0.2); }
.modal-dialog::backdrop { background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* Meds and Unit Converter styles */
.meds-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 12px; margin-top: 10px; }
.med-card { display: flex; flex-direction: column; gap: 8px; }
.med-card.med-taken { opacity: 0.75; border-color: #10b981; }
.med-time { font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.badge-success { background: #047857; color: #fff; }
.badge-pending { background: #92400e; color: #fff; }
.med-actions { display: flex; gap: 8px; margin-top: 6px; }

.unit-convert-row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.unit-num-input { width: 100px; padding: 10px; font-size: 1.2rem; border-radius: 8px; border: 1px solid var(--line); background: var(--card-bg); color: var(--ink); }
.unit-equals { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.unit-result-text { font-size: 1.5rem; font-weight: 700; color: var(--accent); min-width: 60px; text-align: center; }
.calc-subnav { display: flex; gap: 8px; margin-bottom: 12px; }

/* Location Awareness and Senior Mode styles */
.header-simple-actions { display: flex; gap: 8px; align-items: center; }
.loc-hero-card { display: flex; flex-direction: column; gap: 12px; }
.loc-readout-box { background: rgba(42,125,225,0.06); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 12px 0; }
.loc-street { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.loc-town { font-size: 1.1rem; color: var(--ink); margin-top: 4px; }
.loc-heading { font-size: 0.95rem; font-weight: 600; color: var(--muted); margin-top: 4px; }
.location-actions-grid { display: flex; flex-wrap: wrap; gap: 10px; }

/* Senior Simple Mode Overrides */
body.mode-senior { font-size: 1.1rem; }
body.mode-senior .btn { padding: 12px 18px; font-size: 1.05rem; }
body.mode-senior .text-editor { font-size: 1.3rem; }
body.mode-senior .p-dot-btn { width: 56px; height: 74px; font-size: 1.25rem; }

/* Junior Mode Overrides */
body.mode-junior { font-size: 1.05rem; }
body.mode-junior .p-dot-btn { background: #e0f2fe; border-color: #38bdf8; }
body.mode-junior .tab-btn.active { background: #ec4899; color: #fff; }

/* Stepper Bar for Simple / Senior Navigation */
.stepper-bar-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
}

.stepper-btn {
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: 12px;
}

.stepper-btn.prev, .stepper-btn.next {
  min-width: 90px;
  padding: 10px 16px;
}

.stepper-btn.active {
  flex: 1;
  max-width: 320px;
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* OCR Scan & Read styles */
.ocr-camera-card { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.ocr-viewport-wrapper { position: relative; width: 100%; max-width: 500px; height: 320px; background: #000; border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.ocr-viewport-wrapper video { width: 100%; height: 100%; object-fit: cover; }
.ocr-document-guide { position: absolute; inset: 20px; border: 2px dashed rgba(255,255,255,0.6); border-radius: 8px; pointer-events: none; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 10px; }
.guide-text { background: rgba(0,0,0,0.7); color: #fff; padding: 4px 10px; border-radius: 6px; font-size: 0.85rem; }
.ocr-actions-row { display: flex; gap: 12px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }
.ocr-result-card { margin-top: 14px; }
.ocr-status-msg { font-weight: 600; color: var(--accent); margin: 6px 0; }
.doc-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Email & Messaging App Styles */
.email-subnav-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.email-items-grid { display: flex; flex-direction: column; gap: 8px; }
.email-card { cursor: pointer; padding: 12px 16px; border-left: 4px solid transparent; transition: transform 0.1s, border-color 0.2s; }
.email-card:hover, .email-card:focus { transform: translateY(-1px); border-left-color: var(--accent); outline: 2px solid var(--accent); }
.email-card.unread { border-left-color: #2a7de1; background: rgba(42, 125, 225, 0.05); font-weight: 500; }
.email-card-header { display: flex; justify-content: space-between; font-size: 0.95rem; margin-bottom: 4px; color: var(--subtext); }
.email-subject { font-size: 1.15rem; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.email-snippet { font-size: 0.95rem; color: var(--subtext); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-detail-card { padding: 16px; }
.email-compose-card { padding: 16px; }

/* Live Talking Chat & WhatsApp Bridge Styles */
.chat-header-card { padding: 14px 18px; }
.chat-contact-info { display: flex; align-items: center; gap: 12px; }
.chat-status-pill { font-size: 0.85rem; font-weight: 600; padding: 4px 10px; border-radius: 20px; }
.chat-status-pill.online { background: #e8f8ee; color: #1e7e34; }
.chat-status-pill.offline { background: #fff3cd; color: #856404; }
.chat-contacts-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; overflow-x: auto; padding-bottom: 4px; }
.chat-messages-stream { max-height: 380px; min-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px 6px; background: rgba(0,0,0,0.02); border-radius: 10px; }
.chat-bubble { max-width: 80%; padding: 10px 14px; border-radius: 12px; font-size: 1.05rem; line-height: 1.4; outline: none; }
.chat-bubble:focus { outline: 3px solid var(--accent); }
.chat-bubble.incoming { align-self: flex-start; background: var(--card-bg, #fff); border: 2px solid var(--line); border-bottom-left-radius: 2px; }
.chat-bubble.outgoing { align-self: flex-end; background: var(--accent, #2a7de1); color: var(--accent-text); border-bottom-right-radius: 2px; }
.chat-bubble-sender { font-size: 0.85rem; margin-bottom: 3px; opacity: 0.85; display: flex; justify-content: space-between; gap: 8px; }
.chat-quick-replies-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.btn-quick-reply { font-size: 0.9rem; padding: 6px 10px; }

/* Uncluttered Calm UI Styles */
body.mode-senior .app-tabs-nav,
body.mode-junior .app-tabs-nav {
  display: none !important; /* Only show Stepper Bar */
}

.stepper-bar-container {
  margin: 10px 0 16px 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.stepper-btn.active {
  font-size: 1.35rem;
  font-weight: 800;
  padding: 14px 28px;
  min-width: 260px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.stepper-btn.prev, .stepper-btn.next {
  font-size: 1.1rem;
  padding: 14px 20px;
  border-radius: 12px;
}

.editor-main-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  border-radius: 14px;
}

.perkins-keyboard-container {
  padding: 8px 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}

/* Integrated Header Stepper Styles */
header {
  padding: 8px 16px;
  gap: 12px;
}

.header-stepper {
  margin: 0 !important;
  background: transparent !important;
  border: none !important;
  border-bottom: none !important;
  padding: 0 !important;
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-stepper .stepper-btn.active {
  font-size: 1.15rem;
  font-weight: 800;
  padding: 8px 18px;
  min-width: 0;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.header-stepper .stepper-btn.prev,
.header-stepper .stepper-btn.next {
  font-size: 0.95rem;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 10px;
}

body.mode-senior .header-stepper .stepper-btn.active {
  font-size: 1.25rem;
  padding: 10px 22px;
  min-width: 0;
}

body.scale-large .header-stepper,
body.scale-xlarge .header-stepper,
body.scale-jumbo .header-stepper {
  order: 3;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 6px 0 !important;
}

body.scale-large .header-stepper .stepper-btn.active,
body.scale-xlarge .header-stepper .stepper-btn.active,
body.scale-jumbo .header-stepper .stepper-btn.active {
  width: 100%;
  order: 1;
  text-align: center;
}

body.scale-large .header-stepper .stepper-btn.prev,
body.scale-xlarge .header-stepper .stepper-btn.prev,
body.scale-jumbo .header-stepper .stepper-btn.prev {
  order: 2;
  flex: 1;
  text-align: center;
}

body.scale-large .header-stepper .stepper-btn.next,
body.scale-xlarge .header-stepper .stepper-btn.next,
body.scale-jumbo .header-stepper .stepper-btn.next {
  order: 3;
  flex: 1;
  text-align: center;
}

/* Fluid Touch Targets for Magnified Modes */
body.scale-large .btn,
body.scale-xlarge .btn,
body.scale-jumbo .btn {
  min-height: 44px;
  font-weight: 700;
}

body.scale-jumbo .btn {
  min-height: 52px;
  border-width: 2px;
}

/* Responsive wrap & reflow for cards and panes in scaled modes */
body.scale-large main, body.scale-xlarge main, body.scale-jumbo main {
  padding: 8px 10px;
  max-width: 100%;
}

/* Fluid single column reflow for small screens or high zoom */
@media (max-width: 768px) {
  header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }
  .header-stepper {
    order: 3;
    width: 100%;
    justify-content: center;
    margin: 4px 0 !important;
  }
  .header-stepper .stepper-btn.active {
    flex: 1;
    min-width: 0 !important;
    text-align: center;
  }
  .header-status {
    gap: 6px;
    flex-wrap: wrap;
  }
  .modal-dialog {
    width: 96vw !important;
    max-width: 96vw !important;
    padding: 14px !important;
  }
}

/* High zoom modal & checklist reflow adjustments */
body.scale-large .modal-dialog, body.scale-xlarge .modal-dialog, body.scale-jumbo .modal-dialog {
  max-width: 98vw !important;
  width: 98vw !important;
  max-height: 95vh;
  padding: 16px;
}
body.scale-large #settingsAppsChecklist, body.scale-xlarge #settingsAppsChecklist, body.scale-jumbo #settingsAppsChecklist {
  grid-template-columns: 1fr !important;
}

/* Shared pane furniture used by every app but previously undefined */
.sub { color: var(--muted); font-size: 0.92rem; }
.field { margin: 8px 0; }
.field label { display: block; font-weight: 600; }
.field input[type="text"], .field input[type="email"], .field input[type="tel"], .field input[type="url"],
.field input[type="time"], .field input[type="date"], .field input[type="number"], .field select, .field textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card-bg); color: var(--ink); font: inherit; margin-top: 4px;
}
.pane-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: space-between; }
.pane-toolbar h3, .pane-toolbar h4 { margin: 0; }
.tool-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn-small { padding: 6px 10px; font-size: 0.9rem; }
.btn-icon { padding: 4px 10px; background: transparent; border-color: transparent; }
.btn-icon:hover { border-color: var(--line); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.empty-state { padding: 20px; text-align: center; color: var(--muted); }
.search-input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card-bg); color: var(--ink); font: inherit; }
.calc-input, .note-title-input { color: var(--ink); }
.loc-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.upload-btn { display: inline-flex; align-items: center; cursor: pointer; }
.upload-btn input[hidden] { display: none; }
.guide-corner { display: none; }
.contacts-grid, .planner-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 12px; margin-top: 10px; }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.notes-text { color: var(--muted); }
.event-card { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.event-details { flex: 1 1 10rem; min-width: 0; overflow-wrap: anywhere; }
.event-time { font-weight: 700; color: var(--accent); white-space: nowrap; }

/* Linear web reader */
.web-toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.web-url-input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card-bg); color: var(--ink); font: inherit; }
.web-navigation-help { color: var(--muted); font-size: 0.9rem; }
.web-content-container { flex: 1; min-height: 0; }
.web-article-view { background: var(--card-bg); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; max-height: 60vh; overflow-y: auto; line-height: 1.6; }
.web-article-view h1, .web-article-view h2, .web-article-view h3 { margin: 14px 0 6px; color: var(--accent); }
.web-article-view p, .linear-list-item, .linear-link { margin: 6px 0; }
.web-article-view [data-idx]:focus { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.linear-link a { color: var(--accent); }
.web-error { color: var(--danger); font-weight: 600; }

/* Playing state for radio and playlists */
.playlist-item.playing { border-color: var(--accent); background: rgba(42,125,225,0.06); }

/* Flex items otherwise retain the title input/select's intrinsic width, which
   clips the editor's controls on a phone or at 220% magnification. */
.app-pane, .card, .editor-main-card, .editor-main-card .action-group {
  min-width: 0;
  max-width: 100%;
}
.editor-main-card > div:first-child > div:first-child {
  min-width: 0 !important;
  max-width: 100%;
  flex-wrap: wrap;
}
.editor-main-card #noteTitle {
  min-width: 0;
  max-width: 100%;
  flex: 1 1 10rem !important;
}
.editor-main-card #noteFolderSelect {
  min-width: 0;
  max-width: 100%;
}
.editor-main-card .btn, .editor-main-card input, .editor-main-card select {
  max-width: 100%;
}
.editor-main-card .btn, .modal-dialog {
  overflow-wrap: anywhere;
}

/* Commands and spelling use native modal dialogs, the shared theme and root
   magnification. Wrapping controls stay inside a phone's visible viewport. */
.command-menu-dialog, .spell-review-dialog {
  width: min(94vw, 42rem);
  max-width: min(94vw, 42rem);
  max-height: 90vh;
  max-height: 90dvh;
  overflow: auto;
}
.command-menu-dialog .dialog-body, .spell-review-dialog .dialog-body {
  min-width: 0;
  max-width: 100%;
}
#commandMenuHint, #spellReviewStatus {
  color: var(--muted);
  margin-block: .5rem .75rem;
}
#commandMenuItems {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  min-width: 0;
  padding: 4px;
}
.command-menu-item {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}
.command-menu-item[aria-disabled="true"] {
  color: var(--muted);
  border-style: dashed;
  cursor: not-allowed;
  opacity: 1;
}
.command-menu-shortcut {
  display: block;
  color: var(--muted);
  font-size: .9em;
  font-weight: 400;
}
.spell-review-word {
  color: var(--accent);
  font-size: 1.35rem;
  font-weight: 700;
  overflow-wrap: anywhere;
  margin-block: .75rem;
}
.spell-review-context {
  border-inline-start: 3px solid var(--accent);
  padding: .5rem .75rem;
  margin-block: .75rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.spell-review-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .4rem;
  min-width: 0;
}
.spell-review-controls label { font-weight: 600; }
.spell-review-controls input, .spell-review-controls select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: .5rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--ink);
  font: inherit;
}
.spell-review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-block-start: 1rem;
}
.spell-review-actions .btn {
  flex: 1 1 9rem;
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}
.editor-main-card [readonly] { cursor: default; }
#btnReadingMode[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
#editorModeStatus { color: var(--muted); }

/* Local book searches wrap with the reader; the original BRF page keeps its
   cell spacing inside an independently scrollable, labelled preview. */
#bookSearchForm, #bookLibrarySearchForm {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: .5rem;
  min-width: 0;
  max-width: 100%;
  margin-block: .5rem .75rem;
}
#bookSearchForm label, #bookLibrarySearchForm label { font-weight: 600; }
#bookSearchQuery, #bookLibrarySearch {
  flex: 1 1 14rem;
  min-width: 0;
  max-width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--ink);
  font: inherit;
}
#bookSearchStatus, #bookPageStatus { color: var(--muted); }
#bookSearchResults {
  max-width: 100%;
  min-width: 0;
  padding-inline-start: 1.5rem;
  overflow-wrap: anywhere;
}
.book-search-result {
  max-width: 100%;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  margin-block: .4rem;
}
.book-search-result .btn { max-width: 100%; text-align: start; white-space: normal; }
#bookBrailleDisplay {
  display: block;
  min-width: 0;
  max-width: 100%;
  max-height: 20rem;
  overflow: auto;
  white-space: pre;
  font-family: 'APH Braille Shadows', monospace;
  line-height: 1.6;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--ink);
}
#brfImportDialog {
  width: min(94vw, 36rem);
  max-width: min(94vw, 36rem);
  max-height: 90vh;
  max-height: 90dvh;
  overflow: auto;
}
#brfImportDialog .dialog-body { min-width: 0; max-width: 100%; }
#brfImportGrade {
  display: block;
  max-width: 100%;
  width: 100%;
  min-width: 0;
  margin-block: .5rem .75rem;
  padding: .5rem;
  background: var(--card-bg);
  color: var(--ink);
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
}
#brfImportDialog .dialog-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
#brfImportDialog .btn { max-width: 100%; white-space: normal; }
.books-pane .talking-book-controls { flex-wrap: wrap; }
.books-pane .btn, .books-pane select { max-width: 100%; white-space: normal; }

#bookSearchHit {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: .15em;
  scroll-margin-block: 1.5rem;
}

/* All essential actions reflow at 220% on a phone. Keep spatial BRF previews
   scrollable, but never put buttons in an off-screen horizontal carousel. */
.btn, main .tab-btn {
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}
body.scale-large .header-stepper .stepper-btn.active,
body.scale-xlarge .header-stepper .stepper-btn.active,
body.scale-jumbo .header-stepper .stepper-btn.active {
  flex: 1 0 100%;
  max-width: 100%;
}
.pane-toolbar > *, .player-header > *, .chat-contact-info > *,
.books-pane .calc-subnav > *, .reading-player-card > div > div,
.music-pane .calc-subnav > *, .station-meta, .track-meta {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.player-header, .player-controls, .player-speed-row,
.chat-contact-info, .chat-composer-row, .dialog-actions, .med-actions,
.music-pane .calc-subnav, .music-pane .calc-subnav > div,
.reading-player-card > div > div, #bookShelfList,
.books-pane .talking-book-controls, .playlist-item, .now-playing-radio-card {
  flex-wrap: wrap;
}
.chat-composer-row input { min-width: 0; max-width: 100%; flex-basis: 10rem !important; }
.chat-bubble { overflow-wrap: anywhere; }
.scratchpad-pane textarea { width: 100%; min-width: 0; max-width: 100%; }
.books-pane .vr-controls-bar > div { min-width: 0; max-width: 100%; flex-wrap: wrap; }
.books-pane .reading-player-card > div { max-width: 100%; min-width: 0; }
.theme-contrast, .theme-amber { --danger: #ff8383; }

/* Flex:1's zero basis otherwise squeezes the dose action to a single letter
   per line when its two neighbours fit. Give the action a readable row. */
.med-item .btn-take-med { flex: 1 1 9rem !important; }
.med-item > div:first-child > div:first-child { flex-wrap: wrap; gap: 8px; }
.med-item h4, .med-item .badge { max-width: 100%; overflow-wrap: anywhere; }
.books-pane select {
  font: inherit;
  min-width: 0;
  max-width: 100%;
  color: var(--ink);
  background: var(--card-bg);
}
