/* ============================================================
   Sistema Consultorio Medico - Paleta Teal profesional
   ============================================================ */
:root {
  --teal-900: #0b3b3c;
  --teal-800: #0f4f52;
  --teal-700: #136468;
  --teal-600: #0e8a8f;
  --teal-500: #14a8ae;
  --teal-400: #2bc4cb;
  --teal-300: #7ddfe3;
  --teal-50:  #e8f7f8;
  --accent:   #ff7a59;
  --accent-soft: #ffe9e2;
  --ink:      #1f2937;
  --muted:    #6b7280;
  --line:     #e5e9ee;
  --bg:       #eef4f6;
  --white:    #ffffff;
  --success:  #16a34a;
  --warning:  #d97706;
  --danger:   #dc2626;
  --info:     #0ea5b7;
  --shadow:   0 10px 30px rgba(15, 79, 82, .12);
  --shadow-sm:0 2px 10px rgba(15, 79, 82, .07);
  --radius:   16px;
  --sidebar-w: 260px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background:
    linear-gradient(135deg, rgba(7, 22, 30, .88), rgba(11, 59, 60, .72)),
    url('../img/app-clouds.jpg') center / cover fixed no-repeat,
    var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
a { text-decoration: none; color: inherit; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; max-width: 100%; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  background:
    linear-gradient(180deg, rgba(8, 45, 47, .88) 0%, rgba(4, 27, 29, .94) 100%),
    url('../img/sidebar-stars.jpg') 48% center / cover no-repeat,
    var(--teal-900);
  color: #cdeced;
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  z-index: 30;
  transition: transform .25s ease;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 22px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand .logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--teal-400);
  display: grid; place-items: center;
  color: var(--teal-900); flex-shrink: 0;
}
.sidebar .brand b { font-size: 15px; display: block; line-height: 1.2; }
.sidebar .brand span { font-size: 11px; color: var(--teal-300); }

