:root {
  --bg: #f7efe2;
  --bg-soft: #fffaf1;
  --panel: #fffdf8;
  --ink: #1f241f;
  --muted: #6f6a5f;
  --brand: #183d34;
  --brand-2: #24584b;
  --gold: #d6b56d;
  --gold-soft: #efe2bd;
  --brown: #6f4e37;
  --danger: #9f2f2f;
  --warn: #9a6b00;
  --ok: #1b6b4a;
  --line: rgba(31, 36, 31, .12);
  --shadow: 0 14px 40px rgba(24, 61, 52, .12);
  --radius: 18px;
  --radius-sm: 12px;
  --font-title: Georgia, 'Times New Roman', serif;
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: radial-gradient(circle at top left, rgba(214,181,109,.22), transparent 36%), var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  min-height: 100vh;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-header {
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: rgba(255, 253, 248, .92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.brand-icon { width: 48px; height: 48px; border-radius: 14px; box-shadow: var(--shadow); }
.brand strong { display: block; font-family: var(--font-title); font-size: 1.35rem; letter-spacing: .02em; color: var(--brand); }
.brand span { display: block; font-size: .83rem; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 10px; }
.header-actions select { max-width: 330px; }

.install-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  font-size: .92rem;
}
.icon-btn {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.2rem;
  line-height: 1;
  padding: 6px 8px;
}

.app-shell { display: grid; grid-template-columns: 278px 1fr; min-height: calc(100vh - 74px); }
.sidebar {
  background: rgba(255, 250, 241, .76);
  border-right: 1px solid var(--line);
  padding: 16px;
  position: sticky;
  top: 74px;
  height: calc(100vh - 74px);
  overflow: auto;
}
.nav { display: grid; gap: 7px; }
.nav button {
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  color: var(--ink);
  padding: 11px 12px;
  border-radius: 12px;
  transition: .15s ease;
}
.nav button:hover { background: rgba(214,181,109,.13); }
.nav button.active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 8px 24px rgba(24, 61, 52, .18);
}
.sidebar-footer {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.sidebar-footer span,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(214,181,109,.2);
  color: var(--brand);
  border: 1px solid rgba(214,181,109,.36);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: .78rem;
  font-weight: 700;
}
.badge.ok { color: var(--ok); background: rgba(27,107,74,.1); border-color: rgba(27,107,74,.18); }
.badge.warn { color: var(--warn); background: rgba(154,107,0,.1); border-color: rgba(154,107,0,.18); }
.badge.danger { color: var(--danger); background: rgba(159,47,47,.1); border-color: rgba(159,47,47,.18); }
.badge.neutral { color: var(--muted); background: rgba(31,36,31,.05); border-color: var(--line); }

.main { padding: 24px; max-width: 1500px; width: 100%; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0 0 7px; font-family: var(--font-title); color: var(--brand); font-size: clamp(1.85rem, 3vw, 2.6rem); }
.page-head p { margin: 0; color: var(--muted); max-width: 800px; line-height: 1.5; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card h2, .card h3 { margin-top: 0; color: var(--brand); }
.card h2 { font-family: var(--font-title); font-size: 1.55rem; }
.card h3 { font-size: 1.08rem; }
.card p, .muted { color: var(--muted); line-height: 1.55; }
.compact p { margin: .35rem 0; }

.stat {
  padding: 18px;
  background: linear-gradient(145deg, rgba(255,253,248,.98), rgba(239,226,189,.28));
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.stat span { color: var(--muted); font-size: .82rem; }
.stat strong { display: block; margin-top: 7px; font-size: 2.15rem; color: var(--brand); }

.stage-list { display: grid; gap: 8px; }
.stage-item {
  display: grid;
  grid-template-columns: 25px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.42);
}
.stage-dot { width: 14px; height: 14px; border-radius: 999px; background: rgba(31,36,31,.18); }
.stage-item.done .stage-dot { background: var(--ok); }
.stage-item.current { border-color: rgba(214,181,109,.8); background: rgba(214,181,109,.14); }
.stage-item.current .stage-dot { background: var(--gold); }
.stage-item small { color: var(--muted); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row { display: grid; gap: 7px; margin-bottom: 13px; }
.form-row label { font-size: .86rem; color: var(--brand); font-weight: 800; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf8;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(214,181,109,.2); }
.checkbox-row { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0; color: var(--ink); }
.checkbox-row input { width: auto; margin-top: 4px; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
  transition: .16s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); transform: translateY(-1px); }
.btn-secondary { background: var(--gold-soft); color: var(--brand); border-color: rgba(214,181,109,.45); }
.btn-secondary:hover { background: #ead7a3; }
.btn-ghost { background: transparent; color: var(--brand); border-color: var(--line); }
.btn-ghost:hover { background: rgba(214,181,109,.12); }
.btn-danger { background: rgba(159,47,47,.1); color: var(--danger); border-color: rgba(159,47,47,.22); }
.btn-light { background: #fff; color: var(--brand); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.client-card { display: grid; gap: 10px; }
.client-card header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.client-card h3 { margin: 0; font-size: 1.12rem; }
.client-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: .85rem; color: var(--muted); }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; background: #fffdf8; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--brand); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; background: rgba(214,181,109,.16); }
tr:last-child td { border-bottom: 0; }

.output-box, pre.output-box {
  white-space: pre-wrap;
  background: #132c26;
  color: #f7efe2;
  border-radius: 14px;
  padding: 16px;
  line-height: 1.55;
  overflow: auto;
  max-height: 560px;
  border: 1px solid rgba(247,239,226,.1);
}
.output-box.light {
  background: #fffaf1;
  color: var(--ink);
  border: 1px solid var(--line);
}

.question-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.5);
  padding: 14px;
  margin-bottom: 12px;
}
.question-item strong { color: var(--brand); }
.question-item textarea { min-height: 88px; margin-top: 8px; }

.file-drop {
  border: 2px dashed rgba(24,61,52,.25);
  background: rgba(214,181,109,.1);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
}
.file-drop.drag { border-color: var(--gold); background: rgba(214,181,109,.2); }
.recording { color: var(--danger); font-weight: 900; }
.audio-list audio { width: 100%; margin-top: 8px; }

.timeline { display: grid; gap: 10px; }
.timeline-item {
  border-left: 4px solid var(--gold);
  padding: 10px 12px;
  background: rgba(214,181,109,.1);
  border-radius: 0 12px 12px 0;
}
.timeline-item strong { display: block; color: var(--brand); }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--brand);
  color: #fff;
  padding: 13px 16px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: 420px;
}
.empty-state {
  max-width: 620px;
  margin: 12vh auto;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 36px;
}
.empty-state h2 { font-family: var(--font-title); color: var(--brand); }

