:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #dfe5ee;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-soft: #eff6ff;
  --true-color: #0f766e;
  --true-bg: #f0fdfa;
  --true-border: #14b8a6;
  --false-color: #b91c1c;
  --false-bg: #fef2f2;
  --false-border: #f87171;
  --warning-bg: #fffbeb;
  --warning-border: #f59e0b;
  --warning-text: #92400e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.text-danger {
  color: var(--false-color);
}

.text-true {
  color: var(--true-color);
}

.text-false {
  color: var(--false-color);
}

/* Topbar fija */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.topbar-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

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

.brand-badge {
  background: var(--primary-dark);
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Progreso y cronómetro */
.progress-area {
  flex: 1;
  min-width: 180px;
  max-width: 300px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.progress-track {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #0f766e);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.topbar-status-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.timer-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #0f172a;
  color: #f8fafc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 6px 13px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

.timer-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}

.timer-dot.running {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.28);
  animation: blinkDot 1.6s infinite;
}

@keyframes blinkDot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.sync-badge {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.sync-ok {
  background: var(--true-bg);
  color: var(--true-color);
  border-color: #ccfbf1;
}

.sync-saving {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #bfdbfe;
}

.sync-offline {
  background: var(--warning-bg);
  color: var(--warning-text);
  border-color: var(--warning-border);
}

/* Container & Cards */
.container {
  max-width: 1140px;
  margin: 24px auto 64px;
  padding: 0 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 18px;
}

.center-card {
  text-align: center;
  padding: 48px 24px;
}

.success-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--true-bg);
  color: var(--true-color);
  border: 2px solid var(--true-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  font-weight: 800;
}

.completed-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.meta-chip {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.88rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.autosave-indicator {
  font-size: 0.78rem;
  color: var(--true-color);
  background: var(--true-bg);
  border: 1px solid #ccfbf1;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 500;
}

/* Gate de inicio y estado bloqueado */
.start-gate-card {
  background: linear-gradient(135deg, #eff6ff 0%, #f0fdfa 100%);
  border: 1.5px solid #93c5fd;
}

.start-gate-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.start-gate-content h2 {
  margin: 0;
  color: var(--primary-dark);
  font-size: 1.15rem;
}

.form-locked {
  position: relative;
}

.form-locked .card,
.form-locked .questions-container,
.form-locked .pagination-bar,
.form-locked .finish-bar {
  opacity: 0.58;
  user-select: none;
}

.locked-notice {
  background: #f1f5f9;
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  text-align: center;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 0.88rem;
}

/* Formularios */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-wide {
  grid-column: span 3;
}

.field-span-2 {
  grid-column: span 2;
}

.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field input,
.field select,
.select-sm,
.input-search {
  font-family: inherit;
  font-size: 0.92rem;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus,
.select-sm:focus,
.input-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.field input:disabled,
.field select:disabled {
  background: #f8fafc;
  cursor: not-allowed;
}

.field input.input-readonly {
  background: #f1f5f9;
  color: #475569;
  border-color: var(--border);
  cursor: default;
}

/* Quitar flechas genéricas en inputs number */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Desplegable personalizado con estética de la web */
.cselect {
  position: relative;
  width: 100%;
}

.cselect-sm {
  width: auto;
  min-width: 155px;
}

.cselect-native {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
  margin: 0;
}

.cselect-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.cselect-sm .cselect-trigger {
  padding: 6px 10px;
  font-size: 0.85rem;
}

.cselect-trigger:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--surface-alt);
}

.cselect.open .cselect-trigger,
.cselect-trigger:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.cselect-trigger:disabled {
  background: #f8fafc;
  color: var(--text-muted);
  cursor: not-allowed;
}

.cselect-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cselect-label.is-placeholder {
  color: var(--text-muted);
}

.cselect-chevron {
  display: inline-flex;
  align-items: center;
  color: var(--text-muted);
  transition: transform 0.18s ease, color 0.15s ease;
  flex-shrink: 0;
}

.cselect.open .cselect-chevron {
  transform: rotate(180deg);
  color: var(--primary);
}

.cselect-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 100%;
  z-index: 200;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12), 0 4px 10px rgba(15, 23, 42, 0.06);
  padding: 5px;
  max-height: 240px;
  overflow-y: auto;
}

