:root {
  --navy: #172b4d;
  --navy-2: #1e3a5f;
  --accent: #c00000;
  --bg: #f2f4f7;
  --card: #ffffff;
  --line: #d9dee6;
  --text: #1f2937;
  --muted: #64748b;
  --ok: #16a34a;
  --warn: #d97706;
  --info: #2563eb;
  --err: #dc2626;
}

body.paleta-rojo { --navy: #7c1d1d; --navy-2: #902424; --accent: #b91c1c; }
body.paleta-verde { --navy: #14532d; --navy-2: #1a6b3a; --accent: #15803d; }
body.paleta-morado { --navy: #4c1d95; --navy-2: #5b21b6; --accent: #6d28d9; }
body.paleta-amarillo { --navy: #7a5d0f; --navy-2: #8d6b13; --accent: #ca8a04; }

* { box-sizing: border-box; }

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

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

header.topbar {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 6px 20px;
  min-height: 56px;
}

header.topbar .brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #fff;
  text-decoration: none;
  line-height: 1.05;
  max-width: 240px;
  min-width: 64px;
}
header.topbar .brand img.brand-logo { height: 26px; max-width: 230px; width: auto; object-fit: contain; display: block; }
header.topbar .brand .brand-text { font-weight: 700; font-size: 12px; letter-spacing: .3px; white-space: nowrap; }

header.topbar nav { display: flex; gap: 4px; flex: 1; align-items: center; }
header.topbar nav a {
  color: #c7d2e0;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}
header.topbar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
header.topbar nav .separator { flex: 1; }

.user-info {
  font-size: 12px;
  text-align: right;
  color: #c7d2e0;
  white-space: nowrap;
}
.user-info b { color: #fff; display: block; font-size: 12.5px; }

main.content { width: 100%; max-width: 1280px; margin: 0 auto; padding: 22px 20px 40px; }

.flashes { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; border: 1px solid transparent; }
.flash.ok { background: #e8f7ee; color: #14532d; border-color: #bbf7d0; }
.flash.error { background: #fdecec; color: #7f1d1d; border-color: #fecaca; }
.flash.info { background: #eaf2ff; color: #1e3a5f; border-color: #bfdbfe; }
.flash.warning { background: #fef6e6; color: #78350f; border-color: #fde9b0; }

h1.titulo { font-size: 22px; margin: 0 0 4px; color: var(--navy); }
.subtitulo { color: var(--muted); margin: 0 0 18px; }

.estado { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.estado.PENDIENTE { background: #e2e8f0; color: #475569; }
.estado.BORRADOR { background: #fef3c7; color: #92400e; }
.estado.ENVIADA { background: #dbeafe; color: #1d4ed8; }
.estado.REVISADA { background: #dcfce7; color: #166534; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card h2 { margin: 0 0 10px; font-size: 15px; color: var(--navy); }
.card .hint { color: var(--muted); font-size: 12.5px; }

table.tabla { width: 100%; border-collapse: collapse; }
table.tabla th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); }
table.tabla td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }

.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { background: #fff; color: var(--err); border-color: #fecaca; }
.btn.danger:hover { background: #fdecec; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

form.fila { display: flex; gap: 10px; align-items: flex-end; }
form.inline { display: inline; }
label.campo { display: block; margin-bottom: 12px; }
label.campo span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
label.campo input, label.campo select, label.campo textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff;
}
label.campo input:focus, label.campo select:focus, label.campo textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--info); }
textarea { resize: vertical; min-height: 60px; }
.checkline { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.fichas { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.ficha { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.ficha h3 { margin: 0 0 4px; font-size: 15px; color: var(--navy); }
.ficha .barra { height: 8px; background: #eef2f7; border-radius: 99px; margin: 10px 0 6px; overflow: hidden; }
.ficha .barra > div { height: 100%; background: var(--info); border-radius: 99px; }
.ficha .meta { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }

/* Cuestionarios */
.cuestionario-wrap h2.dom { margin: 22px 0 8px; font-size: 15px; color: var(--navy); border-left: 4px solid var(--accent); padding-left: 10px; }
.cuestionario-wrap h2.dom:first-child { margin-top: 4px; }
table.preguntas th {
  background: var(--navy); color: #fff; font-size: 13px; text-transform: uppercase; letter-spacing: .4px; padding: 8px 10px; text-align: left;
}
table.preguntas td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.preguntas .preg { min-width: 260px; max-width: 420px; }
table.preguntas .preg strong { display: block; font-size: 13px; }
table.preguntas .valor-cell { white-space: nowrap; }
select.valor {
  padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line); background: #fff; font-weight: 600;
}
select.valor[data-val="SI"] { color: #166534; }
select.valor[data-val="N/A"] { color: #92400e; }
select.valor[data-val="NO"] { color: #991b1b; }

.guardado { color: var(--ok); font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.leido { color: var(--muted); font-size: 12px; font-weight: 600; }

.acciones-cabecera { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 14px 0; }

.pill { display: inline-block; background: #eef2f7; border-radius: 6px; padding: 2px 8px; font-size: 12px; color: var(--navy); }

footer { font-size: 11.5px; color: var(--muted); padding: 12px 20px; border-top: 1px solid var(--line); text-align: center; }

.margen-arriba { margin-top: 18px; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.derecha { text-align: right; }
.centro { text-align: center; }

/* Personalización de marca */
.preview-bar {
  background: var(--navy); color: #fff; border-radius: 10px; padding: 10px 14px;
  display: flex; align-items: center; min-height: 56px; margin-bottom: 18px;
}
.preview-bar .brand {
  display: inline-flex; flex-direction: column; align-items: center; gap: 3px;
  color: #fff; text-decoration: none; line-height: 1.05;
}
.preview-bar .brand img { height: 26px; width: auto; max-width: 230px; object-fit: contain; display: block; }
.preview-bar .brand .brand-text { font-weight: 700; font-size: 12px; letter-spacing: .3px; white-space: nowrap; }

.paletas { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.paleta-opt {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border: 2px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 13px;
}
.paleta-opt.seleccionada { border-color: var(--navy); background: #eef2f7; }
.paleta-opt input { display: none; }
.swatch { width: 22px; height: 22px; border-radius: 6px; display: inline-block; }
.swatch-azul { background: #172b4d; }
.swatch-rojo { background: #7c1d1d; }
.swatch-verde { background: #14532d; }
.swatch-morado { background: #4c1d95; }
.swatch-amarillo { background: #7a5d0f; }