/* ============================================================
   ALO CLIENT CHAT v2.5
   Design: Teal-blue thinking partner (calm + focus palette)
   Updated: Feb 23, 2026 — Color palette overhaul + dark mode
   Changes: New teal-blue color system, dark mode via data-theme,
            theme toggle persistence, warm accent (clay), 
            WCAG AA contrast compliance, nighttime-optimized dark mode
   ============================================================ */

/* === LIGHT MODE (default) === */
:root {
  color-scheme: light;
  --warm-bg: #F3EDE4;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --text-primary: #1D3539;
  --text-secondary: #4A5C5E;
  --text-muted: #566A6F;
  --border-subtle: rgba(58, 124, 134, 0.10);
  --border-visible: rgba(58, 124, 134, 0.22);
  --border-color: rgba(58, 124, 134, 0.22);
  
  /* Primary brand — teal-blue */
  --primary: #3A7C86;
  --primary-light: #E0EDEB;
  --primary-hover: #2D6B74;
  --primary-dark: #264038;
  --primary-glow: rgba(58, 124, 134, 0.12);
  
  /* Warm accent — clay terracotta */
  --accent: #C7865F;
  --accent-hover: #B57550;
  --accent-light: rgba(199, 134, 95, 0.10);
  
  /* Legacy aliases (components still reference these) */
  --sage: var(--primary);
  --sage-light: var(--primary-light);
  --sage-hover: var(--primary-hover);
  --sage-dark: var(--primary-dark);
  --white: var(--surface);
  
  --danger: #C45A4D;
  --danger-bg: #FEF2F0;
  --success: #5C9E7A;
  --success-bg: rgba(92, 158, 122, 0.08);
  
  /* Header */
  --header-bg: linear-gradient(180deg, rgba(224, 237, 235, 0.4) 0%, rgba(243, 237, 228, 0.98) 100%);
  --header-border-top: var(--primary);
  --footer-bg: rgba(243, 237, 228, 0.98);
  
  /* Modal */
  --modal-overlay: rgba(29, 53, 57, 0.45);
  --modal-shadow: rgba(29, 53, 57, 0.12);
  
  /* Focus ring */
  --focus-ring: var(--primary);
  --focus-glow: rgba(58, 124, 134, 0.12);
  
  /* Chat iframe bg */
  --chat-bg: #FFFFFF;
  
  /* Toast */
  --toast-bg: var(--text-primary);
  --toast-success: var(--primary-dark);
  
  /* Loading spinner */
  --spinner-track: rgba(58, 124, 134, 0.12);
  --spinner-head: var(--primary);
}

/* === DARK MODE === */
[data-theme="dark"] {
  color-scheme: dark;
  --warm-bg: #111917;
  --surface: #1A2420;
  --surface-raised: #1E2A27;
  --text-primary: #E0DBD3;
  --text-secondary: #A8B5B3;
  --text-muted: #7A8A88;
  --border-subtle: rgba(82, 153, 165, 0.10);
  --border-visible: rgba(82, 153, 165, 0.18);
  --border-color: rgba(82, 153, 165, 0.18);
  
  --primary: #5299A5;
  --primary-light: #1E2A27;
  --primary-hover: #6AADB8;
  --primary-dark: #1A2420;
  --primary-glow: rgba(82, 153, 165, 0.15);
  
  --accent: #D19A6E;
  --accent-hover: #DBA97E;
  --accent-light: rgba(209, 154, 110, 0.10);
  
  --sage: var(--primary);
  --sage-light: var(--primary-light);
  --sage-hover: var(--primary-hover);
  --sage-dark: var(--primary-dark);
  --white: var(--surface);
  
  --danger: #E07066;
  --danger-bg: rgba(224, 112, 102, 0.12);
  --success: #6FB88A;
  --success-bg: rgba(111, 184, 138, 0.10);
  
  --header-bg: linear-gradient(180deg, rgba(26, 36, 32, 1) 0%, rgba(17, 25, 23, 0.98) 100%);
  --header-border-top: var(--primary);
  --footer-bg: rgba(17, 25, 23, 0.98);
  
  --modal-overlay: rgba(0, 0, 0, 0.55);
  --modal-shadow: rgba(0, 0, 0, 0.3);
  
  --focus-ring: var(--primary);
  --focus-glow: rgba(82, 153, 165, 0.2);
  
  --chat-bg: #111917;
  
  --toast-bg: var(--surface-raised);
  --toast-success: var(--primary);
  
  --spinner-track: rgba(82, 153, 165, 0.15);
  --spinner-head: var(--primary);
}