.cselect-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.cselect-option:hover:not(:disabled) {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.cselect-option.selected {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
}

.cselect-check {
  color: var(--primary);
  font-weight: 800;
  font-size: 0.85rem;
}

/* Autocompletado de pacientes existentes */
.autocomplete-wrap {
  position: relative;
  width: 100%;
}

.autocomplete-input-box {
  position: relative;
  display: flex;
  align-items: center;
}

.autocomplete-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.autocomplete-input-box input {
  width: 100%;
  padding-left: 36px !important;
}

.autocomplete-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 210;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12), 0 4px 10px rgba(15, 23, 42, 0.06);
  padding: 5px;
  max-height: 250px;
  overflow-y: auto;
}

.autocomplete-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.autocomplete-item:hover {
  background: var(--primary-soft);
}

.autocomplete-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.autocomplete-item-name {
  font-weight: 600;
  color: var(--text);
}

.autocomplete-item-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.autocomplete-dni-pill {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--primary-dark);
  white-space: nowrap;
}

.autocomplete-empty {
  padding: 10px 12px;
  font-size: 0.84rem;
  color: var(--text-muted);
  text-align: center;
}

/* Instrucciones */
.instructions-card details > summary {
  list-style: none;
  cursor: pointer;
  margin-bottom: 0;
}

.instructions-card details[open] > summary {
  margin-bottom: 14px;
}

.instructions-card details > summary::-webkit-details-marker {
  display: none;
}

.toggle-hint {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
}

.instructions-body p {
  margin: 0 0 10px;
  font-size: 0.92rem;
}

.important-note {
  margin-top: 12px !important;
  margin-bottom: 0 !important;
  padding: 10px 14px;
  background: var(--primary-soft);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 0.88rem;
}

.examples-table-wrap {
  margin: 10px 0 12px;
  overflow-x: auto;
}

.examples-table {
  border-collapse: collapse;
  width: 100%;
  max-width: 420px;
  font-size: 0.88rem;
}

.examples-table th,
.examples-table td {
  border: 1px solid var(--border);
  padding: 7px 12px;
  text-align: left;
}

.examples-table th:not(:first-child),
.examples-table td:not(:first-child) {
  text-align: center;
  width: 56px;
}

.examples-table th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 700;
}

.example-mark {
  display: inline-block;
  font-weight: 800;
  width: 24px;
  height: 24px;
  line-height: 24px;
  border-radius: 6px;
}

.mark-v {
  background: var(--true-bg);
  color: var(--true-color);
}

.mark-f {
  background: var(--false-bg);
  color: var(--false-color);
}

/* Toolbar & Preguntas */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
}

.checkbox-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.checkbox-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

.select-sm {
  padding: 6px 10px;
  font-size: 0.85rem;
}

.questions-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid transparent;
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease;
}

.question-card.answered-V {
  border-left-color: var(--true-color);
}

.question-card.answered-F {
  border-left-color: var(--false-color);
}

.question-content {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex: 1;
}

.question-num {
  flex-shrink: 0;
  min-width: 38px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.question-text {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 500;
}

.question-options {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.opt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 112px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
}

.opt-btn:disabled {
  cursor: not-allowed;
}

.opt-btn .opt-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  font-size: 0.8rem;
  font-weight: 800;
  background: var(--surface-alt);
  color: var(--text-muted);
}

.opt-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--surface-alt);
}

.opt-btn.opt-v.selected {
  background: var(--true-bg);
  border-color: var(--true-border);
  color: var(--true-color);
  box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.18);
}

.opt-btn.opt-v.selected .opt-letter {
  background: var(--true-color);
  color: #fff;
}

.opt-btn.opt-f.selected {
  background: var(--false-bg);
  border-color: var(--false-border);
  color: var(--false-color);
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.18);
}

