/* ═══════════════════════════════════════════════════════════════
   Angiogram Study – Styles (complete rewrite)
   ═══════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;
  --bg: #f2f5fa;
  --card: #ffffff;
  --text: #14213d;
  --muted: #5f6b82;
  --primary: #1f6feb;
  --primary-dark: #174ea6;
  --border: #d7dce5;
  --danger: #c02626;
  --success: #1a8c3a;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ── Screen infrastructure ─────────────────────────────────── */
.screen {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* ── Typography helpers ────────────────────────────────────── */
h1 { font-size: 1.6rem; margin-bottom: 6px; }
h2 { font-size: 1.25rem; margin-bottom: 4px; }
p  { margin-bottom: 10px; line-height: 1.45; }
.muted { color: var(--muted); font-size: 0.92rem; }
.error { color: var(--danger); min-height: 22px; font-size: 0.92rem; }

/* ── Shared components ─────────────────────────────────────── */
.center-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 70dvh;
  gap: 10px;
}

.login-card {
  background: #ffffff;
  border-radius: var(--radius);
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.login-card h1 {
  margin-bottom: 24px;
  text-align: center;
}

.login-card .muted {
  margin-bottom: 24px;
  text-align: center;
}

.login-card label {
  margin-top: 16px;
  margin-bottom: 6px;
}

.login-card label:first-of-type {
  margin-top: 0;
}

.login-card input {
  margin-bottom: 4px;
}

.login-card #login-btn {
  margin-top: 20px;
  width: 100%;
}

.login-card #login-error {
  margin-top: 12px;
  text-align: center;
  min-height: 20px;
}

label {
  font-weight: 600;
  font-size: 0.95rem;
  display: block;
  margin-bottom: 4px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
.date-input {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.05rem;
  background: #fff;
  color: var(--text);
}

input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  -webkit-appearance: none;
}

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

.btn.primary:active { background: var(--primary-dark); }
.btn.small { min-height: 40px; font-size: 0.9rem; padding: 0 12px; }
.btn.full  { width: 100%; }

.btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* ── Rows ──────────────────────────────────────────────────── */
.row {
  display: flex;
  gap: 10px;
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.user-info-card {
  background: #e8f4fd;
  border: 1px solid #b3d9f2;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.user-info-card p {
  margin-bottom: 4px;
}

.user-info-card p:last-child {
  margin-bottom: 0;
}

/* ── HOME screen ───────────────────────────────────────────── */
.home-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.home-subtitle {
  font-size: 1.05rem;
  color: var(--muted);
}

.action-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 80px;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  -webkit-appearance: none;
}

.action-card:active {
  background: #f0f4ff;
}

.action-card.primary {
  border-color: var(--primary);
  background: #f0f6ff;
}

.action-card.primary:active {
  background: #dce8ff;
}

.action-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.action-text {
  display: flex;
  flex-direction: column;
}

.action-text strong {
  font-size: 1.1rem;
  color: var(--text);
}

.action-text small {
  font-size: 0.88rem;
  color: var(--muted);
}

/* ── Admin ─────────────────────────────────────────────────── */
.admin-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--card);
}

.admin-section summary {
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--muted);
}

.admin-inner {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Upload screen ─────────────────────────────────────────── */
.upload-body {
  gap: 14px;
}

.warning {
  background: #fff8e6;
  border: 1px solid #f0d060;
  border-radius: var(--radius);
  padding: 12px;
  font-size: 0.92rem;
  color: #7a5c00;
  margin-bottom: 10px;
}

input[type="file"] {
  width: 100%;
  padding: 14px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: #fafbfd;
  font-size: 1rem;
  cursor: pointer;
}

/* ── Review screen ─────────────────────────────────────────── */
.review-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.table-wrap { overflow-x: auto; }

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

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

th {
  background: #f5f7fa;
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════
   SURVEY – Full-screen wizard
   ═══════════════════════════════════════════════════════════════ */

/* When in survey mode, override everything to full-screen */
body.survey-mode {
  overflow: hidden;
}

body.survey-mode #survey-screen {
  max-width: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100dvh;
}

/* ── Survey bar ────────────────────────────────────────────── */
.survey-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}

.progress-text {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--muted);
}

/* ── Question area ─────────────────────────────────────────── */
.question-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  overflow-y: auto;
}

.q-inner {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.q-label {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.q-label-text {
  flex: 0 1 auto;
}

.info-icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--primary);
  background: var(--card);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  font-style: italic;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}

.info-icon:hover,
.info-icon:focus {
  background: var(--primary);
  color: var(--card);
  outline: none;
}

