:root {
  --navy: #0f2342;
  --navy2: #1b3a6b;
  --accent: #c8a96e;
  --accent2: #e8c98a;
  --light: #f5f3ee;
  --white: #ffffff;
  --text: #1a1a2e;
  --muted: #6b7280;
  --border: #e2ddd6;
  --ok: #1e8a5a;
  --warn: #c98a12;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(15, 35, 66, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--light);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--navy2); }
img, svg { max-width: 100%; }
.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 1.25rem; }
[hidden] { display: none !important; }

/* Cabecera de cada demo */
.demo-top {
  background: linear-gradient(135deg, var(--c1, var(--navy)), var(--c2, var(--navy2)));
  color: #fff;
  padding: 1.1rem 0 1.4rem;
  position: relative;
  overflow: hidden;
}
/* Patrón de fondo por tema: se desvanece hacia la izquierda para no competir con el texto */
.demo-top::before, .con-fondo::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: var(--fondo); opacity: var(--fondo-op, 0.08);
  -webkit-mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0.15), #000 75%);
  mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0.15), #000 75%);
}
.fondo-puntos { --fondo: radial-gradient(#fff 1.1px, transparent 1.7px) 0 0 / 18px 18px; --fondo-op: 0.16; }
.fondo-cuadricula {
  --fondo: linear-gradient(#fff 1px, transparent 1px) 0 0 / 96px 96px, linear-gradient(90deg, #fff 1px, transparent 1px) 0 0 / 96px 96px,
           linear-gradient(#fff 1px, transparent 1px) 0 0 / 24px 24px, linear-gradient(90deg, #fff 1px, transparent 1px) 0 0 / 24px 24px;
  --fondo-op: 0.06;
}
.fondo-libro {
  --fondo: repeating-linear-gradient(#fff 0 1px, transparent 1px 22px), linear-gradient(90deg, #fff 1px, transparent 1px) 0 0 / 160px 100%;
  --fondo-op: 0.07;
}
.fondo-circuito {
  --fondo: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cg fill='none' stroke='%23fff' stroke-width='1.2'%3E%3Cpath d='M0 30h40l15 15h45v40l20 20h20M0 100h25l15-15h30v55M70 0v20l10 10h60M100 140v-15l10-10h30'/%3E%3C/g%3E%3Cg fill='%23fff'%3E%3Ccircle cx='40' cy='30' r='2.5'/%3E%3Ccircle cx='100' cy='45' r='2.5'/%3E%3Ccircle cx='70' cy='85' r='2.5'/%3E%3Ccircle cx='80' cy='30' r='2.5'/%3E%3Ccircle cx='110' cy='115' r='2.5'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 140px 140px;
  --fondo-op: 0.1;
}
.fondo-guilloche {
  --fondo: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='40'%3E%3Cg fill='none' stroke='%23fff' stroke-width='.8'%3E%3Cpath d='M0 20q15-20 30 0t30 0 30 0 30 0'/%3E%3Cpath d='M0 20q15 20 30 0t30 0 30 0 30 0'/%3E%3Cpath d='M0 10q15-20 30 0t30 0 30 0 30 0'/%3E%3Cpath d='M0 30q15 20 30 0t30 0 30 0 30 0'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 120px 40px;
  --fondo-op: 0.09;
}
.fondo-nodos {
  --fondo: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cg fill='none' stroke='%23fff' stroke-width='.9'%3E%3Cpath d='M20 30 90 15l50 55-80 20-40 40M90 15 60 90l50 50 30-70M15 130l95 10'/%3E%3C/g%3E%3Cg fill='%23fff'%3E%3Ccircle cx='20' cy='30' r='3'/%3E%3Ccircle cx='90' cy='15' r='3'/%3E%3Ccircle cx='140' cy='70' r='3'/%3E%3Ccircle cx='60' cy='90' r='3'/%3E%3Ccircle cx='110' cy='140' r='3'/%3E%3Ccircle cx='15' cy='130' r='3'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 160px 160px;
  --fondo-op: 0.1;
}
.demo-top-in { position: relative; z-index: 1; display: grid; gap: 0.8rem; }

/* Ilustración del lado derecho */
.demo-arte { display: none; position: absolute; right: 1.25rem; top: 50%; transform: translateY(-50%); width: 300px; height: 160px; pointer-events: none; }
.demo-arte svg { width: 100%; height: 100%; overflow: visible; }
.demo-arte.persp svg { transform: perspective(700px) rotateY(-16deg) rotateX(4deg); }
@media (min-width: 1080px) {
  .demo-arte { display: block; }
  .demo-top-in.con-arte { padding-right: 340px; }
}
.demo-arte .s { fill: rgba(255, 255, 255, 0.07); stroke: rgba(255, 255, 255, 0.28); }
.demo-arte .sd { fill: rgba(8, 14, 28, 0.32); }
.demo-arte .s2 { fill: rgba(255, 255, 255, 0.12); }
.demo-arte .l { fill: none; stroke: rgba(255, 255, 255, 0.3); }
.demo-arte .p { fill: rgba(255, 255, 255, 0.4); }
.demo-arte .calle { fill: none; stroke: rgba(255, 255, 255, 0.1); stroke-width: 7; }
.demo-arte .a { fill: none; stroke: var(--acento); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.demo-arte .a.grueso { stroke-width: 2.4; }
.demo-arte .af { fill: var(--acento); }
.demo-arte .ab { fill: color-mix(in srgb, var(--acento) 18%, transparent); stroke: var(--acento); }
.demo-arte .hl { fill: var(--acento); opacity: 0.55; }
.demo-arte .d1 { stroke: var(--acento); } .demo-arte .d1f { fill: var(--acento); }
.demo-arte .d2 { stroke: rgba(255, 255, 255, 0.6); } .demo-arte .d2f { fill: rgba(255, 255, 255, 0.6); }
.demo-arte .d3 { stroke: rgba(255, 255, 255, 0.38); } .demo-arte .d3f { fill: rgba(255, 255, 255, 0.38); }
.demo-arte .d4 { stroke: rgba(255, 255, 255, 0.2); } .demo-arte .d4f { fill: rgba(255, 255, 255, 0.2); }
.demo-arte text { fill: rgba(255, 255, 255, 0.78); font: 600 8.5px ui-monospace, 'SFMono-Regular', Consolas, monospace; }
.demo-arte text.c { text-anchor: middle; }
.demo-arte text.e { text-anchor: end; }
.demo-arte text.ta { fill: var(--acento); }
.demo-arte text.dim { fill: rgba(255, 255, 255, 0.5); }
.demo-arte text.tb { font-weight: 800; }
.demo-arte text.u { font-size: 7px; }
.demo-arte text.m { font: 700 11px 'DM Sans', sans-serif; }
.demo-arte text.big { font: 700 34px 'DM Sans', sans-serif; fill: #fff; letter-spacing: 0.02em; }
.demo-arte text.k { font: 700 19px 'DM Sans', sans-serif; fill: #fff; }
.demo-arte text.k2 { font: 700 13px 'DM Sans', sans-serif; fill: #fff; }
.demo-arte text.k3 { font: 700 13px 'DM Sans', sans-serif; fill: #fff; }
.demo-arte .pulso { animation: arte-pulso 1.6s ease-in-out infinite; }
@keyframes arte-pulso { 50% { opacity: 0.3; } }

.demo-tags .insignia { display: inline-flex; align-items: center; gap: 0.4rem; background: rgba(0, 0, 0, 0.22); border-color: rgba(74, 222, 128, 0.45); text-transform: uppercase; letter-spacing: 0.08em; }
.demo-tags .insignia i { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); animation: en-vivo 1.8s ease-out infinite; }
@keyframes en-vivo { 70% { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0); } 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); } }
@media (prefers-reduced-motion: reduce) { .demo-arte .pulso, .demo-tags .insignia i { animation: none; } }
.volver {
  color: rgba(255, 255, 255, 0.85); text-decoration: none; font-size: 0.85rem; font-weight: 600;
  width: fit-content; padding: 0.3rem 0.8rem; border-radius: 100px; background: rgba(255, 255, 255, 0.12);
  transition: background 0.2s;
}
.volver:hover { background: rgba(255, 255, 255, 0.24); color: #fff; }
.demo-tit { display: flex; gap: 1rem; align-items: center; }
.demo-ico {
  font-size: 2rem; width: 58px; height: 58px; flex-shrink: 0; border-radius: 16px;
  display: grid; place-items: center; background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18); color: #fff;
}
.demo-ico svg { width: 28px; height: 28px; }
.demo-tit h1 { font-family: 'Playfair Display', serif; font-size: clamp(1.4rem, 3vw, 2rem); line-height: 1.15; }
.demo-tit p { opacity: 0.85; font-size: 0.92rem; max-width: 760px; }
.demo-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.demo-tags span {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em; padding: 0.22rem 0.65rem;
  border-radius: 100px; background: rgba(255, 255, 255, 0.16); border: 1px solid rgba(255, 255, 255, 0.22);
}

.demo-tags .vistas { display: inline-flex; align-items: center; gap: 0.3rem; background: rgba(0, 0, 0, 0.18); border-color: transparent; margin-left: auto; }

.demo-main { flex: 1; padding-top: 1.6rem; padding-bottom: 2.5rem; }
.demo-pie { text-align: center; padding: 1.4rem 0; font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--border); background: #fff; }
.demo-pie a { color: var(--navy2); font-weight: 600; text-decoration: none; }
.demo-pie a:hover { text-decoration: underline; }

/* Bloques */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; border: 1px solid rgba(226, 221, 214, 0.6); }
.card h2, .card h3 { font-family: 'Playfair Display', serif; color: var(--navy); }
.card h2 { font-size: 1.25rem; margin-bottom: 0.8rem; }
.card h3 { font-size: 1.05rem; margin-bottom: 0.6rem; }
.grid { display: grid; gap: 1.1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.fila { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.entre { justify-content: space-between; }
.mt { margin-top: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.nota {
  font-size: 0.82rem; color: var(--navy2); background: #edf2fb; border-left: 3px solid var(--navy2);
  padding: 0.6rem 0.85rem; border-radius: 8px;
}

/* Indicadores */
.kpi { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.15rem; border-top: 3px solid var(--accent); }
.kpi small { display: block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.kpi strong { display: block; font-size: 1.55rem; color: var(--navy); font-weight: 700; line-height: 1.25; margin-top: 0.15rem; }
.kpi span { font-size: 0.78rem; color: var(--muted); }
.kpi.ok { border-top-color: var(--ok); }
.kpi.warn { border-top-color: var(--warn); }
.kpi.danger { border-top-color: var(--danger); }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: 600 0.86rem 'DM Sans', sans-serif; padding: 0.6rem 1.05rem; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  background: var(--navy); color: #fff; transition: transform 0.15s, background 0.2s, box-shadow 0.2s;
}
.btn:hover { background: var(--navy2); box-shadow: 0 4px 14px rgba(15, 35, 66, 0.2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.btn-accent { background: var(--accent); color: var(--navy); }
.btn-accent:hover { background: var(--accent2); }
.btn-light { background: #fff; color: var(--navy); border-color: var(--border); }
.btn-light:hover { background: var(--light); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #a93226; }
.btn-ok { background: var(--ok); }
.btn-ok:hover { background: #17724a; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.78rem; border-radius: 8px; }
.btn-icon { padding: 0.35rem 0.55rem; }
.btn-block { width: 100%; }

/* Formularios */
.campo { display: grid; gap: 0.3rem; }
.campo label, .etq { font-size: 0.78rem; font-weight: 600; color: var(--navy); }
input, select, textarea {
  font: 400 0.9rem 'DM Sans', sans-serif; color: var(--text);
  padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: 10px; background: #fff; width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--navy2); box-shadow: 0 0 0 3px rgba(27, 58, 107, 0.12); }
input[type="checkbox"], input[type="radio"], input[type="color"] { width: auto; }
textarea { resize: vertical; min-height: 80px; }
.error-campo { color: var(--danger); font-size: 0.76rem; }

/* Tablas */
.tabla-wrap { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
.tabla th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  padding: 0.65rem 0.75rem; border-bottom: 2px solid var(--border); white-space: nowrap;
}
.tabla td { padding: 0.65rem 0.75rem; border-bottom: 1px solid #f0ece6; vertical-align: middle; }
.tabla tbody tr:hover { background: #faf8f4; }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; }
.vacio { text-align: center; color: var(--muted); padding: 2rem 1rem !important; }

/* Etiquetas */
.badge { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 0.18rem 0.6rem; border-radius: 100px; background: #edf2fb; color: var(--navy2); white-space: nowrap; }
.badge.ok { background: #e3f4ec; color: var(--ok); }
.badge.warn { background: #fdf2dc; color: #9a6a0c; }
.badge.danger { background: #fbe5e2; color: var(--danger); }
.badge.gold { background: #f6ecd8; color: #7a5c1e; }

/* Chips de filtro */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  font: 600 0.8rem 'DM Sans', sans-serif; padding: 0.4rem 0.9rem; border-radius: 100px; cursor: pointer;
  border: 1px solid var(--border); background: #fff; color: var(--navy); transition: all 0.2s;
}
.chip:hover { border-color: var(--navy2); }
.chip.activo { background: var(--navy); border-color: var(--navy); color: #fff; }

/* Ventana modal */
.modal {
  position: fixed; inset: 0; z-index: 1000; background: rgba(15, 35, 66, 0.55);
  display: grid; place-items: center; padding: 1rem; animation: aparecer 0.2s ease;
}
.modal-box {
  background: #fff; border-radius: 18px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  padding: 1.4rem; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3); animation: subir 0.25s ease;
}
.modal-box h2 { font-family: 'Playfair Display', serif; color: var(--navy); font-size: 1.3rem; margin-bottom: 1rem; }
.modal-acciones { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.2rem; flex-wrap: wrap; }

/* Aviso flotante */
#toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 20px); z-index: 2000; opacity: 0; pointer-events: none;
  background: var(--navy); color: #fff; padding: 0.7rem 1.2rem; border-radius: 12px; font-size: 0.88rem; font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); transition: transform 0.3s ease, opacity 0.3s ease; max-width: calc(100% - 2rem); text-align: center;
}
#toast.visible { transform: translate(-50%, 0); opacity: 1; }
#toast.ok { background: var(--ok); }
#toast.error { background: var(--danger); }

/* Gráfico de dona */
.dona { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; justify-content: center; }
.dona svg { width: 180px; height: 180px; flex-shrink: 0; }
.dona svg circle { transition: stroke-width 0.2s; }
.dona svg circle:hover { stroke-width: 34; }
.leyenda { display: grid; gap: 0.35rem; font-size: 0.82rem; min-width: 160px; }
.leyenda div { display: flex; align-items: center; gap: 0.5rem; }
.leyenda i { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.leyenda b { margin-left: auto; font-variant-numeric: tabular-nums; }

.cargando { display: inline-block; width: 18px; height: 18px; border: 2px solid rgba(15, 35, 66, 0.2); border-top-color: var(--navy); border-radius: 50%; animation: girar 0.7s linear infinite; }

@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }
@keyframes subir { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes girar { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .demo-ico { width: 48px; height: 48px; font-size: 1.6rem; }
  .demo-ico svg { width: 24px; height: 24px; }
  .card { padding: 1rem; }
}