.opt-btn.opt-f.selected .opt-letter {
  background: var(--false-color);
  color: #fff;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

/* Paginación */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  flex-wrap: wrap;
}

.page-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#pageLabel {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

.page-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
}

.page-dot {
  min-width: 28px;
  height: 26px;
  padding: 0 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

.page-dot.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.page-dot.complete:not(.active) {
  background: var(--true-bg);
  border-color: #99f6e4;
  color: var(--true-color);
}

.finish-bar {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-success {
  background: var(--true-color);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: #115e59;
}

.btn-secondary {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-alt);
}

.btn-ghost-danger {
  background: transparent;
  color: var(--false-color);
  border-color: #fecaca;
}

.btn-ghost-danger:hover:not(:disabled) {
  background: var(--false-bg);
}

.btn-danger {
  background: var(--false-color);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #991b1b;
}

/* Modales personalizados */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.14s ease;
}

.modal-overlay.visible {
  opacity: 1;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.18), 0 6px 16px rgba(15, 23, 42, 0.08);
  padding: 22px 24px 20px;
  transform: scale(0.96) translateY(6px);
  transition: transform 0.16s ease;
}

.modal-overlay.visible .modal-card {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.modal-icon {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-icon-primary {
  background: var(--primary-soft);
  color: var(--primary);
}

.modal-icon-success {
  background: var(--true-bg);
  color: var(--true-color);
}

.modal-icon-warning {
  background: var(--warning-bg);
  color: #d97706;
}

.modal-icon-danger {
  background: var(--false-bg);
  color: var(--false-color);
}

.modal-titles {
  flex: 1;
}

.modal-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.modal-message {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: pre-line;
  line-height: 1.5;
}

.modal-copy-wrap {
  margin-top: 14px;
}

.modal-copy-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  background: var(--surface-alt);
  color: var(--text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.btn-lg {
  padding: 13px 26px;
  font-size: 0.98rem;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.btn-xs {
  padding: 4px 9px;
  font-size: 0.78rem;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  font-weight: 700;
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
}

/* Alertas */
.alert-warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
}

.alert-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.alert-desc {
  margin: 4px 0 0;
  font-size: 0.86rem;
}

/* Panel Admin - Pestañas estilo carpeta debajo de la nav */
.folder-tabs {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding-left: 0;
  margin-bottom: 0;
  position: relative;
  z-index: 2;
  flex-wrap: wrap;
}

.folder-tab {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 12px 22px;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-muted);
  background: #e9eef5;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.folder-tab:hover:not(.active) {
  background: #dfe6f0;
  color: var(--text);
}

.folder-tab.active {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  margin-bottom: -1px;
  padding-bottom: 13px;
  position: relative;
  z-index: 3;
}

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

.tab-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  background: #dce3ee;
  color: var(--text-muted);
}

.folder-tab.active .tab-count {
  background: var(--primary-soft);
  color: var(--primary);
}

.folder-panel-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  position: relative;
  z-index: 1;
}

.folder-panel-shell > .admin-tab-panel > .card:first-child,
.folder-panel-shell > .admin-tab-panel > #patientsListView.card {
  box-shadow: none;
}

.folder-panel-shell > .admin-tab-panel > .card:last-child,
.folder-panel-shell > #sessionDetailView > .card:last-child {
  margin-bottom: 0;
}

@media (max-width: 640px) {
  .folder-tab {
    padding: 10px 14px;
    font-size: 0.84rem;
  }
  .folder-panel-shell {
    padding: 16px;
    border-radius: var(--radius);
  }
}

.generated-link-box {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--true-bg);
  border: 1px solid var(--true-border);
  border-radius: var(--radius-sm);
}

.generated-link-title {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--true-color);
  margin-bottom: 8px;
}

.generated-link-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.generated-link-row input {
  flex: 1;
  min-width: 240px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  background: #fff;
}

.tests-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.test-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  background: var(--surface-alt);
}

.test-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.test-card h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  color: var(--primary-dark);
}

.test-card p {
  margin: 0 0 12px;
  font-size: 0.85rem;
}

