/* ─── Reset & Base ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #7C6FBF;
  --primary-soft: #A89BD4;
  --primary-bg: #EEEAF7;
  --bg: #FAF8F5;
  --bg-warm: #F5F0EB;
  --card: #FFFFFF;
  --text: #3D3852;
  --text-light: #8E8A9D;
  --text-warm: #6B6580;
  --border: #E8E4F0;
  --danger: #D4726A;
  --danger-bg: #FCEEED;
  --success: #6BAF8D;
  --success-bg: #EDF7F1;
  --warning: #D4A84B;
  --warning-bg: #FDF5E6;
  --accent: #B8A9D9;
  --radius: 20px;
  --radius-sm: 14px;
  --radius-xs: 10px;
  --shadow: 0 2px 16px rgba(60, 50, 90, 0.06);
  --shadow-lg: 0 8px 40px rgba(60, 50, 90, 0.1);
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Rounded', 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  overscroll-behavior: none;
}

/* ─── Auth Page ─── */
.auth-container {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #F5F0EB 0%, #EEEAF7 50%, #E8F0F5 100%);
}

.auth-logo {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(124, 111, 191, 0.25);
}

.auth-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.auth-subtitle {
  color: var(--text-light);
  font-size: 16px;
  margin-bottom: 32px;
  font-weight: 400;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.6);
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  background: var(--bg-warm);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  border: none;
  background: transparent;
  color: var(--text-light);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all 0.25s ease;
}

.auth-tab.active {
  background: var(--card);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(60, 50, 90, 0.08);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-warm);
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 13px 16px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  transition: all 0.25s ease;
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-soft);
  background: white;
  box-shadow: 0 0 0 4px rgba(124, 111, 191, 0.1);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  color: white;
  box-shadow: 0 4px 12px rgba(124, 111, 191, 0.3);
}

.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(124, 111, 191, 0.3);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:active {
  opacity: 0.9;
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text-warm);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 14px;
  width: auto;
}

.error-msg {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 12px 16px;
  border-radius: var(--radius-xs);
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
  font-weight: 500;
}

.error-msg.visible {
  display: block;
}

/* ─── App Layout ─── */
.app {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
  background: var(--bg);
}

.app.visible {
  display: flex;
}

.app-header {
  background: linear-gradient(135deg, var(--primary), #6B5EAA);
  color: white;
  padding: 18px 20px 16px;
  padding-top: calc(18px + var(--safe-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.greeting {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.8;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.header-btn {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  font-size: 22px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s;
}

.header-btn:active {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0.93);
}

/* ─── Tab Navigation ─── */
.tab-bar {
  display: flex;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  padding-bottom: var(--safe-bottom);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-light);
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.25s;
}

.tab-item .tab-icon {
  font-size: 24px;
  margin-bottom: 2px;
}

.tab-item.active {
  color: var(--primary);
}

/* ─── Content Area ─── */
.app-content {
  flex: 1;
  padding: 20px 16px;
  padding-bottom: calc(76px + var(--safe-bottom));
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-light);
  letter-spacing: 0.3px;
  margin-bottom: 12px;
  padding-left: 4px;
}

/* ─── Stats Cards ─── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 16px;
  box-shadow: var(--shadow);
  text-align: center;
  border: 1px solid rgba(0, 0, 0, 0.03);
}

.stat-card .stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -1px;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
  font-weight: 500;
}

/* ─── Entry Cards ─── */
.entry-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.03);
  transition: transform 0.15s;
}

.entry-card:active {
  transform: scale(0.99);
}

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

.entry-date {
  font-size: 13px;
  color: var(--text-light);
}

.entry-type {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.severity-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  color: white;
}

