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

:root {
  --bg:          #f5f5f0;
  --surface:     #ffffff;
  --border:      #e0ddd6;
  --border-soft: #ece9e2;
  --text:        #1a1a1a;
  --text-muted:  #6b6460;
  --accent:      #2c5f8a;
  --accent-bg:   #eaf1f8;
  --radio-size:  18px;
  --radius:      10px;
  --shadow:      0 1px 3px rgba(0,0,0,.08);
}

html, body {
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ── Layout ───────────────────────────────────────────────────── */
.app {
  min-height: 100dvh;
}

/* ── Header / Tabs ────────────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 14px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header .inner {
  display: flex;
  align-items: center;
  gap: 24px;
  max-width: 860px;
  margin: 0 auto;
}

.app-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  padding: 7px 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.tab:hover {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Content ──────────────────────────────────────────────────── */
.content {
  padding: 24px;
}

.scale-header,
.questions-list {
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Scale header ─────────────────────────────────────────────── */
.scale-header {
  margin-bottom: 20px;
}

.scale-header h2 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 6px;
}

.scale-instructions {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  max-width: 760px;
}

.scale-header-footer {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.keyboard-hint {
  font-size: 12px;
  color: var(--text-muted);
  opacity: .7;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg);
  font-size: 11px;
  font-family: inherit;
  line-height: 1.5;
  color: var(--text);
}

/* ── Dialog ───────────────────────────────────────────────────── */
dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 32px;
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  max-width: 360px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}

dialog::backdrop {
  background: rgba(0,0,0,.35);
}

dialog p {
  margin: 0 0 24px;
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-actions button {
  padding: 7px 20px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}

#dialog-cancelar {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
}

#dialog-cancelar:hover {
  background: var(--bg);
}

#dialog-confirmar {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

#dialog-confirmar:hover {
  opacity: .88;
}

/* ── Nuevo Paciente button ────────────────────────────────────── */
.btn-nuevo-paciente {
  margin-left: auto;
  padding: 7px 18px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .03em;
  transition: background .15s, color .15s;
}

.btn-nuevo-paciente:hover {
  background: var(--accent);
  color: #fff;
}

/* ── Reset button ─────────────────────────────────────────────── */
.btn-reset {
  margin-top: 10px;
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.btn-reset:hover {
  background: #fdf0f0;
  color: #c0392b;
  border-color: #e4b4b4;
}

/* ── Question rows ────────────────────────────────────────────── */
.questions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 900px;
}

.question-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
}

.question-row:hover {
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.question-row.answered {
  border-left: 3px solid var(--accent);
}

.question-row:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(44, 95, 138, 0.18);
}

.question-row:focus .question-num {
  color: var(--accent);
}

.question-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 28px;
  padding-top: 2px;
}

.question-text {
  flex: 1;
  font-size: 14px;
  line-height: 1.5;
  padding-top: 1px;
}

/* ── Radio group ──────────────────────────────────────────────── */
.radio-group {
  display: flex;
  justify-content: space-between;
  flex-wrap: nowrap;
  align-items: flex-start;
  min-width: 300px;
}

.radio-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  gap: 4px;
  cursor: pointer;
}

.radio-option input[type="radio"] {
  width: var(--radio-size);
  height: var(--radio-size);
  accent-color: var(--accent);
  cursor: pointer;
}

.radio-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
  max-width: 60px;
  word-break: break-word;
}

/* ── Results bar (fixed footer) ───────────────────────────────── */
.results-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  overflow-x: auto;
  box-shadow: 0 -2px 6px rgba(0,0,0,.06);
}

.results-inner {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  min-width: max-content;
  margin: 0 auto;
}

.result-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 100px;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
}

.result-chip.total {
  background: var(--accent-bg);
  border-color: var(--accent);
  min-width: 120px;
}

.result-chip-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 2px;
}

.result-chip.total .result-chip-label {
  color: var(--accent);
  font-weight: 600;
}

.result-chip-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.result-chip.total .result-chip-value {
  color: var(--accent);
}

.result-chip-value.empty {
  color: var(--border);
  font-weight: 400;
}

.result-chip-cat {
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.btn-copy {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  align-self: center;
}

.btn-copy:hover  { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.btn-copy.copied { background: #e8f5e9; color: #2e7d32; border-color: #a5d6a7; }

.cat-bajo       { background: #e8f5e9; color: #2e7d32; }
.cat-moderado   { background: #fff3e0; color: #e65100; }
.cat-severo     { background: #fce4ec; color: #b71c1c; }
.cat-medio-bajo { background: #fffde7; color: #f9a825; }
.cat-medio-alto { background: #fff3e0; color: #e65100; }
.cat-alto       { background: #fce4ec; color: #b71c1c; }
.cat-baja       { background: #e8f5e9; color: #2e7d32; }
.cat-media      { background: #fff3e0; color: #e65100; }
.cat-alta       { background: #fce4ec; color: #b71c1c; }

.result-chip.disabled {
  opacity: .45;
  border-style: dashed;
}

/* ── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 600px) {
  * { box-sizing: border-box; }

  .app-header {
    padding: 10px 16px;
  }

  .app-header .inner {
    flex-wrap: wrap;
    gap: 8px;
  }

  .app-title {
    font-size: 14px;
    width: 100%;
  }

  .tabs {
    flex: 1;
  }

  .btn-nuevo-paciente {
    padding: 6px 12px;
    font-size: 12px;
    margin-left: 0;
  }

  .keyboard-hint { display: none; }

  .content {
    padding: 16px;
  }

  .question-row {
    flex-direction: column;
    gap: 12px;
  }

  .question-num {
    padding-top: 0;
  }

  .radio-group {
    width: 100%;
    min-width: unset;
  }

  .radio-label {
    max-width: unset;
    font-size: 10px;
  }

  .results-bar {
    padding: 10px 12px;
    overflow-x: unset;
  }

  .results-inner {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    min-width: unset;
    width: 100%;
  }

  .result-chip {
    min-width: unset;
    width: 100%;
    padding: 6px 4px;
  }

  .result-chip-label {
    font-size: 10px;
  }

  .result-chip-value {
    font-size: 18px;
  }

  .btn-copy {
    grid-column: 1 / -1;
    justify-self: center;
  }

  .result-chip {
    min-width: 80px;
    padding: 6px 10px;
  }
}

/* ── Resumen ──────────────────────────────────────────────────── */
.tab-resumen {
  margin-left: 8px;
  border-color: var(--accent);
  color: var(--accent);
}

.tab-resumen.active {
  background: var(--accent);
  color: #fff;
}

.resumen-wrapper {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.resumen-section {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.resumen-titulo {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.resumen-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ── Aviso de formulario incompleto ───────────────────────────── */
.aviso-copia {
  position: fixed;
  transform: translate(-50%, calc(-100% - 10px));
  background: #fff8e1;
  border: 1px solid #e6ac00;
  color: #6b4f00;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 500;
  pointer-events: none;
  box-shadow: 0 3px 10px rgba(0,0,0,.12);
  animation: aviso-in .15s ease forwards;
  transition: opacity .3s;
}

.aviso-copia::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #e6ac00;
}

.aviso-copia-out { opacity: 0; }

@keyframes aviso-in {
  from { opacity: 0; transform: translate(-50%, calc(-100% - 4px)); }
  to   { opacity: 1; transform: translate(-50%, calc(-100% - 10px)); }
}

.btn-copy-all {
  padding: 9px 24px;
  font-size: 13px;
  font-weight: 600;
  border-color: var(--accent);
  color: var(--accent);
}

.btn-copy-all:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #c0b8b0; }