.test-card-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.test-card-actions {
  margin-top: 12px;
  display: flex;
}

.test-card-actions .btn {
  width: 100%;
}

.preview-banner {
  background: #f8fafc;
  border: 1.5px dashed var(--primary);
}

.filter-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.input-search {
  flex: 1;
  min-width: 220px;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.empty-cell {
  text-align: center !important;
  color: var(--text-muted);
  padding: 28px !important;
}

.actions-cell {
  white-space: nowrap;
  width: 1%;
}

.actions-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.actions-group .btn {
  white-space: nowrap;
}

.btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-refresh .refresh-icon {
  transition: transform 0.2s ease;
}

.btn-refresh.is-loading .refresh-icon {
  animation: spinRefresh 0.7s linear infinite;
}

.btn-refresh.is-done {
  border-color: var(--true-border);
  color: var(--true-color);
  background: var(--true-bg);
}

@keyframes spinRefresh {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.status-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.status-completed {
  background: var(--true-bg);
  color: var(--true-color);
}

.status-progress {
  background: var(--primary-soft);
  color: var(--primary);
}

.status-pending {
  background: #f1f5f9;
  color: var(--text-muted);
}

/* Métricas de resultados */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.metric-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.metric-value {
  font-size: 1.35rem;
  font-weight: 800;
}

/* Hoja de respuestas imprimible */
.sheet-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
}

.sheet-toolbar-left,
.sheet-toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sheet-summary-badge {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  border-bottom: 2px solid var(--primary-dark);
  padding-bottom: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.sheet-header h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--primary-dark);
}

.sheet-subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.sheet-stats {
  display: flex;
  gap: 10px;
  font-size: 0.82rem;
  font-weight: 600;
}

.stat-pill {
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.sheet-patient-info {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px 16px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 0.85rem;
}

.patient-item strong {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 4px;
}

.answer-grid-wrapper {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  overflow-x: auto;
}

.answer-col-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.answer-col-table th,
.answer-col-table td {
  border: 1px solid var(--border);
  text-align: center;
  padding: 3px 4px;
}

.answer-col-table th {
  background: var(--primary-dark);
  color: #fff;
  font-weight: 700;
}

.answer-col-table td.num-cell {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text-muted);
  width: 34%;
}

.answer-col-table td.cell-v {
  color: var(--true-color);
  font-weight: 800;
  background: var(--true-bg);
}

.answer-col-table td.cell-f {
  color: var(--false-color);
  font-weight: 800;
  background: var(--false-bg);
}

