/*
 * PAT Wiz — FlyerWorks branding
 * Navy + royal blue + orange accent. Light/dark via data-theme on body.
 */

/* --- Light mode (default) --- */
:root,
[data-theme="light"] {
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --text: #061A3A;
  --muted: #64748B;
  --primary: #0057B8;
  --primary-dark: #002B5C;
  --accent: #FF6A00;
  --border: #E2E8F0;
  --shadow: rgba(0, 43, 92, 0.12);
  --on-primary: #FFFFFF;
  --focus-ring: rgba(0, 87, 184, 0.2);
  --primary-soft: rgba(0, 87, 184, 0.1);
  --accent-soft: rgba(255, 106, 0, 0.15);
  --input-bg: #F8FAFC;
  --warning-bg: #FFF8EB;
  --warning-border: #FCD34D;
  --warning-text: #92400E;
  --highlight-green: #16A34A;
  --highlight-green-soft: rgba(22, 163, 74, 0.12);
  --radius: 16px;
  --radius-sm: 12px;
  --max-width: 640px;
}

/* --- Dark mode --- */
[data-theme="dark"] {
  --bg: #061A3A;
  --card: #0B234A;
  --text: #F8FAFC;
  --muted: #A7B4C8;
  --primary: #1E90FF;
  --primary-dark: #0A4F9E;
  --accent: #FF7A1A;
  --border: #1E3A5F;
  --shadow: rgba(0, 0, 0, 0.35);
  --on-primary: #FFFFFF;
  --focus-ring: rgba(30, 144, 255, 0.25);
  --primary-soft: rgba(30, 144, 255, 0.15);
  --accent-soft: rgba(255, 122, 26, 0.2);
  --input-bg: #061A3A;
  --warning-bg: rgba(255, 193, 7, 0.12);
  --warning-border: rgba(255, 193, 7, 0.35);
  --warning-text: #FCD34D;
  --highlight-green: #4ADE80;
  --highlight-green-soft: rgba(74, 222, 128, 0.15);
}

/* --- Base reset --- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* --- Theme toggle (top-right) --- */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow);
  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.theme-toggle:hover {
  border-color: var(--primary);
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.theme-icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.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; }