.nav { padding: 14px 12px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; }
.nav .group-label {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: rgba(205,236,237,.5); margin: 16px 14px 6px;
}
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px;
  color: #bfe3e4; font-weight: 500; margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.nav a svg { width: 19px; height: 19px; flex-shrink: 0; opacity: .9; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active {
  background: var(--teal-500); color: #fff;
  box-shadow: 0 4px 14px rgba(20,168,174,.35);
}
.nav a.profile-link { margin-top: auto; }
.sidebar .foot {
  padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08);
  font-size: 11px; color: rgba(205,236,237,.55);
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 66px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,.45);
  display: flex; align-items: center; gap: 16px;
  padding: 0 26px; position: sticky; top: 0; z-index: 20;
}
.topbar .page-title { font-size: 18px; font-weight: 700; color: var(--teal-900); }
.topbar .search {
  margin-left: auto; position: relative; max-width: 320px; flex: 1;
}
.topbar .search input {
  width: 100%; padding: 10px 14px 10px 38px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); font-size: 13px; outline: none;
}
.topbar .search input:focus { border-color: var(--teal-400); background: #fff; }
.topbar .search svg { position: absolute; left: 12px; top: 11px; width: 16px; height: 16px; color: var(--muted); }
.topbar .user {
  display: flex; align-items: center; gap: 10px; padding-left: 6px;
}
.topbar .user .avatar {
  width: 55px; height: 55px; border-radius: 50%;
  background: linear-gradient(135deg, var(--teal-500), var(--teal-700)); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.topbar .user .meta b { display: block; font-size: 13px; }
.topbar .user .meta span { font-size: 11px; color: var(--muted); }

/* Fondo del area de contenido con tinte suave */
.content {
  padding: 26px;
  min-width: 0;
  min-height: calc(100vh - 66px);
  background:
    linear-gradient(180deg, rgba(238,244,246,.84), rgba(238,244,246,.92)),
    radial-gradient(900px 340px at 100% -10%, rgba(20,168,174,.18), transparent 60%),
    radial-gradient(760px 320px at -8% 0%, rgba(255,122,89,.12), transparent 55%);
}

/* ---------- KPI cards ---------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px; margin-bottom: 22px;
}
.kpi {
  position: relative; overflow: hidden;
  background: var(--white); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: 16px;
  border: 1px solid var(--line);
  transition: transform .18s ease, box-shadow .18s ease;
}
.kpi::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: var(--teal-500);
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.kpi .icon {
  width: 54px; height: 54px; border-radius: 15px;
  display: grid; place-items: center; flex-shrink: 0;
  color: #fff; box-shadow: 0 8px 18px rgba(15,79,82,.18);
}
.kpi .icon svg { width: 24px; height: 24px; }
.kpi .icon.teal  { background: linear-gradient(135deg, var(--teal-500), var(--teal-700)); }
.kpi .icon.blue  { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.kpi .icon.coral { background: linear-gradient(135deg, #ff9472, #ff5e62); }
.kpi .icon.green { background: linear-gradient(135deg, #34d399, #059669); }
.kpi .icon.violet{ background: linear-gradient(135deg, #a78bfa, #7c3aed); }
.kpi:nth-child(1)::before { background: linear-gradient(90deg, var(--teal-500), var(--teal-700)); }
.kpi:nth-child(2)::before { background: linear-gradient(90deg, #3b82f6, #1d4ed8); }
.kpi:nth-child(3)::before { background: linear-gradient(90deg, #a78bfa, #7c3aed); }
.kpi:nth-child(4)::before { background: linear-gradient(90deg, #34d399, #059669); }
.kpi:nth-child(5)::before { background: linear-gradient(90deg, #ff9472, #ff5e62); }
.kpi .val { font-size: 26px; font-weight: 800; color: var(--teal-900); line-height: 1; }
.kpi .lbl { font-size: 12px; color: var(--muted); margin-top: 5px; }

/* ---------- Cards / Paneles ---------- */
.card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); border: 1px solid var(--line);
  margin-bottom: 18px; overflow: hidden;
  min-width: 0;
  transition: box-shadow .18s ease, transform .18s ease;
}
.card:hover { box-shadow: var(--shadow); }
.card .card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 20px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f1fafa 0%, #ffffff 100%);
}
.card .card-head h3 {
  margin: 0; font-size: 15px; color: var(--teal-900);
  position: relative; padding-left: 14px;
}
.card .card-head h3::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 5px; height: 18px; border-radius: 3px;
  background: linear-gradient(180deg, var(--teal-400), var(--teal-700));
}
.card .card-body { padding: 20px; }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
@media (max-width: 1000px){ .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Charts ---------- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}
.chart-box {
  position: relative;
  width: 100%;
  height: 280px;
  min-width: 0;
}
.chart-box canvas { max-width: 100% !important; }
@media (max-width: 820px){ .charts-grid { grid-template-columns: 1fr; } }
@media (max-width: 560px){ .chart-box { height: 240px; } }

/* ---------- Tables ---------- */
.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
}
.table-wrap.table-scroll { overflow-x: auto; }
table.tbl {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.tbl th {
  text-align: left; padding: 8px 8px; color: var(--muted);
  font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; border-bottom: 1px solid var(--line);
  background: #f6fafa;
  vertical-align: middle;
}
table.tbl td {
  padding: 8px 8px; border-bottom: 1px solid var(--line);
  vertical-align: top; word-break: normal; overflow-wrap: anywhere;
}
table.tbl tbody tr:hover { background: var(--teal-50); }
table.tbl tbody tr:last-child td { border-bottom: 0; }

/* ---------- Tables específicas ---------- */
table.consultas-table {
  table-layout: fixed;
  width: 100%;
}
table.consultas-table th:nth-child(1),
table.consultas-table td:nth-child(1),
table.consultas-table th:nth-child(5),
table.consultas-table td:nth-child(5) {
  white-space: nowrap;
}
table.consultas-table th:nth-child(1), table.consultas-table td:nth-child(1) { width: 90px; }
table.consultas-table th:nth-child(2), table.consultas-table td:nth-child(2) { width: 28%; }
table.consultas-table th:nth-child(3), table.consultas-table td:nth-child(3) { width: 22%; }
table.consultas-table th:nth-child(5), table.consultas-table td:nth-child(5) { width: 104px; }
table.consultas-table td:nth-child(4) {
  white-space: normal;
}
table.consultas-table td:nth-child(5),
table.pacientes-table td:nth-child(7) {
  text-align: right;
}
.table-actions {
  white-space: nowrap;
  min-width: 0;
  padding-left: 6px;
  padding-right: 6px;
}
.row-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
}