/* === AUTO DARK (respects system preference when no explicit toggle) === */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --warm-bg: #111917;
    --surface: #1A2420;
    --surface-raised: #1E2A27;
    --text-primary: #E0DBD3;
    --text-secondary: #A8B5B3;
    --text-muted: #7A8A88;
    --border-subtle: rgba(82, 153, 165, 0.10);
    --border-visible: rgba(82, 153, 165, 0.18);
    --border-color: rgba(82, 153, 165, 0.18);
    
    --primary: #5299A5;
    --primary-light: #1E2A27;
    --primary-hover: #6AADB8;
    --primary-dark: #1A2420;
    --primary-glow: rgba(82, 153, 165, 0.15);
    
    --accent: #D19A6E;
    --accent-hover: #DBA97E;
    --accent-light: rgba(209, 154, 110, 0.10);
    
    --sage: var(--primary);
    --sage-light: var(--primary-light);
    --sage-hover: var(--primary-hover);
    --sage-dark: var(--primary-dark);
    --white: var(--surface);
    
    --danger: #E07066;
    --danger-bg: rgba(224, 112, 102, 0.12);
    --success: #6FB88A;
    --success-bg: rgba(111, 184, 138, 0.10);
    
    --header-bg: linear-gradient(180deg, rgba(26, 36, 32, 1) 0%, rgba(17, 25, 23, 0.98) 100%);
    --header-border-top: var(--primary);
    --footer-bg: rgba(17, 25, 23, 0.98);
    
    --modal-overlay: rgba(0, 0, 0, 0.55);
    --modal-shadow: rgba(0, 0, 0, 0.3);
    
    --focus-ring: var(--primary);
    --focus-glow: rgba(82, 153, 165, 0.2);
    
    --chat-bg: #111917;
    
    --toast-bg: var(--surface-raised);
    --toast-success: var(--primary);
    
    --spinner-track: rgba(82, 153, 165, 0.15);
    --spinner-head: var(--primary);
  }
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { overflow-x: clip; }
@supports not (overflow-x: clip) {
  html, body { overflow-x: hidden; }
}

html { height: 100dvh; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', system-ui, sans-serif;
  background: var(--warm-bg);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

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

/* === HEADER === */
header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  background: var(--header-bg);
  border-top: 3px solid var(--header-border-top);
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(58, 124, 134, 0.3);
}

.brand-text {
  overflow: visible;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.2;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

/* === THEME TOGGLE === */
.theme-toggle {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  box-shadow: none;
}

.theme-toggle:hover {
  background: var(--primary-light);
  color: var(--text-primary);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

/* Show/hide sun/moon icons based on theme */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }

[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* Auto dark via media query */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* === MORE MENU BUTTON === */
.guest-auth-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.guest-auth-actions.hidden { display: none; }

.btn-link {
  background: none;
  border: none;
  color: var(--primary-dark);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.btn-link:hover { color: var(--primary); }

.more-btn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--primary-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

[data-theme="dark"] .more-btn {
  color: var(--primary);
}

.more-btn:hover { background: var(--primary-light); }

/* === MORE MENU PANEL === */
.more-menu {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
}

.more-menu.hidden { display: none; }

.more-menu-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--modal-overlay);
}

.more-menu-panel {
  position: absolute;
  top: 60px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 8px 24px var(--modal-shadow);
  min-width: 200px;
  padding: 6px 0;
  animation: menuFadeIn 0.12s ease-out;
}

@keyframes menuFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.more-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: transparent;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  min-height: 44px;
  border-radius: 0;
  box-shadow: none;
}

.more-menu-item:hover { background: var(--primary-light); }

.more-menu-item svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

.more-menu-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 12px;
}

.more-menu-logout {
  color: var(--danger);
}

.more-menu-logout svg {
  color: var(--danger);
}

/* === TRUST BADGE === */
.connected-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.connected-actions.hidden { display: none; }

.trust-badge {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.trust-badge.connected {
  display: inline-flex;
  background: var(--primary-light);
  color: var(--primary);
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

[data-theme="dark"] .trust-badge.connected {
  color: var(--text-secondary);
}

.trust-badge svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

/* === PRIVACY ASSURANCE BAR === */
.privacy-bar {
  flex-shrink: 0;
  background: var(--primary-light);
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 20px;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--primary);
}

[data-theme="dark"] .privacy-bar {
  color: var(--text-secondary);
}

.privacy-bar svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.privacy-bar-text {
  line-height: 1.3;
}

.privacy-bar-dismiss {
  background: transparent;
  border: none;
  padding: 4px;
  min-height: 28px;
  min-width: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 16px;
  cursor: pointer;
  opacity: 0.6;
  flex-shrink: 0;
  box-shadow: none;
}

[data-theme="dark"] .privacy-bar-dismiss {
  color: var(--text-secondary);
}

.privacy-bar-dismiss:hover {
  opacity: 1;
  background: transparent;
}

/* === BUTTONS === */
button {
  border: 1px solid var(--border-subtle);
  background: transparent;
  padding: 8px 14px;
  min-height: 44px;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: none;
}

button:hover { background: var(--primary-light); color: var(--text-primary); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: 600;
}

.btn-primary:hover { 
  background: var(--primary-hover);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border-visible);
  color: var(--text-primary);
}

