/* ===================== Variables de marca Protexa ===================== */
:root {
  --rojo: #f83b1d;
  --rojo-dark: #d12d12;
  --gris: #575756;
  --gris-claro: #8a8a89;
  --bg: #f4f5f7;
  --card: #ffffff;
  --borde: #d9dce1;
  --texto: #2a2a2a;
  --ok: #1e9e57;
  --warn: #c97a04;
  --warn-bg: #fff6e6;
  --error: #d12d12;
  --error-bg: #fdecea;
  --radio: 14px;
  --sombra: 0 2px 10px rgba(0,0,0,.07);
  --tap: 52px; /* altura mínima táctil */
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--texto);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
}

/* ===================== Header ===================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--borde);
  box-shadow: var(--sombra);
}
.logo { height: 34px; width: auto; }
.icon-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
}

/* ===================== Layout pantallas ===================== */
#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px 96px;
}
.screen { animation: fade .2s ease; }
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.screen-title { font-size: 1.4rem; margin: 4px 0 6px; color: var(--gris); }
.screen-sub { color: var(--gris-claro); margin: 0 0 18px; font-size: .95rem; }
.section-title { font-size: 1.1rem; margin: 28px 0 4px; color: var(--gris); }

/* ===================== Campos de formulario ===================== */
.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

label {
  display: block;
  font-weight: 600;
  font-size: .92rem;
  margin-bottom: 6px;
  color: var(--gris);
}
input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  font-size: 1rem;
  border: 1.5px solid var(--borde);
  border-radius: var(--radio);
  background: var(--card);
  color: var(--texto);
  font-family: inherit;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--rojo);
  box-shadow: 0 0 0 3px rgba(248,59,29,.12);
}
.field.invalid input,
.field.invalid select,
.field.invalid textarea { border-color: var(--error); }
.hint { display: block; color: var(--gris-claro); font-size: .8rem; margin-top: 4px; }
.error-msg { display: none; color: var(--error); font-size: .82rem; margin-top: 5px; }
.error-msg.show { display: block; }

/* ===================== Pantalla 1: tipo ===================== */
.tipo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 10px;
}
.tipo-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 130px;
  padding: 16px;
  border: 2px solid var(--borde);
  border-radius: 18px;
  background: var(--card);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gris);
  cursor: pointer;
  box-shadow: var(--sombra);
}
.tipo-btn .tipo-ico { font-size: 2.4rem; }
.tipo-btn--active { border-color: var(--rojo); color: var(--rojo); }
.tipo-btn--active:active { transform: scale(.98); }
.tipo-btn:disabled { opacity: .5; cursor: not-allowed; }
.badge {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--gris-claro);
  color: #fff;
  font-size: .62rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 20px;
  letter-spacing: .3px;
}

/* ===================== Toggles Sí/No ===================== */
.toggle-group {
  background: var(--card);
  border: 1.5px solid var(--borde);
  border-radius: var(--radio);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--sombra);
}
.toggle-label { display: block; font-weight: 600; color: var(--gris); margin-bottom: 10px; }
.toggle-buttons { display: flex; gap: 10px; }
.toggle-btn {
  flex: 1;
  min-height: var(--tap);
  border: 2px solid var(--borde);
  border-radius: 12px;
  background: var(--card);
  font-size: 1rem;
  font-weight: 700;
  color: var(--gris);
  cursor: pointer;
}
.toggle-btn.active[data-val="si"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.toggle-btn.active[data-val="no"] { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.toggle-group.invalid { border-color: var(--error); }

.conditional {
  margin: -4px 0 16px;
  padding: 14px;
  background: #fbfbfc;
  border: 1.5px dashed var(--borde);
  border-radius: var(--radio);
}

/* ===================== Dictado ===================== */
.dictation-wrap { position: relative; }
.dictate-btn {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1.5px solid var(--rojo);
  border-radius: 30px;
  background: var(--card);
  color: var(--rojo);
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
}
.dictate-btn.recording {
  background: var(--rojo);
  color: #fff;
  animation: pulse 1.1s infinite;
}
.dictate-btn.unsupported { display: none; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(248,59,29,.5);} 50% { box-shadow: 0 0 0 8px rgba(248,59,29,0);} }

/* ===================== Uploader ===================== */
.uploader {
  background: var(--card);
  border: 1.5px solid var(--borde);
  border-radius: var(--radio);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--sombra);
}
.uploader-title { font-weight: 700; color: var(--gris); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.uploader-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.up-btn {
  flex: 1;
  min-width: 130px;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1.5px solid var(--rojo);
  border-radius: 12px;
  background: var(--card);
  color: var(--rojo);
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
}
.up-btn input[type="file"] { display: none; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 10px; margin-top: 12px; }
.thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--borde);
  background: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .pdf-ico { font-size: 1.8rem; color: var(--gris); }