table.pacientes-table {
  table-layout: fixed;
  width: max(100%, 760px);
}
table.pacientes-table th:last-child,
table.pacientes-table td:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
  background: #fff;
  box-shadow: -1px 0 0 var(--line);
}
table.pacientes-table thead th:last-child {
  background: #f6fafa;
  z-index: 3;
}
table.pacientes-table th:nth-child(1), table.pacientes-table td:nth-child(1) { width: 27%; }
table.pacientes-table th:nth-child(2), table.pacientes-table td:nth-child(2) { width: 14%; }
table.pacientes-table th:nth-child(3), table.pacientes-table td:nth-child(3) { width: 76px; }
table.pacientes-table th:nth-child(4), table.pacientes-table td:nth-child(4) { width: 96px; }
table.pacientes-table th:nth-child(5), table.pacientes-table td:nth-child(5) { width: 116px; }
table.pacientes-table th:nth-child(6), table.pacientes-table td:nth-child(6) { width: 94px; }
table.pacientes-table th:nth-child(7), table.pacientes-table td:nth-child(7) { width: 162px; }
.paciente-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.paciente-cell b {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge.success { background: #e7f7ee; color: var(--success); }
.badge.warning { background: #fef3e2; color: var(--warning); }
.badge.danger  { background: #fde8e8; color: var(--danger); }
.badge.info    { background: var(--teal-50); color: var(--teal-600); }
.badge.secondary { background: #eef1f4; color: var(--muted); }
.status-badge { border: 1px solid transparent; }
.status-badge::before {
  content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 5px;
  border-radius: 50%; background: currentColor; vertical-align: 1px;
}
.status-pending { background: #fff4d8; color: #9a6700; border-color: #f3d38a; }
.status-confirmed { background: #e8f2ff; color: #2365a6; border-color: #b9d5f4; }
.status-waiting { background: #fff0e5; color: #b45309; border-color: #f3c39d; }
.status-done { background: #e8f7ee; color: #197341; border-color: #b8e2c7; }
.status-stage { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: filter .15s, background .15s; background: var(--bg); color: var(--ink);
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--teal-600); color: #fff; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-light { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-light:hover { background: var(--bg); }
.recipe-new-btn { margin-left:auto; white-space:nowrap; border-color:#b8dfe1; color:var(--teal-700); box-shadow:0 2px 5px rgba(15,80,82,.08); }
.recipe-new-btn:hover { background:var(--teal-50); border-color:var(--teal-400); color:var(--teal-800); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--teal-600); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 760px){ .form-grid { grid-template-columns: 1fr; } }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 13px; font-family: inherit; outline: none; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--teal-400); box-shadow: 0 0 0 3px rgba(20,168,174,.12); }
.field textarea { resize: vertical; min-height: 78px; }
.field .help { font-size: 11px; color: var(--muted); margin-top: 4px; }
.field .err { font-size: 11px; color: var(--danger); margin-top: 4px; }
.document-form table.tbl input,
.document-form table.tbl select,
.document-form table.tbl textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  font: inherit;
}
.document-form table.tbl textarea { min-height: 42px; resize: vertical; }
.document-form table.tbl input[type=checkbox] { width: auto; }
.document-form .delete-cell { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.form-actions { display: flex; gap: 10px; margin-top: 22px; }

/* ---------- Formularios de documentos medicos ---------- */
.medical-document-form {
  --medical-navy: #09275e;
  --medical-line: #e1ebf2;
  --medical-input: #bfd1e5;
  --medical-page: #f5fafd;
  --medical-teal: #06a6b3;
  max-width: 100%;
}
.medical-document-form .medical-page-titlebar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 10px 0 26px;
}
.medical-document-form .medical-page-titlebar h2 {
  margin: 0;
  color: var(--medical-navy);
  font-size: 28px;
  line-height: 1.2;
  font-weight: 800;
}
.medical-document-form .medical-back {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  color: #08a7b4;
  background: #fff;
  border: 1px solid var(--medical-line);
  box-shadow: 0 2px 8px rgba(9,39,94,.06);
}
.medical-document-form .medical-back svg {
  width: 22px;
  height: 22px;
}
.medical-document-form .medical-form-card {
  background: #fff;
  border: 1px solid var(--medical-line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: none;
  margin-bottom: 22px;
}
.medical-document-form .medical-form-header {
  min-height: 68px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--medical-line);
  background: #fff;
}
.medical-document-form .medical-form-header h3 {
  margin: 0;
  color: var(--medical-navy);
  font-size: 21px;
  font-weight: 700;
  line-height: 1.2;
}
.medical-document-form .medical-form-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: #dffbfd;
  color: #0797a7;
}
.medical-document-form .medical-form-icon svg {
  width: 21px;
  height: 21px;
}
.medical-document-form .medical-form-body {
  padding: 28px 24px;
}
.medical-document-form .medical-base-grid {
  display: grid;
  grid-template-columns: minmax(280px, 640px);
  gap: 16px;
}
.medical-document-form .medical-field label,
.medical-document-form .medical-grid-head {
  color: var(--medical-navy);
}
.medical-document-form .medical-field label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
}
.medical-document-form .medical-field input,
.medical-document-form .medical-field select,
.medical-document-form .medical-field textarea,
.medical-document-form .medical-cell input,
.medical-document-form .medical-cell select,
.medical-document-form .medical-cell textarea {
  width: 100%;
  min-width: 0;
  height: 45px;
  border: 1px solid var(--medical-input);
  border-radius: 7px;
  background: #fff;
  padding: 0 14px;
  color: var(--medical-navy);
  font: inherit;
  outline: none;
  box-shadow: none;
}
.medical-document-form .medical-field textarea,
.medical-document-form .medical-cell textarea {
  height: auto;
  min-height: 90px;
  padding: 12px 14px;
  resize: vertical;
}
.medical-document-form .medical-field input:focus,
.medical-document-form .medical-field select:focus,
.medical-document-form .medical-field textarea:focus,
.medical-document-form .medical-cell input:focus,
.medical-document-form .medical-cell select:focus,
.medical-document-form .medical-cell textarea:focus {
  border-color: var(--medical-teal);
  box-shadow: 0 0 0 3px rgba(6,166,179,.12);
}
.medical-document-form .medical-items {
  border: 1px solid var(--medical-line);
  border-radius: 8px;
  overflow: visible;
  background: #fff;
  position: relative;
  z-index: 5;
}
.medical-document-form .medical-grid-head {
  border-radius: 8px 8px 0 0;
}
.medical-document-form .medical-grid {
  display: grid;
  gap: 14px;
  align-items: start;
}
.medical-document-form .medical-prescription-grid {
  grid-template-columns:
    minmax(220px, 2.2fr)
    minmax(72px, 80px)
    minmax(220px, 2.2fr)
    minmax(68px, 75px);
}
.medical-document-form .medical-order-grid {
  grid-template-columns:
    minmax(170px, 1.2fr)
    minmax(260px, 2.2fr)
    minmax(260px, 2.3fr)
    minmax(120px, .9fr)
    minmax(68px, 75px);
}
.medical-document-form .medical-grid-head {
  background: #f3f8fc;
  padding: 12px 18px;
  color: #173b77;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.medical-document-form .medical-row {
  padding: 14px 16px 10px;
  border-top: 1px solid var(--medical-line);
}
.medical-document-form .medical-row:first-child {
  border-top: 0;
}
.medical-document-form .medical-cell {
  min-width: 0;
}
.medical-document-form .suggest-wrap {
  position: relative;
}
.medical-document-form .suggest-box {
  position: absolute;
  z-index: 80;
  left: 0;
  right: 0;
  top: calc(100% + 5px);
  max-height: 220px;
  overflow: auto;
  border: 1px solid #d8eef0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 30px rgba(9,39,94,.14);
}
.medical-document-form .suggest-box[hidden] {
  display: none;
}
.medical-document-form .suggest-item {
  width: 100%;
  min-height: 38px;
  padding: 9px 12px;
  border: 0;
  background: #fff;
  color: var(--medical-navy);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.medical-document-form .suggest-item:hover {
  background: #f4fbfb;
  color: #0e8a8f;
}
.medical-document-form .medical-notes-cell input {
  height: 78px;
  padding-top: 12px;
  padding-bottom: 12px;
}
.medical-document-form .medical-action-cell {
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.medical-document-form .medical-hidden-delete {
  display: none;
}
.medical-document-form .medical-delete {
  min-height: 45px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--medical-navy);
  font-weight: 600;
}
.medical-document-form .medical-delete input {
  width: auto;
  height: auto;
}
.medical-document-form .medical-remove {
  min-height: 45px;
  padding: 0 15px;
  border-color: #c7d7e7;
  border-radius: 8px;
  color: #075ea8;
  background: #fff;
}
.medical-document-form .medical-add {
  height: 44px;
  margin-top: 14px;
  padding: 0 16px;
  border: 1px solid #c7d7e7;
  border-radius: 8px;
  background: #fff;
  color: #075ea8;
  font-weight: 700;
}
.medical-document-form .medical-add span {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  border: 2px solid #1685e5;
  color: #1685e5;
  line-height: 1;
}
.medical-document-form .medical-actions {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-top: 22px;
}
.medical-document-form .medical-save,
.medical-document-form .medical-cancel {
  min-height: 50px;
  border-radius: 8px;
  padding: 0 24px;
  font-size: 14px;
}
.medical-document-form .medical-save {
  background: var(--medical-teal);
  color: #fff;
}
.medical-document-form .medical-cancel {
  background: #fff;
  color: var(--medical-navy);
  border-color: #c7d7e7;
}
.medical-document-form .err {
  margin-top: 5px;
  color: var(--danger);
  font-size: 11px;
}

@media (min-width: 901px) {
  body:has(.medical-document-form) .content {
    background: var(--medical-page);
  }
}
@media (max-width: 1500px) {
  .medical-document-form .medical-prescription-grid {
    grid-template-columns:
      minmax(200px, 2fr)
      minmax(68px, 76px)
      minmax(190px, 2fr)
      minmax(66px, 72px);
    gap: 12px;
  }
  .medical-document-form .medical-order-grid {
    grid-template-columns:
      minmax(150px, 1.1fr)
      minmax(230px, 2fr)
      minmax(230px, 2.1fr)
      minmax(110px, .9fr)
      minmax(66px, 72px);
    gap: 12px;
  }
}
@media (max-width: 1180px) {
  .medical-document-form .medical-grid-head {
    display: none;
  }
  .medical-document-form .medical-prescription-grid,
  .medical-document-form .medical-order-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .medical-document-form .medical-main-cell,
  .medical-document-form .medical-notes-cell {
    grid-column: span 2;
  }
  .medical-document-form .medical-action-cell {
    justify-content: flex-start;
  }
}
@media (max-width: 760px) {
  .medical-document-form .medical-form-body,
  .medical-document-form .medical-form-header {
    padding-left: 16px;
    padding-right: 16px;
  }
  .medical-document-form .medical-base-grid,
  .medical-document-form .medical-prescription-grid,
  .medical-document-form .medical-order-grid {
    grid-template-columns: 1fr;
  }
  .medical-document-form .medical-main-cell,
  .medical-document-form .medical-notes-cell {
    grid-column: auto;
  }
  .medical-document-form .medical-actions {
    flex-wrap: wrap;
  }
}

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.toolbar .spacer { margin-left: auto; }
.toolbar form { margin: 0; }
.toolbar input[type=search] {
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 13px; min-width: 240px;
}

/* ---------- Messages ---------- */
.messages { margin-bottom: 16px; }
.alert {
  padding: 12px 16px; border-radius: 10px; font-size: 13px;
  margin-bottom: 10px; border-left: 4px solid;
}
.alert.success { background: #e7f7ee; border-color: var(--success); color: #14532d; }
.alert.info    { background: var(--teal-50); border-color: var(--teal-500); color: var(--teal-900); }
.alert.warning { background: #fef3e2; border-color: var(--warning); color: #7c2d12; }
.alert.danger  { background: #fde8e8; border-color: var(--danger); color: #7f1d1d; }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty svg { width: 48px; height: 48px; opacity: .35; margin-bottom: 10px; }

/* ---------- Avatar list ---------- */
.av { width: 34px; height: 34px; border-radius: 50%; background: var(--teal-50);
  color: var(--teal-700); display: inline-grid; place-items: center; font-weight: 700; font-size: 12px; }

/* ---------- Pagination ---------- */
.card:has(+ .pager) {
  margin-bottom: 8px;
}
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 0;
}
.pager a, .pager span {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; font-size: 13px; color: var(--ink);
}
.pager .current { background: var(--teal-600); color: #fff; border-color: var(--teal-600); }
.pager .ellipsis {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding-left: 4px;
  padding-right: 4px;
}

/* ---------- Sidebar toggle (mobile) ---------- */
.menu-toggle { display: none; background: none; border: 0; cursor: pointer; color: var(--teal-800); padding: 4px; }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 25;
  background: rgba(11,59,60,.45); backdrop-filter: blur(1px);
}

@media (max-width: 900px){
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.3); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .sidebar-overlay { display: block; }
  .main { margin-left: 0; }
  .menu-toggle { display: grid; }
  .content { padding: 18px 16px; }
  .topbar { padding: 0 16px; gap: 10px; }
  .topbar .search { max-width: none; }
}

@media (max-width: 1100px){
  .topbar .search { max-width: 220px; }
}

@media (max-width: 640px){
  .topbar .page-title { font-size: 16px; }
  .topbar .search { display: none; }
  .topbar .user .meta { display: none; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
  .kpi { padding: 16px; gap: 12px; }
  .kpi .icon { width: 46px; height: 46px; }
  .kpi .val { font-size: 22px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input[type=search] { min-width: 0; width: 100%; }
  .form-actions { flex-wrap: wrap; }
  table.consultas-table {
    table-layout: fixed;
    font-size: 12px;
  }
  table.consultas-table th,
  table.consultas-table td {
    padding: 8px 6px;
  }
  table.consultas-table th:nth-child(1),
  table.consultas-table td:nth-child(1) {
    width: 78px;
  }
  table.consultas-table th:nth-child(2),
  table.consultas-table td:nth-child(2) {
    width: auto;
  }
  table.consultas-table th:nth-child(3),
  table.consultas-table td:nth-child(3),
  table.consultas-table th:nth-child(4),
  table.consultas-table td:nth-child(4) {
    display: none;
  }
  table.consultas-table th:nth-child(5),
  table.consultas-table td:nth-child(5) {
    width: 68px;
  }
  table.consultas-table .row-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
  }
  table.consultas-table .btn-sm {
    justify-content: center;
    padding: 4px 6px;
    font-size: 11px;
  }
}

@media (max-width: 420px){
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   NovaSalud UI System · SaaS clínico 2026
   Capa global para todas las vistas: no altera HTML ni flujos.
   ============================================================ */
:root {
  --teal-900: #12333a;
  --teal-800: #164852;
  --teal-700: #176674;
  --teal-600: #0f8492;
  --teal-500: #14a3b2;
  --teal-400: #46bbc5;
  --teal-300: #a6e2e7;
  --teal-50: #eefbfc;
  --accent: #f26b4c;
  --ink: #172b35;
  --muted: #667780;
  --line: #e5edf0;
  --bg: #f6f9fa;
  --shadow-sm: 0 1px 2px rgba(18, 51, 58, .035), 0 4px 14px rgba(18, 51, 58, .045);
  --shadow: 0 12px 30px rgba(18, 51, 58, .09);
  --radius: 14px;
  --sidebar-w: 248px;
}

body { background: var(--bg); color: var(--ink); font-size: 14px; }
body::selection { background: #c9f0f3; color: var(--teal-900); }

/* Navegación: compacta, con contraste controlado y estados claros. */
.sidebar {
  background:
    linear-gradient(180deg, rgba(9, 34, 40, .87) 0%, rgba(7, 25, 30, .95) 100%),
    url('../img/sidebar-milky-way.png') center / cover no-repeat,
    #0e2a31;
  border-right: 1px solid rgba(255,255,255,.06);
}
.sidebar .brand { padding: 22px 18px 20px; border-color: rgba(255,255,255,.1); }
.sidebar .brand .logo { width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(135deg, #7ce0e4, #28a9b5); box-shadow: 0 6px 16px rgba(0,0,0,.15); }
.sidebar .brand b { font-size: 14px; letter-spacing: -.01em; }
.nav { padding: 12px 10px 14px; }
.nav .group-label { margin: 18px 12px 7px; font-size: 9px; font-weight: 700; letter-spacing: .14em; }
.nav a { min-height: 40px; padding: 9px 12px; gap: 11px; border-radius: 9px; font-size: 13px; color: #c6dbe0; }
.nav a svg { width: 18px; height: 18px; opacity: .8; }
.nav a:hover { background: rgba(255,255,255,.075); }
.nav a.active { background: linear-gradient(90deg, rgba(52,176,188,.95), rgba(26,142,155,.95)); box-shadow: none; }
.sidebar .foot { padding: 13px 18px; font-size: 10px; }

/* Marco principal y barra superior. */
.topbar { height: 72px; padding: 0 30px; background: rgba(255,255,255,.92); border-bottom-color: var(--line); box-shadow: 0 1px 0 rgba(18,51,58,.025); }
.topbar .page-title { font-size: 19px; letter-spacing: -.025em; }
.topbar .search { max-width: 360px; }
.topbar .search input { height: 38px; border-radius: 10px; background: #f7fafb; border-color: #e7eef0; transition: .18s ease; }
.topbar .search input:focus { border-color: var(--teal-400); box-shadow: 0 0 0 4px rgba(20,163,178,.1); }
.topbar .user { gap: 9px; }
.topbar .user .avatar { width: 36px; height: 36px; font-size: 12px; box-shadow: none; }
.topbar .user .meta b { font-size: 12px; }
.content { padding: 28px 30px 40px; min-height: calc(100vh - 72px); background: radial-gradient(760px 260px at 100% 0, rgba(121,220,228,.13), transparent 70%), var(--bg); }

/* Paneles, indicadores y contenidos informativos. */
.kpi-grid { gap: 14px; margin-bottom: 20px; }
.kpi { padding: 18px; border-radius: var(--radius); border-color: #e7eef0; box-shadow: var(--shadow-sm); }
.kpi::before { height: 3px; opacity: .9; }
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi .icon { width: 48px; height: 48px; border-radius: 13px; box-shadow: none; }
.kpi .val { font-size: 24px; letter-spacing: -.035em; }
.kpi .lbl { margin-top: 4px; font-size: 11px; font-weight: 500; }
.card { border-radius: var(--radius); border-color: #e7eef0; box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.card:hover { transform: none; box-shadow: 0 7px 20px rgba(18,51,58,.06); }
.card .card-head { min-height: 57px; padding: 14px 18px; background: #fff; border-bottom-color: #edf2f3; }
.card .card-head h3 { padding-left: 0; font-size: 14px; letter-spacing: -.01em; }
.card .card-head h3::before { display: none; }
.card .card-body { padding: 18px; }
.charts-grid { gap: 16px; margin-bottom: 16px; }

/* Acciones y campos: densidad uniforme y foco accesible. */
.btn { min-height: 38px; padding: 8px 14px; border-radius: 9px; font-size: 12px; font-weight: 700; letter-spacing: .005em; transition: transform .16s ease, box-shadow .16s ease, background .16s ease, border-color .16s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: linear-gradient(135deg, #0f8997, #16737e); box-shadow: 0 5px 12px rgba(15,132,146,.18); }
.btn-primary:hover { filter: none; box-shadow: 0 7px 16px rgba(15,132,146,.25); }
.btn-light { background: #fff; border-color: #dfe9ec; }
.btn-light:hover { background: #f5fafb; border-color: #bcdde1; }
.btn-danger { box-shadow: 0 5px 12px rgba(220,38,38,.12); }
.btn-sm { min-height: 31px; padding: 5px 10px; font-size: 11px; border-radius: 8px; }
.field label { margin-bottom: 7px; color: #314850; font-size: 11px; font-weight: 700; letter-spacing: .015em; }
.field input, .field select, .field textarea,
input:not([type=checkbox]):not([type=radio]), select, textarea {
  border-color: #dce7e9; border-radius: 9px; background: #fff; color: var(--ink); transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
.field input, .field select, select, input:not([type=checkbox]):not([type=radio]) { min-height: 40px; }
.field input:focus, .field select:focus, .field textarea:focus,
input:not([type=checkbox]):not([type=radio]):focus, select:focus, textarea:focus { border-color: var(--teal-400); box-shadow: 0 0 0 4px rgba(20,163,178,.11); outline: 0; }
.field textarea, textarea { min-height: 92px; }
.form-grid { gap: 18px; }
.form-actions { padding-top: 4px; margin-top: 24px; }

/* Tablas y estados: lectura rápida sin bordes pesados. */
.table-wrap { border-radius: 0 0 var(--radius) var(--radius); }
table.tbl { font-size: 12.5px; }
table.tbl th { padding: 11px 14px; background: #f8fbfb; color: #69808a; font-size: 10px; font-weight: 800; letter-spacing: .07em; border-bottom-color: #e6eef0; }
table.tbl td { padding: 13px 14px; border-bottom-color: #edf2f3; }
table.tbl tbody tr { transition: background .14s ease; }
table.tbl tbody tr:hover { background: #f4fcfc; }
table.pacientes-table th:last-child, table.pacientes-table td:last-child { box-shadow: -8px 0 12px -12px rgba(18,51,58,.3); }
.badge { padding: 4px 9px; font-size: 10px; font-weight: 700; letter-spacing: .01em; }
.status-stage { font-size: 9px; }
.toolbar { gap: 10px; margin-bottom: 16px; }
.toolbar input[type=search] { height: 39px; border-radius: 9px; border-color: #dce7e9; background: #fff; }

/* Feedback, paginación y overlays coherentes. */
.alert { display: flex; align-items: center; min-height: 44px; padding: 11px 14px; border-radius: 10px; border-left-width: 3px; box-shadow: 0 2px 8px rgba(18,51,58,.035); }
.pager { gap: 5px; padding-top: 8px; }
.pager a, .pager span { min-width: 34px; text-align: center; padding: 7px 10px; border-radius: 8px; border-color: #e0eaec; }
.pager a:hover { background: var(--teal-50); color: var(--teal-800); }
.pager .current { background: var(--teal-600); box-shadow: 0 3px 8px rgba(15,132,146,.18); }

/* Estado y acciones de recetas/ordenes: evita badges cortados y botones aislados. */
.document-list-table .document-actions-head { min-width: 255px; text-align: right; }
.document-list-table .document-actions { min-width: 255px; white-space: nowrap; text-align: right; }
.document-action-buttons { display: inline-flex; align-items: center; gap: 5px; margin-left: 12px; vertical-align: middle; }
.document-action-buttons .btn { justify-content: center; }
.document-list-table th:nth-child(4),
.document-list-table td:nth-child(4) { min-width: 150px; white-space: nowrap; }
.document-list-table th:first-child,
.document-list-table td:first-child { min-width: 170px; white-space: nowrap; overflow-wrap: normal; word-break: keep-all; }

@media (max-width: 900px) {
  .content { padding: 20px 16px 30px; }
  .topbar { height: 64px; padding: 0 16px; }
  .sidebar { width: min(280px, 86vw); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .content { padding: 16px 12px 26px; }
  .topbar .page-title { font-size: 16px; }
  .card .card-head { padding: 12px 14px; }
  .card .card-body { padding: 14px; }
  .kpi-grid { gap: 10px; }
  .kpi { padding: 14px; gap: 11px; }
  .kpi .icon { width: 42px; height: 42px; }
  .kpi .val { font-size: 20px; }
  table.tbl th, table.tbl td { padding-left: 10px; padding-right: 10px; }
  .btn { min-height: 40px; }
  .document-list-table .document-actions-head,
  .document-list-table .document-actions { min-width: 220px; }
  .document-action-buttons { gap: 4px; margin-left: 7px; }
}
