/* Tap AAC Design System & Stylesheet */
:root {
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg-app: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-surface-elevated: #F1F5F9;
  --text-main: #0F172A;
  --text-muted: #64748B;
  --border-color: #E2E8F0;
  --primary: #0284C7;
  --primary-hover: #0369A1;
  --primary-active: #075985;
  --accent-green: #16A34A;
  --accent-red: #DC2626;
  --accent-yellow: #D97706;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg-app: #0F172A;
  --bg-surface: #1E293B;
  --bg-surface-elevated: #334155;
  --text-main: #F8FAFC;
  --text-muted: #94A3B8;
  --border-color: #334155;
  --primary: #38BDF8;
  --primary-hover: #0EA5E9;
  --primary-active: #0284C7;
}

[data-theme="high-contrast"] {
  --bg-app: #000000;
  --bg-surface: #111111;
  --bg-surface-elevated: #222222;
  --text-main: #FFFFFF;
  --text-muted: #E2E8F0;
  --border-color: #FFFFFF;
  --primary: #FACC15;
  --primary-hover: #EAB308;
  --primary-active: #CA8A04;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* TOP APP BAR */
.top-app-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 56px;
  flex-shrink: 0;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-logo {
  font-size: 1.5rem;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.board-picker-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.select-control {
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface-elevated);
  color: var(--text-main);
  cursor: pointer;
}

.app-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* BUTTONS */
.btn {
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--bg-surface-elevated);
}

.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
}

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

.btn-danger {
  background: var(--accent-red);
  color: #FFFFFF;
  border-color: var(--accent-red);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.8rem;
}

/* QUICKFIRES BAR (INSTANT SPEECH) */
.quickfires-bar {
  background: var(--bg-surface-elevated);
  border-bottom: 2px solid var(--border-color);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
  flex-shrink: 0;
  scrollbar-width: none;
}

.quickfires-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-right: 4px;
}

.qf-btn {
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(0,0,0,0.15);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, filter 0.1s ease;
  color: #0F172A;
}

.qf-btn:active {
  transform: scale(0.95);
  filter: brightness(0.9);
}

/* SENTENCE BAR */
.sentence-bar-wrapper {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  flex-shrink: 0;
}

.sentence-display {
  flex: 1;
  background: var(--bg-app);
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.sentence-placeholder {
  color: var(--text-muted);
  font-size: 0.95rem;
  font-style: italic;
}

.sentence-tile {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  animation: popIn 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.sentence-tile-symbol {
  font-size: 1.1rem;
}

.sentence-tile-text {
  font-weight: 600;
  font-size: 0.95rem;
}

.sentence-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-speak {
  padding: 8px 16px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: var(--radius-md);
}

/* BOARD CONTAINER */
.board-container {
  flex: 1;
  padding: 10px;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.board-grid {
  display: grid;
  gap: 8px;
  flex: 1;
  width: 100%;
  height: 100%;
}

.tile-btn {
  font-family: var(--font-main);
  background: #FFFFFF;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
  cursor: pointer;
  position: relative;
  box-shadow: var(--shadow-sm);
  transition: transform 0.08s ease, filter 0.08s ease, box-shadow 0.08s ease;
  min-height: 52px;
}

.tile-btn:active {
  transform: scale(0.96);
  filter: brightness(0.92);
}

.tile-symbol {
  font-size: 1.4rem;
  line-height: 1.2;
}

.tile-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.tile-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #0F172A;
  margin-top: 2px;
  text-align: center;
  line-height: 1.1;
  word-break: break-word;
}

.tile-folder-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.65rem;
  background: rgba(0,0,0,0.1);
  padding: 2px 4px;
  border-radius: 4px;
}

.tile-home-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  font-size: 0.75rem;
  font-weight: 800;
}

.tile-masked {
  opacity: 0.15;
  pointer-events: none;
  background: #E2E8F0 !important;
  border-color: #CBD5E1 !important;
}

/* PROGRESSIVE LADDER CONTROLS */
.ladder-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ladder-button-group {
  display: flex;
  gap: 6px;
}

