/* ==================================================================
   Pedident Dental Charting System - stylesheet
   Organised top-down: tokens -> layout primitives -> screens ->
   odontogram/tooth rendering -> responsive tweaks.
   ================================================================== */

:root {
  --color-bg: #0f172a;
  --color-surface: #ffffff;
  --color-surface-muted: #f1f5f9;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #cbd5e1;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-accent: #0ea5e9;

  --tooth-unset: #eef2f7;
  --tooth-sound: #ffffff;
  --tooth-missing: #4b5563;
  --tooth-carious: #f5c518;
  --tooth-prosthesis: #2563eb;
  --tooth-skipped: #d1d5db;
  --tooth-stroke: #334155;

  --radius: 10px;
  --shadow-card: 0 10px 30px rgba(15, 23, 42, 0.15);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
}

#app { min-height: 100vh; }

button, input { font-family: inherit; }

.screen { min-height: 100vh; }

.btn {
  font-size: 1rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--color-surface-muted); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-large { padding: 0.9rem 1.5rem; font-size: 1.1rem; width: 100%; }

/* ---------------- Patient screen ---------------- */

.patient-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(circle at top, #1e293b, #0f172a 65%);
}

.patient-card {
  width: 100%;
  max-width: 440px;
  background: var(--color-surface);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 2rem;
}

.app-title {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
  color: var(--color-primary-dark);
}
.app-title span {
  display: block;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.app-subtitle {
  margin: 0 0 1.5rem;
  color: var(--color-text-muted);
}

.field {
  display: block;
  margin-bottom: 1rem;
}
.field span {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 0.3rem;
}
.field input {
  width: 100%;
  padding: 0.7rem 0.8rem;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-muted);
}
.field input:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  background: #fff;
}

.field-error {
  color: #dc2626;
  font-size: 0.85rem;
  margin: -0.4rem 0 1rem;
}

/* ---------------- Charting screen ---------------- */

.charting-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: #f8fafc;
}

.charting-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--color-bg);
  color: #e2e8f0;
}
.patient-summary strong { font-size: 1rem; margin-right: 0.75rem; }
.patient-summary span { color: #94a3b8; font-size: 0.85rem; }
.progress { font-variant-numeric: tabular-nums; color: #cbd5e1; font-size: 0.9rem; }

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  background: #e0e7ff;
  border-bottom: 1px solid #c7d2fe;
}
.status-tooth-number {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-primary-dark);
  margin-right: 0.6rem;
}
.status-tooth-phase {
  font-size: 0.85rem;
  color: #4338ca;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.status-hint { font-size: 0.9rem; color: #334155; }

.odontogram-wrap {
  flex: 1;
  overflow: auto;
  padding: 1.25rem;
  display: flex;
  justify-content: center;
}

#odontogram-container {
  width: 100%;
  max-width: 1100px;
  background: #ffffff;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.08);
}

.arch-section + .arch-section { margin-top: 1.75rem; }

.arch-title {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: 0 0 0.6rem;
  text-align: center;
}

.tooth-row {
  display: flex;
  justify-content: center;
  gap: clamp(2px, 0.6vw, 8px);
  flex-wrap: wrap;
}
.tooth-row + .tooth-row { margin-top: 0.6rem; }

.pedal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  padding: 0.75rem 1.25rem 1.25rem;
  background: var(--color-bg);
  color: #cbd5e1;
  font-size: 0.85rem;
}
.legend-group { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.legend-title {
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  margin-right: 0.3rem;
}
.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5em;
  padding: 0.1em 0.4em;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 5px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  color: #f1f5f9;
}

/* ---------------- Tooth diagram ---------------- */

.tooth {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: clamp(34px, 4.6vw, 56px);
  cursor: pointer;
}

.tooth-svg {
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: visible;
  border-radius: 4px;
  transition: filter 0.15s ease, outline-color 0.1s ease;
  outline: 2px solid transparent;
  outline-offset: 2px;
}

.tooth:not(.skipped):hover .tooth-svg {
  outline-color: var(--color-accent);
}
.tooth:not(.skipped):hover .tooth-label {
  color: var(--color-accent);
}

.tooth-outline {
  fill: none;
  stroke: var(--tooth-stroke);
  stroke-width: 2;
  pointer-events: none;
}

.surface {
  stroke: var(--tooth-stroke);
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.fill-unset { fill: var(--tooth-unset); }
.fill-sound { fill: var(--tooth-sound); }
.fill-missing { fill: var(--tooth-missing); }
.fill-carious { fill: var(--tooth-carious); }
.fill-prosthesis { fill: var(--tooth-prosthesis); }
.fill-skipped { fill: var(--tooth-skipped); }

.tooth-label {
  margin-top: 0.25rem;
  font-size: clamp(0.6rem, 1.1vw, 0.75rem);
  font-weight: 600;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.tooth.skipped {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}
.tooth.skipped .tooth-label { color: #94a3b8; }

.tooth.active .tooth-svg {
  filter: drop-shadow(0 0 6px rgba(37, 99, 235, 0.9));
  animation: pedident-blink 1s ease-in-out infinite;
}
.tooth.active .tooth-label {
  color: var(--color-primary-dark);
  font-weight: 800;
}

@keyframes pedident-blink {
  0%, 100% { filter: drop-shadow(0 0 3px rgba(37, 99, 235, 0.55)); }
  50% { filter: drop-shadow(0 0 12px rgba(37, 99, 235, 1)); }
}

@media (prefers-reduced-motion: reduce) {
  .tooth.active .tooth-svg { animation: none; filter: drop-shadow(0 0 8px rgba(37, 99, 235, 0.9)); }
}

/* ---------------- Complete screen ---------------- */

.complete-screen {
  min-height: 100vh;
  background: #f8fafc;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.complete-card {
  width: 100%;
  max-width: 560px;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 2rem;
  text-align: center;
}
.complete-summary { color: var(--color-text-muted); line-height: 1.6; }
.complete-file { margin: 1rem 0; }
.complete-file code {
  background: var(--color-surface-muted);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}
.complete-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.note-field {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
  text-align: left;
}
.note-field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 0.4rem;
}
.note-field label span {
  font-weight: 400;
  color: #94a3b8;
}
.note-field textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-muted);
  resize: vertical;
  margin-bottom: 0.6rem;
}
.note-field textarea:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  background: #fff;
}

.complete-hint {
  margin: 1.25rem 0 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.odontogram-review {
  width: 100%;
}
.odontogram-review .tooth.active { display: none; } /* nothing is "active" once finished */

/* ---------------- Responsive ---------------- */

@media (max-width: 640px) {
  .charting-header, .status-bar { padding: 0.6rem 0.8rem; }
  .odontogram-wrap { padding: 0.75rem; }
  #odontogram-container { padding: 0.75rem; }
  .pedal-legend { gap: 0.85rem; padding: 0.75rem 0.8rem 1rem; font-size: 0.78rem; }
  .patient-summary strong { display: block; }
}