.print-area { background: #fff; color: #111; padding: 28px; border-radius: 12px; border: 1px solid var(--line); }
.print-area h1, .print-area h2 { color: #111; }
.placa-preview {
  border: 2px solid #8d6f31;
  background: linear-gradient(135deg, #c99b42, #f2d28a 45%, #9a7130);
  color: #2b1d0f;
  min-height: 220px;
  border-radius: 18px;
  padding: 24px;
  display: grid;
  place-items: center;
  text-align: center;
  box-shadow: inset 0 0 40px rgba(0,0,0,.18), var(--shadow);
}
.placa-preview strong { display:block; font-family: var(--font-title); font-size: 1.9rem; margin-bottom: 10px; }
.placa-preview span { display:block; font-size: 1.05rem; }
.qr-placeholder {
  width: 96px;
  height: 96px;
  margin: 16px auto 0;
  background: repeating-linear-gradient(45deg, #2b1d0f 0 6px, transparent 6px 12px), #fff7df;
  border: 8px solid #fff7df;
  border-radius: 6px;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.three, .grid.four, .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .app-header { height: auto; align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; flex-wrap: wrap; }
  .header-actions select { max-width: none; }
}

@media (max-width: 600px) {
  .main { padding: 14px; }
  .nav { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
  .actions { align-items: stretch; }
  .btn { justify-content: center; width: 100%; }
}

@media print {
  body { background: #fff; }
  .app-header, .sidebar, .actions, .toast, .install-banner { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; }
  .print-area { border: 0; padding: 0; }
}

/* ── Mejoras adicionales v1.1 ── */
.sensibilidad-alta { border-left: 4px solid var(--danger); }
.sensibilidad-media { border-left: 4px solid var(--warn); }
.sensibilidad-baja { border-left: 4px solid var(--ok); }
.log-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; background: rgba(255,255,255,.4); }
.log-item small { color: var(--muted); font-size: .8rem; }
.nav button svg { vertical-align: middle; margin-right: 7px; }
.btn-sm { padding: 6px 10px; font-size: .83rem; border-radius: 9px; }
.tag { display: inline-flex; align-items: center; background: rgba(214,181,109,.18); color: var(--brand); border: 1px solid rgba(214,181,109,.3); border-radius: 999px; padding: 3px 9px; font-size: .78rem; font-weight: 700; gap: 5px; }
select option:disabled { color: var(--muted); }
@media (max-width: 600px) { .grid.four { grid-template-columns: repeat(2, 1fr); } }