.thumb .thumb-name { position: absolute; bottom: 0; left: 0; right: 0; font-size: .55rem; background: rgba(0,0,0,.55); color: #fff; padding: 2px 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb-remove {
  position: absolute;
  top: 3px; right: 3px;
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: .9rem;
  line-height: 1;
  cursor: pointer;
}
.up-count { font-size: .8rem; color: var(--gris-claro); margin-top: 8px; }

/* ===================== Botones / Nav ===================== */
.btn {
  min-height: var(--tap);
  padding: 12px 20px;
  border-radius: 30px;
  border: 2px solid transparent;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary { background: var(--rojo); color: #fff; }
.btn-primary:active { background: var(--rojo-dark); }
.btn-primary:disabled { background: var(--gris-claro); cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--gris); border-color: var(--borde); }
.btn-block { width: 100%; margin-top: 18px; }
.nav-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--borde);
}
.nav-bar .btn-primary { flex: 2; }
.nav-bar .btn-ghost { flex: 1; }

/* ===================== Resumen / Borrador ===================== */
.resumen-card, .borrador-card {
  background: var(--card);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--sombra);
}
.resumen-card h3, .borrador-card h3 { margin: 0 0 8px; font-size: 1rem; color: var(--rojo); }
.resumen-row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px dashed #eee; font-size: .92rem; }
.resumen-row:last-child { border-bottom: none; }
.resumen-row .k { color: var(--gris-claro); }
.resumen-row .v { font-weight: 600; text-align: right; word-break: break-word; }
.resumen-text { font-size: .92rem; white-space: pre-wrap; color: var(--texto); }
.borrador-card label { font-size: .8rem; color: var(--gris-claro); }
.borrador-card textarea { min-height: 70px; }

/* ===================== Alertas ===================== */
.alert { border-radius: var(--radio); padding: 12px 14px; margin: 12px 0; font-size: .9rem; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert-error { background: var(--error-bg); color: var(--error); border: 1px solid #f3b4ad; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f0d49a; }

/* ===================== Éxito ===================== */
#exito-view { text-align: center; padding-top: 24px; }
.exito-icon { font-size: 3.4rem; }
.exito-links { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.exito-links a {
  display: block;
  min-height: var(--tap);
  line-height: 28px;
  padding: 12px;
  border: 1.5px solid var(--rojo);
  border-radius: 12px;
  color: var(--rojo);
  font-weight: 600;
  text-decoration: none;
}

/* ===================== Overlay ===================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(255,255,255,.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}
.overlay p { margin: 0; font-weight: 600; color: var(--gris); }
.overlay-sub { font-weight: 400 !important; color: var(--gris-claro) !important; font-size: .88rem; }
.spinner {
  width: 54px; height: 54px;
  border: 5px solid #eee;
  border-top-color: var(--rojo);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== Modal ===================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal-card {
  background: var(--card);
  border-radius: 18px;
  padding: 20px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h2 { margin: 0 0 4px; color: var(--gris); }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 8px; }

/* ===================== Desktop tweaks ===================== */
@media (min-width: 600px) {
  .nav-bar { border-radius: 16px 16px 0 0; }
}