.severity-low { background: linear-gradient(135deg, #6BAF8D, #8BC5A7); }
.severity-mid { background: linear-gradient(135deg, #D4A84B, #E0BF7A); }
.severity-high { background: linear-gradient(135deg, #D4726A, #E09590); }

.entry-details {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  display: inline-block;
  padding: 5px 12px;
  background: var(--primary-bg);
  color: var(--primary);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.tag.symptom {
  background: var(--danger-bg);
  color: var(--danger);
}

.tag.medication {
  background: var(--success-bg);
  color: var(--success);
}

.entry-notes {
  margin-top: 10px;
  font-size: 14px;
  color: var(--text-light);
  font-style: italic;
  line-height: 1.4;
}

.entry-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.entry-action-btn {
  flex: 1;
  padding: 9px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  transition: all 0.15s;
}

.entry-action-btn.edit {
  background: var(--primary-bg);
  color: var(--primary);
}

.entry-action-btn.delete {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ─── Date Headers ─── */
.date-header {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-light);
  margin: 20px 0 10px;
  padding-left: 4px;
}

.date-header:first-child {
  margin-top: 0;
}

/* ─── New Entry Form ─── */
.form-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-warm);
  letter-spacing: 0.3px;
  margin-top: 24px;
  margin-bottom: 12px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 9px 16px;
  border: 2px solid var(--border);
  border-radius: 24px;
  font-size: 14px;
  background: var(--card);
  color: var(--text-warm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s ease;
  user-select: none;
  font-family: inherit;
  font-weight: 500;
}

.chip.selected {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

.severity-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(to right, var(--success), var(--warning), var(--danger));
  outline: none;
  opacity: 0.85;
}

.severity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--primary);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  cursor: pointer;
}

.severity-display {
  text-align: center;
  font-size: 36px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
  letter-spacing: -1px;
}

/* ─── Empty State ─── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-light);
}

.empty-state .empty-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.7;
}

.empty-state p {
  font-size: 15px;
  line-height: 1.6;
}

.empty-state strong {
  color: var(--primary);
}

/* ─── Modal / Overlay ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 60, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

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

.modal {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px 24px 24px;
  padding-bottom: calc(24px + var(--safe-bottom));
  animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  -webkit-overflow-scrolling: touch;
}

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

.modal-handle {
  width: 36px;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  margin: 0 auto 16px;
}

.modal-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  letter-spacing: -0.3px;
}

/* ─── Duration Select ─── */
.duration-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.duration-option {
  padding: 11px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  background: var(--card);
  color: var(--text-warm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s ease;
  font-family: inherit;
}

.duration-option.selected {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

/* ─── Settings ─── */
.settings-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(0, 0, 0, 0.03);
}

.settings-section h3 {
  font-size: 17px;
  margin-bottom: 14px;
  font-weight: 700;
  color: var(--text);
}

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.settings-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-item:first-of-type {
  padding-top: 0;
}

.user-email {
  font-size: 14px;
  color: var(--text-light);
  font-weight: 500;
}

/* ─── Toggle Switch ─── */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle {
  position: relative;
  width: 52px;
  height: 32px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 16px;
  transition: 0.25s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 26px;
  width: 26px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.25s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.toggle input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ─── Notification Banner ─── */
.notif-banner {
  background: linear-gradient(135deg, var(--primary-bg), #E8F0F5);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  display: none;
  align-items: center;
  gap: 14px;
  border: 1px solid rgba(124, 111, 191, 0.15);
}

.notif-banner.visible {
  display: flex;
}

.notif-banner-icon {
  font-size: 28px;
  flex-shrink: 0;
}

.notif-banner-text {
  flex: 1;
}

.notif-banner-text strong {
  display: block;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 2px;
}

.notif-banner-text span {
  font-size: 13px;
  color: var(--text-warm);
}

.notif-banner-btn {
  padding: 8px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}

/* ─── Stats breakdown ─── */
.breakdown-bar-bg {
  height: 8px;
  background: var(--bg-warm);
  border-radius: 4px;
  overflow: hidden;
}

.breakdown-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* ─── Loading ─── */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ─── Chip Sublabels ─── */
.chip-sublabel {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-light);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-top: 12px;
  margin-bottom: 6px;
  padding-left: 2px;
}

.chip-sublabel:first-child {
  margin-top: 0;
}

/* ─── Settings Hint ─── */
.settings-hint {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 12px;
  line-height: 1.4;
}

/* ─── Interaction Warnings ─── */
#interaction-warnings {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.interaction-card {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  align-items: flex-start;
}

.interaction-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.interaction-text {
  flex: 1;
}

.interaction-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(212, 114, 106, 0.2);
}

.interaction-warning {
  background: var(--warning-bg);
  color: #8a6d1b;
  border: 1px solid rgba(212, 168, 75, 0.2);
}

.interaction-info {
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px solid rgba(124, 111, 191, 0.15);
}

/* ─── Wissen View ─── */
.wissen-disclaimer {
  background: var(--warning-bg);
  color: #8a6d1b;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 16px;
  border: 1px solid rgba(212, 168, 75, 0.2);
}

.wissen-section {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(0, 0, 0, 0.03);
  overflow: hidden;
}

.wissen-section summary {
  padding: 16px 18px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.wissen-section summary::-webkit-details-marker {
  display: none;
}

.wissen-section summary::after {
  content: '›';
  font-size: 20px;
  color: var(--text-light);
  transition: transform 0.2s;
  font-weight: 400;
}

.wissen-section[open] summary::after {
  transform: rotate(90deg);
}

.wissen-section[open] summary {
  border-bottom: 1px solid var(--border);
}

.wissen-content {
  padding: 16px 18px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-warm);
}

.wissen-content p {
  margin-bottom: 10px;
}

.wissen-content ul,
.wissen-content ol {
  margin-bottom: 12px;
  padding-left: 20px;
}

.wissen-content li {
  margin-bottom: 6px;
}

.wissen-content strong {
  color: var(--text);
}

.wissen-content em {
  color: var(--text-light);
}

.wissen-warning {
  background: var(--warning-bg);
  color: #8a6d1b;
  padding: 12px 14px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  margin-top: 12px;
  border: 1px solid rgba(212, 168, 75, 0.2);
  line-height: 1.45;
}

.wissen-warning ul {
  margin-top: 6px;
  margin-bottom: 0;
}

.wissen-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 12px;
}

.wissen-table-row {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.wissen-table-row:last-child {
  border-bottom: none;
}

.wissen-table-cell:first-child {
  flex: 0 0 45%;
  font-size: 13px;
}

.wissen-table-cell:last-child {
  flex: 1;
  font-size: 13px;
  color: var(--text-light);
}

.wissen-sources {
  list-style: none !important;
  padding-left: 0 !important;
}

.wissen-sources li {
  font-size: 12px;
  color: var(--text-light);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.wissen-sources li:last-child {
  border-bottom: none;
}

/* ─── Utilities ─── */
.hidden { display: none !important; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-12 { margin-bottom: 12px; }
.text-center { text-align: center; }

/* Screen-reader-only (AC-8) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ─── Chat Screen ─── */
#chat-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* Back nav bar */
.chat-nav-bar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  flex-shrink: 0;
}

.chat-back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 16px;
  font-family: inherit;
  padding: 6px 8px;
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
  border-radius: var(--radius-xs);
}

.chat-back-btn:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* ─── Escalation Widget (AC-4) ─── */
#escalation-widget {
  background: #8b0000;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

#escalation-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: #8b0000;
  color: #ffffff; /* white on #8b0000 = 7.5:1 contrast ratio (WCAG AAA) */
  border: none;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  min-height: 44px;
  text-align: left;
}

#escalation-toggle:focus-visible {
  outline: 3px solid #ffcc00;
  outline-offset: -3px;
}

#escalation-toggle .escalation-chevron {
  margin-left: auto;
}

#escalation-details {
  background: #fff5f5;
  border-top: 2px solid #8b0000;
  padding: 16px;
  color: var(--text);
}