/* --- Page shell --- */
.page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.card {
  width: 100%;
  max-width: var(--max-width);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px var(--shadow);
  padding: 32px 24px;
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

/* --- Brand / header --- */
.brand {
  text-align: center;
  margin-bottom: 28px;
}

.brand-compact {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  margin-bottom: 0;
}

.logo {
  display: block;
  object-fit: contain;
}

.logo-large {
  width: min(100%, 400px);
  max-height: 104px;
  height: auto;
  margin: 0 auto 16px;
  object-fit: contain;
}

/* Keep the wide logo readable on dark backgrounds */
[data-theme="dark"] .logo-large {
  background: #FFFFFF;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
}

.logo-small {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

[data-theme="dark"] .logo-small {
  background: #FFFFFF;
  padding: 4px;
  border-radius: 8px;
}

.app-name {
  margin: 0 0 8px;
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  position: relative;
  padding-bottom: 10px;
}

/* Thin orange accent under title — small, not everywhere */
.app-name::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
}

.brand-compact .app-name::after {
  display: none;
}

.app-name-compact {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  padding-bottom: 0;
}

.instruction {
  margin: 12px 0 0;
  color: var(--muted);
}

/* --- Search form --- */
.search-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.textarea-wrap {
  position: relative;
}

textarea {
  width: 100%;
  min-height: 140px;
  padding: 16px 56px 16px 16px;
  font: inherit;
  font-size: 1.0625rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

textarea::placeholder { color: var(--muted); }

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

.mic-button {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card);
  color: var(--primary);
  cursor: pointer;
  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.mic-button:hover {
  background: var(--input-bg);
  border-color: var(--primary);
}

.mic-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.mic-button.is-listening {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  animation: pulse 1.4s ease-in-out infinite;
}

.mic-icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.mic-unsupported {
  margin: -8px 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.submit-button {
  width: 100%;
  min-height: 52px;
  padding: 14px 24px;
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--on-primary);
  background: var(--primary);
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease;
}

.submit-button.is-loading {
  opacity: 1;
  border-bottom-color: var(--accent);
  cursor: wait;
}

.submit-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: var(--on-primary);
  border-right-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.submit-button:hover:not(:disabled) {
  background: var(--primary-dark);
  border-bottom-color: var(--accent);
}

.submit-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.submit-button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.hidden { display: none !important; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* --- Results page --- */
.results-card { padding: 24px 20px 28px; }

.results-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.results-header .brand {
  margin-bottom: 20px;
}

.search-meta {
  margin-top: 0;
  text-align: center;
}

.searched-label {
  margin: 0 0 4px;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

.searched-value {
  margin: 0 0 12px;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

.type-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
}

.type-medication {
  background: var(--primary-soft);
  color: var(--primary);
}

.type-surgery {
  background: var(--primary-soft);
  color: var(--primary);
}

.type-neither {
  background: rgba(100, 116, 139, 0.15);
  color: var(--muted);
}

[data-theme="dark"] .type-neither {
  background: rgba(167, 180, 200, 0.12);
}

.results-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  margin: 0 0 4px;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
}

.result-card {
  padding: 20px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.result-title {
  margin: 0 0 12px;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
}

.result-detail { margin: 0 0 8px; color: var(--text); }

.result-detail .label {
  font-weight: 600;
  color: var(--muted);
}

.highlight-box {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.highlight-primary {
  background: var(--highlight-green-soft);
  border-left: 4px solid var(--highlight-green);
}

/* Standalone guidance cards (surgery risk sections) — matches medication highlight style */
.guidance-card {
  margin-top: 0;
}

.guidance-card .highlight-label {
  font-size: 1rem;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
}

.guidance-card .risk-list {
  margin-top: 8px;
}

.highlight-secondary {
  background: var(--primary-soft);
  border-left: 4px solid var(--primary);
}

.highlight-label {
  margin: 0 0 6px;
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.highlight-text {
  margin: 0;
  line-height: 1.55;
  color: var(--text);
}

.risk-list {
  margin: 0;
  padding-left: 20px;
  color: var(--text);
}

.risk-list li {
  margin-bottom: 8px;
  line-height: 1.5;
}

.risk-list li:last-child { margin-bottom: 0; }

.result-warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

.result-warning h2 {
  margin: 0 0 8px;
  font-size: 1.0625rem;
  color: var(--warning-text);
}

.result-warning p {
  margin: 0;
  color: var(--warning-text);
}

.results-footer {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.back-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 14px 24px;
  width: 100%;
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--on-primary);
  background: var(--primary);
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.back-button:hover {
  background: var(--primary-dark);
  border-bottom-color: var(--accent);
  color: var(--on-primary);
}

.back-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.report-form {
  margin-top: 12px;
}

.report-json {
  display: none;
}

.report-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 14px 24px;
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--on-primary);
  background: var(--primary);
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.report-button:hover:not(:disabled) {
  background: var(--primary-dark);
  border-bottom-color: var(--accent);
  color: var(--on-primary);
}

.report-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.report-button:disabled {
  opacity: 0.7;
  cursor: default;
  color: var(--on-primary);
  background: var(--primary);
}

/* --- Responsive --- */
@media (max-width: 480px) {
  .theme-toggle {
    top: 12px;
    right: 12px;
  }

  .page {
    padding: 0;
    align-items: stretch;
  }

  .card {
    min-height: 100vh;
    max-width: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
    padding: 28px 20px 32px;
  }

  .logo-large {
    width: min(100%, 360px);
    max-height: 92px;
  }
  .app-name { font-size: 1.5rem; }
  textarea { min-height: 160px; font-size: 1rem; }
}

@media (min-width: 768px) {
  .card { padding: 40px 36px; }
  .logo-large {
    width: min(100%, 440px);
    max-height: 112px;
  }
}
