/* ==========================================================================
   NEO-CORPIA · Portal clínico
   Sistema de diseño tomado del logotipo: verde azulado de marca y el rosa
   suave del trazo, a toda fuerza sobre blanco. Nada del azul oscuro de
   NeoPeptide: son dos marcas y el cliente pidió no mezclarlas.
   ========================================================================== */

:root {
  /* Campo y superficies */
  --bg:        #F2F6F5;
  --panel:     #FFFFFF;
  --surface:   #F5F9F8;
  --surface-2: #E8F1EF;
  --line:      rgba(18, 49, 43, 0.13);
  --line-soft: rgba(18, 49, 43, 0.07);

  /* Tinta */
  --ink:       #12312B;
  --ink-soft:  #33564D;
  --muted:     #5E7A72;
  --faint:     #8AA29B;

  /* Verde azulado del logotipo */
  --blue:      #1F8579;
  --blue-soft: #14675E;
  --blue-dim:  rgba(31, 133, 121, 0.10);
  --blue-line: rgba(31, 133, 121, 0.28);

  /* Semánticos — el «violeta» es el rosa del trazo del logotipo */
  --ok:        #1C8A66;
  --ok-dim:    rgba(28, 138, 102, 0.12);
  --warn:      #B4741A;
  --warn-dim:  rgba(180, 116, 26, 0.12);
  --bad:       #C4453F;
  --bad-dim:   rgba(196, 69, 63, 0.10);
  --violet:    #C97D76;
  --violet-dim:rgba(204, 111, 104, 0.12);

  /* Radios y sombras */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 999px;
  --shadow-sm: 0 1px 2px rgba(18, 49, 43, 0.05);
  --shadow-md: 0 8px 26px rgba(18, 49, 43, 0.09);
  --shadow-lg: 0 22px 60px rgba(18, 49, 43, 0.16);

  /* Tipografía */
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --sidebar-w: 252px;
  --topbar-h: 68px;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink-soft);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