#escalation-details p {
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.5;
}

#escalation-details ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

#escalation-details li {
  padding: 6px 0;
  font-size: 15px;
  border-bottom: 1px solid #f5cccc;
}

#escalation-details li:last-child {
  border-bottom: none;
}

#escalation-details a {
  color: #8b0000;
  text-decoration: underline;
  font-weight: 700;
}

/* ─── Chat Main Area ─── */
#chat-main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  max-width: 100%;
}

#chat-heading {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

/* ─── Offline Banner (AC-10) ─── */
#chat-offline-banner {
  background: #c0392b;
  color: #ffffff;
  padding: 12px 16px;
  border-radius: var(--radius-xs);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Message List (AC-8) ─── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0;
  outline: none;
}

#chat-messages:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* ─── Message Bubbles ─── */
.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 2px;
}

.chat-message--user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-message--assistant,
.chat-message--system {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-message__role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  padding: 0 4px;
}

.chat-message__content {
  background: var(--primary-bg);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-message--user .chat-message__content {
  background: var(--primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.chat-message--assistant .chat-message__content,
.chat-message--system .chat-message__content {
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

.chat-message__time {
  font-size: 11px;
  color: var(--text-light);
  padding: 0 4px;
}

/* ─── Resume Banner (AC-5) ─── */
#chat-resume-banner {
  background: var(--primary-bg);
  border: 1px solid var(--primary-soft);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#chat-resume-banner p {
  font-size: 14px;
  color: var(--text);
}

#chat-resume-btn,
#chat-new-btn {
  padding: 10px 16px;
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  border: none;
}

#chat-resume-btn {
  background: var(--primary);
  color: #ffffff;
}

#chat-new-btn {
  background: none;
  border: 2px solid var(--border);
  color: var(--text);
}

#chat-resume-btn:focus-visible,
#chat-new-btn:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* ─── Chat Form / Input ─── */
#chat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  background: var(--card);
  color: var(--text);
  resize: none;
  max-width: 100%;
}

#chat-input:focus {
  outline: none;
  border-color: var(--primary);
}

#chat-input:disabled {
  opacity: 0.5;
  background: var(--bg-warm);
}

#chat-send {
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-xs);
  padding: 10px 18px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  flex-shrink: 0;
  align-self: flex-end;
}

#chat-send:disabled {
  opacity: 0.45;
  cursor: default;
}

#chat-send:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* ─── Chat Actions ─── */
#chat-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

#chat-end-btn {
  background: none;
  border: 2px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-xs);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
}

#chat-end-btn:focus-visible {
  outline: 3px solid var(--danger);
  outline-offset: 2px;
}

#chat-transcript-link {
  display: inline-flex;
  align-items: center;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  padding: 10px 4px;
  min-height: 44px;
}

#chat-transcript-link:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ─── Responsive: 375px and 1280px widths (AC-1) ─── */
@media (min-width: 640px) {
  #chat-main {
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    padding: 24px;
  }

  #chat-messages {
    max-height: 65vh;
  }

  .chat-message {
    max-width: 70%;
  }
}

/* ─── Chat nav-btn tab-bar integration ─── */
.tab-bar .nav-btn {
  /* Inherits tab-item layout; no additional overrides needed */
}