/* Responsive */
@media (max-width: 820px) {
  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .field-wide,
  .field-span-2 {
    grid-column: span 2;
  }
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .answer-grid-wrapper {
    grid-template-columns: repeat(4, 1fr);
  }
  .sheet-patient-info {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  .field-wide,
  .field-span-2 {
    grid-column: span 1;
  }
  .question-card {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .question-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .opt-btn {
    min-width: 0;
  }
  .metrics-grid {
    grid-template-columns: 1fr;
  }
  .answer-grid-wrapper {
    grid-template-columns: repeat(2, 1fr);
  }
  .sheet-patient-info {
    grid-template-columns: 1fr;
  }
}

/* Hamburger button y Drawer móvil */
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.hamburger-btn:hover {
  background: var(--surface-alt);
  border-color: var(--primary);
  color: var(--primary);
}

.mobile-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.mobile-drawer-overlay.open {
  opacity: 1;
}

.mobile-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(300px, 84vw);
  background: var(--surface);
  box-shadow: -8px 0 28px rgba(15, 23, 42, 0.16);
  display: flex;
  flex-direction: column;
  padding: 18px 16px;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.mobile-drawer-overlay.open .mobile-drawer {
  transform: translateX(0);
}

.mobile-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.mobile-drawer-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mobile-nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.mobile-nav-item .tab-count {
  margin-left: auto;
}

.mobile-nav-item:hover {
  background: var(--surface-alt);
}

.mobile-nav-item.active {
  background: var(--primary-soft);
  border-color: #bfdbfe;
  color: var(--primary-dark);
}

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

.mobile-nav-item.active .tab-count {
  background: var(--primary);
  color: #fff;
}

/* Mobile: hamburger bar + tablas convertidas en cards */
@media (max-width: 768px) {
  .topbar-inner:has(.hamburger-btn) {
    flex-wrap: nowrap;
    gap: 12px;
    padding: 10px 14px;
  }

  .topbar-inner:has(.hamburger-btn) .brand {
    min-width: 0;
    flex: 1;
    gap: 10px;
  }

  .topbar-inner:has(.hamburger-btn) .brand > div {
    min-width: 0;
  }

  .topbar-inner:has(.hamburger-btn) .brand .subtitle {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .hamburger-btn {
    display: inline-flex;
    flex-shrink: 0;
  }

  .folder-tabs {
    display: none;
  }

  .folder-panel-shell {
    border-radius: var(--radius);
    padding: 14px;
  }

  .folder-panel-shell .card {
    padding: 14px;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .responsive-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
  }

  .responsive-table tbody tr:hover {
    background: var(--surface);
  }

  .responsive-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid #f1f5f9;
    text-align: right;
  }

  .responsive-table td:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }

  .responsive-table td::before {
    content: attr(data-label);
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
    flex-shrink: 0;
  }

  .responsive-table td.empty-cell {
    display: block;
    text-align: center !important;
    border-bottom: none;
  }

  .responsive-table td.empty-cell::before {
    display: none;
  }

  .responsive-table td.actions-cell {
    width: 100%;
    padding-top: 10px;
    margin-top: 4px;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
  }

  .responsive-table td.actions-cell::before {
    display: none;
  }

  .responsive-table .actions-group {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .responsive-table .actions-group .btn:not(.btn-icon) {
    flex: 1;
    min-width: 100px;
    padding: 8px 10px;
  }

  .responsive-table .actions-group .btn-icon {
    width: 34px;
    height: 34px;
  }
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(145deg, #eef2f8 0%, #f8fafc 60%, #eff6ff 100%);
}

.login-wrapper {
  width: 100%;
  max-width: 420px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.04);
  padding: 32px 28px 28px;
}

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

.login-brand .brand-badge {
  display: inline-block;
  margin-bottom: 10px;
}

.login-brand h1 {
  margin: 0 0 4px;
  font-size: 1.3rem;
  color: var(--primary-dark);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-error {
  background: var(--false-bg);
  border: 1px solid #fecaca;
  color: var(--false-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.86rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.password-box {
  position: relative;
  display: flex;
  align-items: center;
}

.password-box input {
  width: 100%;
  padding-right: 40px;
}

.password-toggle {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.password-toggle:hover {
  color: var(--primary);
  background: var(--surface-alt);
}

.turnstile-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 68px;
  padding: 4px 0;
}

.turnstile-loading {
  font-size: 0.82rem;
  margin: 0;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

.topbar-right-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.mobile-drawer-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
  .desktop-logout-btn {
    display: none;
  }
}

/* Impresión */
@media print {
  body {
    background: #fff;
    color: #000;
  }
  .no-print {
    display: none !important;
  }
  .container {
    max-width: 100%;
    margin: 0;
    padding: 0;
  }
  .card.printable-sheet,
  .folder-panel-shell {
    border: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
  }
  .sheet-patient-info {
    padding: 6px 10px;
    margin-bottom: 10px;
    font-size: 8.5pt;
    grid-template-columns: repeat(3, 1fr);
    background: #fff;
  }
  .answer-grid-wrapper {
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    overflow: visible;
  }
  .answer-col-table {
    font-size: 7pt;
  }
  .answer-col-table th {
    background: #e2e8f0 !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .answer-col-table th,
  .answer-col-table td {
    padding: 1.5px 2px;
    border: 1px solid #94a3b8;
  }
  .answer-col-table td.cell-v,
  .answer-col-table td.cell-f {
    background: #fff !important;
    color: #000 !important;
  }
}