/* FIRST-THEN SCHEDULE STYLES */
.first-then-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.routine-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-md);
}

.routine-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.routine-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.routine-flow {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.routine-step {
  background: var(--bg-surface-elevated);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.routine-step.done {
  background: #DCFCE7;
  border-color: var(--accent-green);
}

.routine-step.done .step-task {
  text-decoration: line-through;
  color: var(--text-muted);
}

.step-label {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 4px;
}

.step-symbol {
  font-size: 2.5rem;
  margin: 6px 0;
}

.step-task {
  font-size: 1rem;
  font-weight: 700;
}

.flow-arrow {
  font-size: 1.5rem;
  color: var(--text-muted);
  text-align: center;
}

/* EMERGENCY & PAIN SCALE */
.emergency-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}

.section-block {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.section-block-title {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pain-scale-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.pain-card {
  padding: 12px 6px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(0,0,0,0.15);
  text-align: center;
  cursor: pointer;
  transition: transform 0.1s ease;
  color: #0F172A;
}

.pain-card:active {
  transform: scale(0.95);
}

.pain-face {
  font-size: 2.2rem;
}

.pain-level {
  font-weight: 800;
  font-size: 0.85rem;
  margin-top: 4px;
}

.body-parts-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.sensory-alerts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.alert-card {
  background: #FEE2E2;
  border: 2px solid #EF4444;
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  font-weight: 700;
  color: #991B1B;
}

/* TUTORIAL OVERLAY & SPOTLIGHT */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(2px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.tutorial-card {
  background: var(--bg-surface);
  border: 2px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}

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

.tutorial-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.tutorial-badge {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--primary);
  background: #E0F2FE;
  padding: 4px 8px;
  border-radius: 4px;
}

.tutorial-close-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.tutorial-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.tutorial-text {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.tutorial-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tutorial-nav-buttons {
  display: flex;
  gap: 8px;
}

.tutorial-highlighted {
  position: relative;
  z-index: 10000 !important;
  box-shadow: 0 0 0 4px #F59E0B, 0 0 20px rgba(245, 158, 11, 0.6) !important;
  animation: pulseHighlight 1.5s infinite alternate;
}

@keyframes pulseHighlight {
  from { transform: scale(1); }
  to { transform: scale(1.03); }
}

/* MODAL DIALOGS */
dialog {
  margin: auto;
  padding: 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  box-shadow: var(--shadow-lg);
  max-width: 650px;
  width: 90%;
  max-height: 85vh;
  overflow: auto;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.dialog-title {
  font-size: 1.25rem;
  font-weight: 700;
}

/* CLINICAL REPORT STYLES */
.metrics-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.metric-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
}

.metric-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  margin-top: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th, td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  background: var(--bg-surface-elevated);
  font-weight: 700;
  color: var(--text-muted);
}

/* HIGH CONTRAST SPECIFICS */
[data-theme="high-contrast"] .tile-btn {
  border: 3px solid #000000 !important;
  color: #000000 !important;
  font-weight: 900 !important;
}

[data-theme="high-contrast"] .tile-label {
  color: #000000 !important;
  font-weight: 900 !important;
}

/* DROPZONE FOR OBF/OBZ IMPORT */
.dropzone {
  border: 2px dashed var(--primary);
  border-radius: var(--radius-md);
  padding: 32px 16px;
  text-align: center;
  background: var(--bg-surface-elevated);
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 16px 0;
}

.dropzone:hover, .dropzone.dragover {
  background: #E0F2FE;
  border-color: var(--primary-hover);
  transform: scale(1.01);
}

.dropzone-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.dropzone-text {
  font-weight: 600;
  color: var(--text-main);
}

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

/* PRINT MEDIA */
@media print {
  .top-app-bar, .quickfires-bar, .app-actions, .tutorial-overlay {
    display: none !important;
  }
  body {
    overflow: visible;
    background: #FFFFFF;
    color: #000000;
  }
  .board-container, dialog {
    overflow: visible;
    box-shadow: none;
    border: none;
  }
}

