/* ==========================  ClinIoT - estilos  ========================== */
:root {
  --bg: #f3f6f9;
  --surface: #ffffff;
  --ink: #0f1f2e;
  --muted: #5b6b7b;
  --line: #e1e7ee;
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-soft: #e6f6f4;
  --nav: #0b2536;
  --danger: #c2410c;
  --danger-soft: #fdeee7;
  --warn: #b45309;
  --warn-soft: #fef5e4;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --info: #1d4ed8;
  --info-soft: #e8eefc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 31, 46, .06), 0 8px 24px rgba(15, 31, 46, .06);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
a { color: var(--brand); }
.container { max-width: 1280px; margin: 0 auto; padding: 0 24px; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.eyebrow { text-transform: uppercase; font-size: .72rem; font-weight: 700; letter-spacing: .08em; color: var(--brand); margin: 0 0 4px; }

/* ---------- Header / navegación ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px; background: var(--nav); color: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .18);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand strong { display: block; font-size: 1.1rem; }
.brand small { display: block; font-size: .72rem; color: #9fb7c7; }
.logo { width: 34px; height: 34px; }
.logo rect { fill: var(--brand-2); }
.logo path { fill: none; stroke: #fff; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
nav > a, .dropdown > button {
  color: #d5e3ec; text-decoration: none; background: none; border: 0; font: inherit; font-size: .95rem;
  padding: 9px 14px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
nav > a:hover, .dropdown > button:hover, .dropdown.open > button { background: rgba(255, 255, 255, .08); color: #fff; }
nav .active, .dropdown.active > button { background: rgba(20, 184, 166, .18); color: #fff; }
.caret { font-size: .7rem; opacity: .8; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 0 rgba(52, 211, 153, .7); animation: pulse 1.8s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }
.dropdown { position: relative; }
.menu {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px;
  background: #fff; border-radius: 12px; padding: 6px; box-shadow: 0 12px 40px rgba(0, 0, 0, .2);
}
.dropdown.open .menu { display: block; }
.menu a { display: flex; justify-content: space-between; padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: .92rem; }
.menu a:hover, .menu a.active { background: var(--brand-soft); color: var(--brand); }
.menu a small { color: var(--muted); }
.menu-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.5rem; cursor: pointer; }

/* ---------- Estructura de página ---------- */
main { padding-top: 28px; padding-bottom: 28px; min-height: calc(100vh - 140px); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p.muted { margin: 6px 0 0; max-width: 720px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.layout-crud { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
.layout-crud > form { position: sticky; top: 84px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: 2fr 1fr; }
.stack { display: grid; gap: 20px; }

/* ---------- Formularios ---------- */
form.card h2 { margin-bottom: 4px; }
form.card .hint { margin: 0 0 16px; font-size: .85rem; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.field label { font-size: .85rem; font-weight: 600; color: #2a3b4b; }
.field small { color: var(--muted); font-size: .76rem; }
.req { color: var(--danger); }
input, select, textarea {
  font: inherit; font-size: .93rem; color: var(--ink); background: #fbfcfd;
  border: 1px solid #cfd8e1; border-radius: 10px; padding: 9px 11px; width: 100%;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-2); background: #fff; box-shadow: 0 0 0 3px rgba(20, 184, 166, .18); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.btn {
  font: inherit; font-weight: 600; font-size: .9rem; border-radius: 10px; padding: 9px 16px; cursor: pointer;
  border: 1px solid transparent; display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  transition: transform .05s, background .15s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: #fff; box-shadow: 0 2px 8px rgba(15, 118, 110, .3); }
.btn.primary:hover { background: #0d635c; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: #f4f7f9; }
.btn.sm { padding: 5px 10px; font-size: .8rem; border-radius: 8px; }
.btn.edit { background: var(--info-soft); color: var(--info); }
.btn.del { background: var(--danger-soft); color: var(--danger); }
.btn:disabled { opacity: .6; cursor: wait; }
form.editing { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(20, 184, 166, .15), var(--shadow); }

/* ---------- Tablas ---------- */
.search { max-width: 260px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; max-height: 620px; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead th {
  position: sticky; top: 0; background: #f0f4f7; text-align: left; font-weight: 700; color: #34495e;
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .03em;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid #eef2f5; vertical-align: top; }
tbody tr:hover { background: #f8fbfc; }
tbody tr.flash { animation: flash 2s ease-out; }
@keyframes flash { from { background: #c9f2ea; } to { background: transparent; } }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.acciones { white-space: nowrap; text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 700; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--danger-soft); color: var(--danger); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-mute { background: #eef1f4; color: var(--muted); }

/* ---------- KPIs / tarjetas ---------- */
.kpi { padding: 18px 20px; }
.kpi .label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 1.9rem; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.kpi.accent { background: linear-gradient(135deg, #0f766e, #14b8a6); color: #fff; border: 0; }
.kpi.accent .label, .kpi.accent .sub, .kpi.accent .value small { color: rgba(255, 255, 255, .85); }
a.tile { text-decoration: none; color: inherit; transition: transform .15s, box-shadow .15s; display: block; }
a.tile:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(15, 31, 46, .12); }
.tile .value { color: var(--brand); }
.hero {
  background: linear-gradient(120deg, #0b2536 0%, #0f4c5c 55%, #0f766e 100%); color: #fff;
  border-radius: 18px; padding: 30px 32px; margin-bottom: 22px; display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap;
}
.hero h1 { font-size: 2rem; }
.hero p { color: #cfe3ea; max-width: 640px; margin: 8px 0 0; }
.hero .btn.ghost { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .25); }
.section-title { margin: 26px 0 12px; font-size: 1rem; color: #34495e; }
.chart-box { position: relative; height: 320px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar select { width: auto; }
.live-pill { display: inline-flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
details.sql { margin-top: 4px; }
details.sql summary { cursor: pointer; font-weight: 600; color: var(--brand); font-size: .9rem; }
pre {
  background: #0b2536; color: #d6f5ef; padding: 16px; border-radius: 10px; overflow: auto; font-size: .8rem;
  line-height: 1.5; font-family: Consolas, "Cascadia Code", monospace;
}
.alert { border-radius: 12px; padding: 16px 18px; border: 1px solid; }
.alert.error { background: var(--danger-soft); border-color: #f6c7b3; color: #7c2d12; }
.alert.info { background: var(--info-soft); border-color: #c7d6fb; color: #1e3a8a; }
.alert code { background: rgba(255, 255, 255, .7); padding: 1px 5px; border-radius: 5px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 100; min-width: 260px; max-width: 420px;
  padding: 13px 16px; border-radius: 12px; color: #fff; background: var(--ink); font-size: .9rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .25); transform: translateY(20px); opacity: 0; pointer-events: none; transition: .25s;
}
.toast.show { transform: none; opacity: 1; }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }

.footer { color: var(--muted); font-size: .8rem; padding-top: 12px; padding-bottom: 24px; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .layout-crud, .grid-2 { grid-template-columns: 1fr; }
  .layout-crud > form { position: static; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .menu-toggle { display: block; }
  .topbar { flex-wrap: wrap; }
  nav { display: none; width: 100%; flex-direction: column; align-items: stretch; }
  nav.open { display: flex; }
  .menu { position: static; box-shadow: none; }
  .grid-4 { grid-template-columns: 1fr; }
}