.btn-secondary:hover { background: var(--primary-light); border-color: var(--primary); }

.btn-link {
  background: transparent;
  border: none;
  color: var(--primary);
  padding: 4px 8px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  text-decoration: underline;
  box-shadow: none;
  font-size: 13px;
}

.btn-danger-outline {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* === MAIN LAYOUT === */
main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* === HOMEWORK CARDS === */
.homework-container {
  flex-shrink: 0;
  padding: 8px 20px;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  background: var(--warm-bg);
  border-bottom: 1px solid var(--border-subtle);
  display: none;
}

.homework-container.show { 
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.homework-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--primary);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 1px 3px var(--modal-shadow);
  transition: opacity 0.3s ease, border-left-color 0.3s ease;
}

.homework-from {
  font-size: 0.6875rem;
  color: var(--primary);
  font-weight: 500;
  margin-bottom: 2px;
}

.homework-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.homework-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  margin: 0;
}

.homework-type-tag {
  display: inline-block;
  font-size: 0.6875rem;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 500;
  margin-bottom: 6px;
}

.homework-goal {
  margin: 0;
}

.homework-collapse {
  background: transparent;
  border: none;
  padding: 8px;
  min-height: 44px;
  min-width: 44px;
  box-shadow: none;
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.homework-body {
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-primary);
  margin-top: 8px;
}

.homework-body.collapsed { display: none; }

.homework-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

@media (min-width: 480px) {
  .homework-actions {
    flex-direction: row;
  }
}

.homework-actions .btn-primary {
  font-size: 13px;
  padding: 10px 16px;
}

.homework-actions .btn-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* === CHAT IFRAME === */
.chat-container {
  flex: 1;
  min-height: 0;
  position: relative;
}

.chat-container #aloFrame {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--chat-bg);
}

/* Botpress JS SDK — fill chat-container, hide floating bubble
   Botpress appends iframes to <body>, not inside #aloFrame,
   so selectors must be global. We position the webchat iframe
   to cover .chat-container using fixed positioning calculated
   by JS (see initBotpressLayout). */
.bpFab, .bpFabWrapper, .bpMessagePreview { display: none !important; }
/* bpWebchat positioning handled by JS overlay (positionWebchat) */

.bpHeaderCloseButton,
.bpCloseButton {
  display: none !important;
}

/* === LOADING === */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--warm-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.loading-message { text-align: center; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--spinner-track);
  border-top-color: var(--spinner-head);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: transparent;
    border-right-color: var(--primary);
  }
}

.error-message {
  text-align: center;
  padding: 20px;
}

.error-message button { margin-top: 16px; }

/* === FOOTER === */
footer {
  flex-shrink: 0;
  padding: 12px 20px;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  font-size: 0.6875rem;
  color: var(--text-muted);
  background: var(--footer-bg);
  border-top: 1px solid var(--border-subtle);
  text-align: center;
  position: relative;
  z-index: 10;
}

footer a {
  color: var(--text-primary);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}

.crisis-notice {
  margin-bottom: 4px;
}

.crisis-link {
  font-weight: 600;
}

.footer-links {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 4px;
}

/* === MODALS === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--modal-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.2s ease;
}

.modal-overlay.show { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 8px 24px var(--modal-shadow);
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
  position: relative;
  outline: none;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  padding-right: 32px;
}

.modal-body p {
  margin: 12px 0;
  line-height: 1.6;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.modal-body ol,
.modal-body ul {
  margin: 16px 0;
  padding-left: 24px;
}

.modal-body li {
  margin: 8px 0;
  line-height: 1.5;
}

.modal-body h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.modal-footer {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-footer button {
  flex: 1;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  padding: 8px;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  box-shadow: none;
}

.modal-close:hover {
  color: var(--text-primary);
  background: var(--primary-glow);
}

/* === MODAL FORM ELEMENTS === */
.modal-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-visible);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  background: var(--warm-bg);
  color: var(--text-primary);
}

.modal-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-glow);
}

.modal-textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--border-visible);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  background: var(--warm-bg);
  color: var(--text-primary);
}

.modal-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-glow);
}

.modal-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.modal-subtext {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.modal-section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.modal-list {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 20px;
  padding-left: 20px;
}

.modal-divider {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
}

.modal-sign-in-link {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 16px;
  text-align: center;
}

.modal-sign-in-link button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  text-decoration: underline;
  padding: 0;
  min-height: auto;
}

/* === TOAST NOTIFICATIONS === */
.toast-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  z-index: 20000;
}