svg { width: 18px; height: 18px; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: -0.02em; color: var(--ink); }
h1 { font-size: 2rem; line-height: 1.12; }
h2 { font-size: 1.45rem; line-height: 1.18; }
h3 { font-size: 1.1rem; }
h4 { font-size: 0.97rem; }
em { font-style: normal; color: var(--blue-soft); }
table { border-collapse: collapse; width: 100%; }
::selection { background: var(--blue); color: #fff; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}
.sidebar-head { padding: 20px 18px 14px; border-bottom: 1px solid var(--line-soft); }
.brand { display: block; }
.brand-fallback { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid;
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(140deg, var(--blue), #14675E);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 0.85rem; color: #fff;
  box-shadow: 0 0 0 1px var(--blue-line), 0 8px 22px rgba(31, 133, 121, 0.22);
}
.brand-logo { width: 100%; max-width: 200px; max-height: 84px; object-fit: contain; object-position: left center; mix-blend-mode: multiply; }
.brand-name { display: block; font-family: var(--font-display); font-weight: 600; font-size: 0.98rem; color: var(--ink); letter-spacing: -0.01em; line-height: 1.1; }
.brand-sub { display: block; font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); margin-top: 3px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px 20px; scrollbar-width: thin; scrollbar-color: var(--surface-2) transparent; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 99px; }
.nav-section {
  display: block; padding: 16px 12px 7px;
  font-size: 0.66rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint); font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8.5px 12px; border-radius: 10px;
  font-size: 0.87rem; font-weight: 500; color: var(--muted);
  transition: background 0.16s, color 0.16s;
}
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: 0.85; }
.nav-item:hover { background: var(--surface); color: var(--ink); }
.nav-item.active { background: var(--blue-dim); color: var(--blue-soft); box-shadow: inset 0 0 0 1px var(--blue-line); }
.nav-item.active svg { color: var(--blue-soft); opacity: 1; }
.nav-badge {
  margin-left: auto; min-width: 22px; text-align: center;
  padding: 1px 6px; border-radius: var(--r-full);
  background: var(--surface-2); color: var(--ink-soft);
  font-size: 0.68rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-badge { background: var(--blue); color: #fff; }

.sidebar-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-top: 1px solid var(--line-soft); background: var(--panel);
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 0.83rem; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.7rem; color: var(--faint); }

/* ---------- Main + topbar ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: 16px;
  padding: 0 26px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar-title { font-size: 1.05rem; font-weight: 600; color: var(--ink); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-full); padding: 7px 14px; width: 310px;
  transition: border-color 0.16s;
}
.search:focus-within { border-color: var(--blue-line); }
.search svg { width: 15px; height: 15px; color: var(--faint); flex: none; }
.search input { background: none; border: none; outline: none; width: 100%; font-size: 0.85rem; color: var(--ink); }
.search input::placeholder { color: var(--faint); }
.topbar .menu-btn { display: none; }

.page { padding: 26px 26px 90px; max-width: 1560px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; flex-wrap: wrap; margin-bottom: 22px; }
.page-title { font-size: 2rem; }
.page-sub { margin: 7px 0 0; color: var(--muted); font-size: 0.9rem; max-width: 72ch; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--r-full);
  font-size: 0.85rem; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent; transition: 0.16s;
}
.btn svg { width: 15px; height: 15px; }
.btn-sm { padding: 6.5px 13px; font-size: 0.79rem; }
.btn-primary { background: var(--blue); color: #fff; box-shadow: 0 8px 20px rgba(31, 133, 121, 0.22); }
.btn-primary:hover { background: var(--blue-soft); }
.btn-soft { background: var(--blue-dim); color: var(--blue-soft); border-color: var(--blue-line); }
.btn-soft:hover { background: rgba(31, 133, 121, 0.18); }
.btn-ghost { background: var(--surface); color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-line { background: none; color: var(--muted); border-color: var(--line); }
.btn-line:hover { color: var(--ink); border-color: var(--blue-line); }
.btn-ok { background: var(--ok-dim); color: var(--ok); border-color: rgba(63, 191, 143, 0.3); }
.btn-ok:hover { background: rgba(63, 191, 143, 0.22); }
.btn-danger { background: var(--bad-dim); color: var(--bad); border-color: rgba(255, 107, 107, 0.3); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; box-shadow: none; cursor: not-allowed; }
.btn-icon {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); transition: 0.16s;
}
.btn-icon:hover { color: var(--ink); background: var(--surface-2); }
.btn-icon svg { width: 16px; height: 16px; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.card-title { font-family: var(--font-display); font-weight: 600; font-size: 1rem; color: var(--ink); letter-spacing: -0.01em; }
.card-sub { font-size: 0.79rem; color: var(--faint); margin-top: 3px; }
.card-flat { background: var(--surface); }

/* ---------- KPIs ---------- */
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 16px 18px; position: relative; overflow: hidden;
}
.stat::after {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 2px;
  background: linear-gradient(180deg, var(--blue), transparent);
  opacity: 0.6;
}
.stat-icon {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--blue-dim); color: var(--blue-soft); margin-bottom: 12px;
}
.stat-icon svg { width: 17px; height: 17px; }
.stat-label { font-size: 0.74rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); font-weight: 700; }
.stat-value {
  font-family: var(--font-display); font-size: 1.85rem; font-weight: 600; color: var(--ink);
  letter-spacing: -0.03em; margin-top: 4px; font-variant-numeric: tabular-nums;
}
.stat-value small { font-family: var(--font-body); font-size: 0.78rem; font-weight: 600; color: var(--faint); margin-left: 6px; letter-spacing: 0; }
.stat-delta { display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; font-size: 0.76rem; font-weight: 600; color: var(--ok); }
.stat-delta svg { width: 13px; height: 13px; }
.stat-delta.down { color: var(--bad); }
.stat-delta.warn { color: var(--warn); }
.stat-delta.flat { color: var(--faint); }

/* ---------- Tablas ---------- */
.table { font-size: 0.85rem; }
.table th {
  text-align: left; padding: 0 14px 10px; font-size: 0.68rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--faint); font-weight: 700; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; color: var(--ink-soft); }
.table tbody tr { transition: background 0.14s; }
.table tbody tr:hover { background: var(--surface); }
.table tbody tr:last-child td { border-bottom: none; }
.table strong { color: var(--ink); font-weight: 650; }
.table small { display: block; font-size: 0.74rem; color: var(--faint); }
.scroll-x .table { min-width: 640px; }
.cell-name strong { white-space: nowrap; }
.scroll-x { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }

.cell-name { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, #DCECE9, #C4E0DA);
  box-shadow: inset 0 0 0 1px var(--line);
  font-family: var(--font-display); font-size: 0.72rem; font-weight: 700; color: var(--ink);
}
.avatar.sm { width: 28px; height: 28px; font-size: 0.64rem; border-radius: 8px; }
.avatar.blue { background: linear-gradient(140deg, var(--blue), #14675E); color: #fff; }
.avatar.green { background: linear-gradient(140deg, #CFE9DD, #B4DCCB); }
.avatar.violet { background: linear-gradient(140deg, #F7DCD9, #EFC2BD); }
.avatar.warn { background: linear-gradient(140deg, #F7E4C6, #EED2A6); }

/* ---------- Etiquetas ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.01em;
  background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--line);
  white-space: nowrap;
}
.tag-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag-blue { background: var(--blue-dim); color: var(--blue-soft); border-color: var(--blue-line); }
.tag-ok { background: var(--ok-dim); color: var(--ok); border-color: rgba(63, 191, 143, 0.28); }
.tag-warn { background: var(--warn-dim); color: var(--warn); border-color: rgba(231, 169, 87, 0.28); }
.tag-bad { background: var(--bad-dim); color: var(--bad); border-color: rgba(255, 107, 107, 0.28); }
.tag-violet { background: var(--violet-dim); color: var(--violet); border-color: rgba(167, 139, 250, 0.28); }

/* ---------- Barras de progreso ---------- */
.bar { height: 6px; border-radius: var(--r-full); background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: var(--r-full); background: linear-gradient(90deg, var(--blue), var(--blue-soft)); }
.bar-fill.ok { background: linear-gradient(90deg, #146B4F, var(--ok)); }
.bar-fill.warn { background: linear-gradient(90deg, #8E5A12, var(--warn)); }
.bar-fill.bad { background: linear-gradient(90deg, #9C332E, var(--bad)); }

/* ---------- Formularios ---------- */
.field { display: block; margin-bottom: 14px; }
.label { display: block; font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); font-weight: 700; margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 13px; font-size: 0.87rem; color: var(--ink);
  outline: none; transition: border-color 0.16s, background 0.16s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--blue-line); background: var(--surface-2); }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238B98AC' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; background-size: 15px; padding-right: 34px; }
.hint { font-size: 0.74rem; color: var(--faint); margin-top: 5px; }
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 0.85rem; }
.switch input { display: none; }
.switch-track { width: 38px; height: 21px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); position: relative; transition: 0.18s; flex: none; }
.switch-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: var(--muted); transition: 0.18s; }
.switch input:checked + .switch-track { background: var(--blue-dim); border-color: var(--blue-line); }
.switch input:checked + .switch-track::after { transform: translateX(17px); background: var(--blue-soft); }

/* ---------- Chips / filtros / pestañas ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 5.5px 13px; border-radius: var(--r-full); font-size: 0.79rem; font-weight: 600;
  background: var(--surface); color: var(--muted); border: 1px solid var(--line); transition: 0.14s;
}
.chip:hover { color: var(--ink); }
.chip.chip-active { background: var(--blue-dim); color: var(--blue-soft); border-color: var(--blue-line); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 10px 15px; font-size: 0.86rem; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.activa { color: var(--blue-soft); border-bottom-color: var(--blue); }
[data-panel] { display: none; }
[data-panel].activo { display: block; }

/* ---------- Utilidades ---------- */
.grid { display: grid; gap: 18px; }
.grid > *, .split > *, .split-igual > *, .split-inv > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 0; }
.mb-2 { margin-bottom: 6px; } .mb-4 { margin-bottom: 12px; } .mb-6 { margin-bottom: 20px; } .mb-8 { margin-bottom: 28px; }
.mt-2 { margin-top: 6px; } .mt-4 { margin-top: 12px; } .mt-6 { margin-top: 20px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.fs-xs { font-size: 0.73rem; }
.fs-sm { font-size: 0.82rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-bad { color: var(--bad); }
.text-blue { color: var(--blue-soft); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; color: var(--ink); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.chart-box { position: relative; }

/* Animación de entrada */
.fade-up { animation: fadeUp 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) both; }
.d1 { animation-delay: 0.04s; } .d2 { animation-delay: 0.1s; } .d3 { animation-delay: 0.16s; } .d4 { animation-delay: 0.22s; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .fade-up { animation: none; } }

/* ---------- Nav inferior móvil ---------- */
.mobile-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
  background: rgba(255, 255, 255, 0.97); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
}
.mobile-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 0.65rem; font-weight: 600; color: var(--faint); padding: 5px 2px; position: relative;
}
.mobile-nav a.active { color: var(--blue-soft); }
.mobile-nav svg { width: 19px; height: 19px; }
.mobile-nav a.primary { color: var(--blue-soft); }
.mobile-nav a.primary svg { background: var(--blue); border-radius: 9px; padding: 3px; width: 24px; height: 24px; }
.mt-badge {
  position: absolute; top: 0; right: 22%; background: var(--bad); color: #fff;
  font-size: 0.58rem; font-weight: 800; padding: 0 5px; border-radius: 99px;
}
.sidebar-backdrop { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1240px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search { width: 210px; }
}
@media (max-width: 1024px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
  }
  body.nav-abierto .sidebar { transform: none; }
  body.nav-abierto .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(18, 49, 43, 0.45); z-index: 39; }
  .topbar .menu-btn { display: grid; }
  .mobile-nav { display: flex; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr !important; }
  .page { padding: 20px 16px 96px; }
  .topbar { padding: 0 16px; }
  .search { display: none; }
  .page-title { font-size: 1.6rem; }
}
@media (max-width: 620px) {
  .grid-4 { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; }
  .topbar-title { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .row.wrap > .flex-1 { flex-basis: 100%; }
}