.info-tooltip {
  padding: 12px 14px;
  background: #f0f4fb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
  text-align: left;
}

.info-tooltip.hidden {
  display: none;
}

.info-tooltip-text {
  margin: 0 0 10px 0;
}

.info-tooltip-close {
  display: block;
  margin: 0 auto;
  padding: 6px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary);
  background: transparent;
  border: 1px solid var(--primary);
  border-radius: 8px;
  cursor: pointer;
}

.info-tooltip-close:hover,
.info-tooltip-close:focus {
  background: var(--primary);
  color: var(--card);
  outline: none;
}

/* ── Choice buttons ────────────────────────────────────────── */
.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 60px;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  line-height: 1.35;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.1s;
  -webkit-appearance: none;
}

.choice-btn:active {
  transform: scale(0.97);
}

.choice-btn.selected {
  border-color: var(--primary);
  background: #e8f0ff;
  color: var(--primary-dark);
}

.choice-mark {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border: 2px solid #8b97ab;
  background: #fff;
  position: relative;
}

.choice-single .choice-mark { border-radius: 50%; }
.choice-multi .choice-mark { border-radius: 6px; }

.choice-btn.selected .choice-mark {
  border-color: var(--primary);
  background: var(--primary);
}

.choice-single.selected .choice-mark::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #fff;
}

.choice-multi.selected .choice-mark::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.choice-label { flex: 1; }

.q-mode {
  align-self: center;
  margin: 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: #e8f0ff;
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 700;
}

.choice-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
}

.choice-divider::before,
.choice-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.extracted-note {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}

/* ── Survey footer ─────────────────────────────────────────── */
.survey-footer {
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}

.survey-footer .btn {
  min-height: 56px;
  font-size: 1.1rem;
}

/* ── Animations ────────────────────────────────────────────── */
.animate-in {
  animation: slideUp 200ms ease-out;
}

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

.shake {
  animation: shake 350ms ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-6px); }
  80%      { transform: translateX(6px); }
}

/* ── Completion celebration ────────────────────────────────── */
#celebrate-screen {
  position: relative;
  max-width: none;
  padding: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 20% 10%, #d9ecff 0%, transparent 50%),
    radial-gradient(ellipse at 80% 90%, #d8f5e4 0%, transparent 45%),
    linear-gradient(160deg, #f7fbff 0%, #eef6f1 100%);
}

.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.celebrate-box {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  padding: 24px;
}

.celebrate-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #c9d8ea;
  border-radius: 20px;
  padding: 36px 28px 28px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(20, 33, 61, 0.12);
  animation: celebrate-pop 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}

.celebrate-burst {
  font-size: 2.6rem;
  line-height: 1;
  margin-bottom: 10px;
  animation: celebrate-spin 1.2s ease-out both;
}

.celebrate-card h1 {
  font-size: 1.85rem;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  color: #0f3d2e;
}

.celebrate-sub {
  font-size: 1.08rem;
  color: var(--text);
  margin-bottom: 8px;
}

.celebrate-card .muted {
  margin-bottom: 22px;
}

.celebrate-card .btn {
  margin-top: 4px;
}

.complete-banner {
  margin-bottom: 16px;
  border-radius: var(--radius);
  border: 1px solid #9fd4b0;
  background: linear-gradient(135deg, #eefaf2 0%, #e7f4ff 100%);
  padding: 18px 16px;
}

.complete-banner-inner {
  text-align: center;
}

.complete-emoji {
  font-size: 1.8rem;
  margin-bottom: 6px;
}

.complete-banner h2 {
  color: #146c3c;
  margin-bottom: 6px;
}

.complete-hint {
  margin: 10px 0 0;
  font-size: 0.92rem;
  color: var(--text);
  font-weight: 600;
}

@keyframes celebrate-pop {
  from { opacity: 0; transform: translateY(18px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes celebrate-spin {
  from { transform: scale(0.4) rotate(-20deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ── Responsive ────────────────────────────────────────────── */
.q-section {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary);
  margin: 0;
}

.q-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0;
}

.q-error {
  text-align: center;
  color: var(--danger);
  font-weight: 600;
  min-height: 1.2em;
  margin: 0;
}

.choice-group {
  margin: 6px 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.subfields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.question-area {
  align-items: flex-start;
  justify-content: flex-start;
}

.q-inner {
  margin: 0 auto;
}

@media (max-width: 600px) {
  .screen {
    padding: 12px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .row {
    flex-direction: column;
  }

  .q-label {
    font-size: 1.25rem;
  }
}