.toast {
  margin-bottom: max(24px, env(safe-area-inset-bottom));
  background: var(--toast-bg);
  color: var(--warm-bg);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(20px);
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 4px 16px var(--modal-shadow);
}

[data-theme="dark"] .toast {
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success {
  background: var(--toast-success);
}

/* === FORMS === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-visible);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  background: var(--warm-bg);
  color: var(--text-primary);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-glow);
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.error-text {
  color: var(--danger);
  font-size: 0.875rem;
  margin: 12px 0;
  padding: 8px 12px;
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: 6px;
  display: none;
}

.error-text.show { display: block; }

.privacy-note {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  background: var(--primary-light);
  padding: 12px;
  border-radius: 8px;
  border-left: 3px solid var(--primary);
  margin: 16px 0;
}

.button-group {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.button-group button { flex: 1; }

/* === COPY BOX === */
.copy-box {
  background: var(--warm-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px;
  margin: 16px 0;
}

.copy-box textarea {
  width: 100%;
  min-height: 80px;
  border: 1px solid var(--border-visible);
  border-radius: 6px;
  padding: 8px;
  font-family: inherit;
  font-size: 16px;
  resize: vertical;
  margin-bottom: 8px;
  background: var(--surface);
  color: var(--text-primary);
}

.copy-box button { width: 100%; }

/* === MESSAGE ITEMS === */
.message-item {
  background: var(--warm-bg);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.message-text {
  font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-delete {
  flex-shrink: 0;
  padding: 4px 8px;
  font-size: 0.75rem;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === SHARE OPTIONS === */
.share-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 20px 0;
}

.share-option {
  padding: 16px 12px;
  flex-direction: column;
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--border-visible);
  border-radius: 8px;
  cursor: pointer;
}

.share-option.active {
  background: var(--primary-light);
  border-color: var(--primary);
}

.share-option-icon { font-size: 24px; }
.share-option-label { font-size: 13px; font-weight: 600; }

/* === SHARE PROMPT BOX === */
.share-prompt-box {
  background: var(--warm-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px;
  margin-top: 12px;
}

.share-prompt-textarea {
  width: 100%;
  min-height: 80px;
  font-size: 13px;
  background: transparent;
  border: none;
  resize: none;
  font-family: inherit;
  color: var(--text-primary);
}

.share-instructions {
  font-size: 14px;
  margin: 12px 0 8px 0;
  color: var(--text-secondary);
}

.share-steps {
  font-size: 14px;
  line-height: 1.5;
  margin: 12px 0;
  padding-left: 20px;
}

.share-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.share-footer-note {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

/* === RANGE INPUTS === */
/* === HOMEWORK STATES === */
.homework-card.completed {
  border-left-color: var(--success);
  background: var(--success-bg);
}

.homework-card.completed .homework-from {
  color: var(--success);
}

.homework-card.completed .homework-title::before {
  content: '\2713 ';
  color: var(--success);
}

.homework-card.completed .homework-title {
  color: var(--text-secondary);
}

.homework-complete-note {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-style: italic;
}

.homework-card.minimized {
  padding: 10px 16px;
}

.homework-card.minimized .homework-from {
  display: none;
}

.homework-card.minimized .homework-header {
  margin-bottom: 0;
}

/* === HIDDEN UTILITY === */
.hidden { display: none !important; }

/* === FOCUS & ACCESSIBILITY === */
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

/* === PHONE === */
@media (max-width: 640px) {
  header {
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  
  .brand-name { font-size: 15px; }
  .brand-text span { font-size: 11px; }
  .brand-icon { width: 30px; height: 30px; font-size: 14px; border-radius: 6px; }
  
  button {
    padding: 8px 12px;
    font-size: 0.75rem;
  }
  
  .privacy-bar {
    padding: 6px 16px;
    font-size: 0.75rem;
  }
  
  footer {
    font-size: 0.625rem;
    padding: 10px 16px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  /* More menu becomes bottom sheet on phone */
  .more-menu-panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    border-radius: 16px 16px 0 0;
    min-width: 100%;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    animation: sheetSlideUp 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .more-menu-panel::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border-visible);
    border-radius: 2px;
    margin: 8px auto 4px;
  }

  /* Bottom sheet modals on phone */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-content {
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 85vh;
    animation: sheetSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .modal-content::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border-visible);
    border-radius: 2px;
    margin: 0 auto 12px;
  }
}

@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@media (max-width: 400px) {
  .brand-text span { display: none; }
  .trust-badge.connected { font-size: 10px; max-width: 160px; }
}

.editable-name {
  border-bottom: 1.5px dotted currentColor;
  cursor: pointer;
  padding-bottom: 1px;
}

.editable-name:hover {
  opacity: 0.8;
}

.editable-name:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 2px;
}
