/* HealthBI · Demo — estilo minimal inspirado en Vercel */
:root {
  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --panel: #ffffff;
  --border: #eaeaea;
  --border-strong: #d4d4d4;
  --fg: #0a0a0a;
  --fg-muted: #666666;
  --fg-faint: #8f8f8f;
  --coral: #F94E58;
  --blue: #45D9F0;
  --amber: #f5a623;
  --green: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px -12px rgba(0,0,0,0.10);
}

* { box-sizing: border-box; }
/* El atributo hidden debe ganarle a las reglas display:flex de abajo */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-subtle);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
.mono { font-family: 'Geist Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }

.demo { display: flex; flex-direction: column; min-height: 100vh; }

/* Topbar */
.demo-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.85rem 1.25rem;
  background: rgba(255,255,255,0.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.demo-brand { display: flex; align-items: center; gap: 0.55rem; font-size: 0.95rem; }
.demo-logo { font-weight: 700; letter-spacing: -0.01em; }
.demo-sep { color: var(--border-strong); }
.demo-hospital { color: var(--fg-muted); font-weight: 500; }
.demo-controls { display: flex; align-items: center; gap: 1rem; }
.demo-select { display: flex; align-items: center; gap: 0.5rem; }
.demo-select label { font-size: 0.72rem; color: var(--fg-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.demo-select select {
  font-family: inherit; font-size: 0.82rem; color: var(--fg);
  padding: 0.35rem 1.8rem 0.35rem 0.7rem; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.6rem center;
}
.demo-live { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.72rem; font-weight: 600; color: var(--coral); }
.demo-live i { width: 7px; height: 7px; border-radius: 50%; background: var(--coral); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.6); opacity: 0.35; } }

/* Main */
.demo-main { flex: 1; padding: 1.25rem; }
.view-head { margin-bottom: 1rem; }
.view-title { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.view-sub { font-size: 0.82rem; color: var(--fg-muted); margin: 0.2rem 0 0; }

/* Grid + cards */
.grid { display: grid; gap: 0.85rem; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.span-2 { grid-column: span 2; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.card:hover { box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.65rem; }
.card-title { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-faint); }
.card-tag { font-size: 0.68rem; padding: 0.12rem 0.5rem; border-radius: 999px; background: var(--bg-subtle); border: 1px solid var(--border); color: var(--fg-muted); }

/* KPI */
.kpi { display: flex; flex-direction: column; gap: 0.15rem; }
.kpi-val { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.kpi-label { font-size: 0.75rem; color: var(--fg-muted); }
.kpi-delta { font-size: 0.72rem; font-weight: 600; margin-top: 0.15rem; }
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--coral); }

/* Charts */
.chart { width: 100%; height: 240px; }
.chart.sm { height: 190px; }
.chart.lg { height: 300px; }

/* Alertas / listas */
.alerts { display: flex; flex-direction: column; gap: 0.55rem; }
.alert { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.82rem; line-height: 1.35; }
.alert i { width: 8px; height: 8px; border-radius: 50%; margin-top: 0.4rem; flex-shrink: 0; }
.alert.warn i { background: var(--amber); }
.alert.info i { background: var(--blue); }
.alert.good i { background: var(--green); }

/* Tags de temas (IA) */
.themes { display: flex; flex-direction: column; gap: 0.5rem; }
.theme { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.5rem 0.7rem; border-radius: 8px; background: var(--bg-subtle); border: 1px solid var(--border); font-size: 0.82rem; }
.theme .n { font-weight: 600; color: var(--fg-muted); }
.theme.pos { border-left: 3px solid var(--green); }
.theme.neg { border-left: 3px solid var(--coral); }

/* Comentarios */
.quotes { display: flex; flex-direction: column; gap: 0.7rem; }
.quote { font-size: 0.85rem; line-height: 1.4; }
.quote .meta { display: block; font-size: 0.72rem; color: var(--fg-faint); margin-top: 0.25rem; }
.quote.pos { border-left: 3px solid var(--green); padding-left: 0.7rem; }
.quote.neg { border-left: 3px solid var(--coral); padding-left: 0.7rem; }

/* Mini stat row inside a card */
.ministat { display: flex; gap: 1.5rem; }
.ministat > div span { display: block; }
.ministat .m-val { font-size: 1.15rem; font-weight: 700; }
.ministat .m-lbl { font-size: 0.72rem; color: var(--fg-muted); }

/* Footer */
.demo-foot { padding: 0.7rem 1.25rem; font-size: 0.7rem; color: var(--fg-faint); border-top: 1px solid var(--border); background: #fff; }

/* Entrada */
.card, .kpi { animation: fadeUp 0.5s cubic-bezier(0.22,1,0.36,1) both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 720px) {
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}

/* Segmented control (granularidad) */
.demo-seg { display: inline-flex; background: #f0f0f0; border-radius: 8px; padding: 2px; }
.demo-seg button {
  font: inherit; font-size: 0.78rem; font-weight: 500; color: var(--fg-muted);
  border: none; background: transparent; padding: 0.3rem 0.7rem; border-radius: 6px; cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.demo-seg button:hover { color: var(--fg); }
.demo-seg button.is-active { background: #fff; color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

/* Botón período personalizado + rango */
.demo-custom {
  font: inherit; font-size: 0.78rem; font-weight: 500; color: var(--fg-muted);
  border: 1px solid var(--border); background: #fff; padding: 0.35rem 0.7rem; border-radius: 8px; cursor: pointer;
}
.demo-custom:hover { color: var(--fg); border-color: var(--border-strong); }
.demo-range { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; color: var(--fg-muted); }
.demo-range input[type="date"] { font: inherit; font-size: 0.76rem; padding: 0.28rem 0.4rem; border: 1px solid var(--border); border-radius: 6px; color: var(--fg); }
.demo-range button { font: inherit; font-size: 0.76rem; font-weight: 600; color: #fff; background: var(--coral); border: none; padding: 0.32rem 0.7rem; border-radius: 6px; cursor: pointer; }

/* view-head con acciones */
.view-head--row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.view-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.btn-ghost {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font: inherit; font-size: 0.8rem; font-weight: 500; color: var(--fg-muted);
  border: 1px solid var(--border); background: #fff; padding: 0.4rem 0.75rem; border-radius: 8px; cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.btn-ghost:hover { color: var(--fg); border-color: var(--border-strong); }
.btn-ghost svg { width: 15px; height: 15px; }
.btn-ghost--primary { color: #fff; background: var(--coral); border-color: var(--coral); }
.btn-ghost--primary:hover { color: #fff; background: #e23c46; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 16px);
  background: #0a0a0a; color: #fff; font-size: 0.82rem; padding: 0.65rem 1.1rem; border-radius: 10px;
  box-shadow: 0 12px 30px -10px rgba(0,0,0,0.4); opacity: 0; transition: opacity 0.25s ease, transform 0.25s ease; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,10,10,0.4); backdrop-filter: blur(2px); }
.modal-box {
  position: relative; width: 100%; max-width: 720px; max-height: 80vh; overflow: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 30px 60px -20px rgba(0,0,0,0.35);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; }
.modal-head h3 { margin: 0; font-size: 1rem; }
.modal-x { border: none; background: transparent; font-size: 1.4rem; line-height: 1; color: var(--fg-faint); cursor: pointer; }
.modal-body { padding: 1rem 1.25rem; }
.enc-grid { display: grid; gap: 0; font-size: 0.82rem; }
.enc-head, .enc-row { display: grid; grid-template-columns: 56px 1.1fr 1fr 48px 2fr; gap: 0.6rem; align-items: center; padding: 0.55rem 0; border-bottom: 1px solid var(--border); }
.enc-head { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--fg-faint); font-weight: 600; }
.enc-obra { color: var(--fg-muted); }
.enc-nps { font-weight: 700; text-align: center; border-radius: 6px; padding: 0.1rem 0; }
.enc-nps.good { color: var(--green); background: rgba(22,163,74,0.1); }
.enc-nps.mid { color: var(--amber); background: rgba(245,166,35,0.12); }
.enc-nps.bad { color: var(--coral); background: rgba(249,78,88,0.1); }
.enc-txt { color: var(--fg-muted); }

/* Informe detallado */
.inf-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 1.25rem;
  padding: 0.9rem 1rem; margin-bottom: 0.85rem;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
}
.inf-groupby { display: flex; align-items: center; gap: 0.5rem; }
.inf-groupby label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--fg-faint); font-weight: 600; }
.inf-groupby select {
  font: inherit; font-size: 0.82rem; color: var(--fg); padding: 0.35rem 1.8rem 0.35rem 0.7rem;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.6rem center;
}
.inf-filter { display: flex; align-items: center; gap: 0.5rem; }
.inf-filter-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--fg-faint); font-weight: 600; }
.inf-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.inf-chip {
  font: inherit; font-size: 0.75rem; color: var(--fg-muted); background: #fff;
  border: 1px solid var(--border); border-radius: 999px; padding: 0.28rem 0.6rem; cursor: pointer;
  transition: all 0.15s ease;
}
.inf-chip:hover { border-color: var(--border-strong); }
.inf-chip.on { color: #fff; background: var(--fg); border-color: var(--fg); }

.inf-table-wrap { overflow-x: auto; }
.inf-table { min-width: 640px; font-size: 0.82rem; }
.inf-row {
  display: grid;
  grid-template-columns: 14px 130px repeat(var(--cols), minmax(42px, 1fr)) 70px 96px;
  gap: 0.5rem; align-items: center; padding: 0.5rem 0.15rem; border-bottom: 1px solid var(--border);
}
.inf-head { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--fg-faint); font-weight: 600; }
.inf-bullet { width: 10px; height: 10px; border-radius: 50%; }
.inf-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inf-per { text-align: right; color: var(--fg-muted); }
.inf-head .inf-per { text-align: right; }
.inf-tot { text-align: right; font-weight: 700; }
.inf-spark { height: 26px; }
.inf-spark .spark { width: 88px; height: 26px; display: block; }

/* Chatbot */
.chat { position: fixed; right: 18px; bottom: 18px; z-index: 55; }
.chat-fab {
  width: 52px; height: 52px; border-radius: 50%; border: none; cursor: pointer; color: #fff;
  background: linear-gradient(135deg, var(--coral), var(--blue));
  box-shadow: 0 12px 28px -8px rgba(249,78,88,0.5); display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s ease;
}
.chat-fab:hover { transform: scale(1.06); }
.chat-fab svg { width: 22px; height: 22px; }
.chat-panel {
  position: absolute; right: 0; bottom: 64px; width: 340px; max-width: calc(100vw - 36px); height: 460px; max-height: calc(100vh - 120px);
  background: #fff; border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 24px 50px -16px rgba(0,0,0,0.32);
  display: flex; flex-direction: column; overflow: hidden; animation: chatIn 0.22s ease;
}
@keyframes chatIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.chat-title { font-size: 0.85rem; font-weight: 600; display: inline-flex; align-items: center; gap: 0.4rem; }
.chat-spark { color: var(--coral); }
.chat-close { border: none; background: transparent; font-size: 1.3rem; line-height: 1; color: var(--fg-faint); cursor: pointer; }
.chat-log { flex: 1; overflow-y: auto; padding: 0.9rem; display: flex; flex-direction: column; gap: 0.6rem; }
.chat-msg { font-size: 0.83rem; line-height: 1.45; padding: 0.55rem 0.75rem; border-radius: 12px; max-width: 85%; }
.chat-msg.bot { background: var(--bg-subtle); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-msg.user { background: var(--coral); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-msg b { font-weight: 700; }
.chat-link {
  display: inline-flex; align-items: center; gap: 0.25rem; margin-top: 0.6rem;
  font: inherit; font-size: 0.8rem; font-weight: 600; color: var(--coral);
  background: transparent; border: none; padding: 0; cursor: pointer; text-align: left;
}
.chat-link:hover { text-decoration: underline; }
.chat-typing { display: inline-flex; gap: 3px; }
.chat-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-faint); animation: blink 1.2s infinite; }
.chat-typing i:nth-child(2) { animation-delay: 0.2s; }
.chat-typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }
.chat-prompts { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0 0.9rem 0.6rem; }
.chat-chip { font: inherit; font-size: 0.72rem; color: var(--fg-muted); background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 0.3rem 0.6rem; cursor: pointer; }
.chat-chip:hover { border-color: var(--coral); color: var(--coral); }
.chat-input { display: flex; gap: 0.4rem; padding: 0.7rem 0.9rem; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; font: inherit; font-size: 0.83rem; border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.7rem; }
.chat-input input:focus { outline: none; border-color: var(--coral); }
.chat-input button { width: 36px; border: none; border-radius: 10px; background: var(--coral); color: #fff; font-size: 1rem; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  .card, .kpi, .demo-live i, .chat-panel, .chat-typing i { animation: none; }
}
