:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f9fbfd;
  --text: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --primary: #0f6cbd;
  --primary-dark: #0b4f8a;
  --success: #16845b;
  --warning: #c66a12;
  --danger: #c83737;
  --info: #177aa6;
  --shadow: 0 14px 36px rgba(22, 32, 51, .08);
  --radius: 8px;
  --sidebar: 280px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: 0;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px;
  background: #102a43;
  color: #eef6ff;
  box-shadow: 10px 0 28px rgba(0, 0, 0, .12);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-weight: 800;
  font-size: 20px;
}
.brand img, .login-logo { width: 42px; height: 42px; }
.nav-list { display: grid; gap: 5px; overflow-y: auto; padding-right: 3px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  padding: 10px 12px;
  color: #d7e9f8;
  border-radius: var(--radius);
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.nav-item:hover, .nav-item.is-active { background: rgba(255, 255, 255, .12); color: #fff; transform: translateX(2px); }
.nav-icon {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 5px;
  opacity: .9;
  flex: none;
}
.icon-clock, .icon-calendar { border-radius: 50%; }
.icon-alert { transform: rotate(45deg); }
.icon-pulse { border-left-color: transparent; border-right-color: transparent; }
.icon-home { border-radius: 4px 4px 7px 7px; }
.sidebar-card {
  margin-top: auto;
  padding: 14px;
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--radius);
}
.sidebar-card small, .sidebar-card strong { display: block; }
.text-link { display: inline-block; margin-top: 6px; color: #bfe0ff; }
.sidebar-backdrop { display: none; }

.main {
  width: calc(100% - var(--sidebar));
  margin-left: var(--sidebar);
  min-height: 100vh;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 28px;
  background: rgba(245, 247, 251, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.topbar h1 { margin: 0; font-size: 22px; }
.breadcrumb, .eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}
.role-switcher { display: grid; gap: 3px; color: var(--muted); font-size: 12px; font-weight: 700; }
select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}
.content { padding: 28px; }
.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.page-heading h2 { margin: 0; font-size: 28px; }

.panel, .metric-card, .credentials-card, .login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 20px; }
.panel + .panel { margin-top: 18px; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel h3, .panel h4 { margin: 0 0 10px; }
.muted, small { color: var(--muted); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.metric-grid.compact { grid-template-columns: repeat(4, minmax(180px, 1fr)); }
.metric-card {
  padding: 18px;
  transition: transform .16s ease, box-shadow .16s ease;
}
.metric-card:hover, .panel:hover { transform: translateY(-1px); }
.metric-card span { color: var(--muted); display: block; }
.metric-card strong { display: block; margin-top: 4px; font-size: 28px; }

.two-column, .three-column, .card-grid, .settings-grid, .portal-layout {
  display: grid;
  gap: 18px;
}
.two-column { grid-template-columns: minmax(0, 1.35fr) minmax(320px, .85fr); }
.three-column { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 18px; }
.card-grid { grid-template-columns: repeat(4, minmax(240px, 1fr)); }
.settings-grid { grid-template-columns: repeat(3, minmax(240px, 1fr)); }
.portal-layout { grid-template-columns: repeat(2, minmax(260px, 1fr)); }
.portal-hero { grid-column: 1 / -1; background: #eef7ff; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th { color: var(--muted); font-size: 12px; text-transform: uppercase; background: var(--panel-soft); }
tr:hover td { background: #fbfdff; }
.filters {
  display: grid;
  grid-template-columns: 2fr repeat(3, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: #eef5fb; color: var(--primary-dark); border-color: #c8dced; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-small { min-height: 32px; padding: 6px 10px; font-size: 13px; }
.action-row { display: flex; flex-wrap: wrap; gap: 6px; min-width: 250px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.badge-success { background: #e8f7f0; color: var(--success); }
.badge-warning { background: #fff4e6; color: var(--warning); }
.badge-danger { background: #fdecec; color: var(--danger); }
.badge-info { background: #e8f5fb; color: var(--info); }
.badge-primary { background: #e7f0fb; color: var(--primary); }
.badge-neutral { background: #edf1f6; color: #596273; }

.progress {
  height: 8px;
  background: #e8edf4;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  border-radius: inherit;
}
.bar-row { margin-bottom: 14px; }
.bar-row > span { display: block; font-weight: 700; margin-bottom: 4px; }

.timeline { display: grid; gap: 10px; }
.timeline-item, .alert-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}
.timeline-item time { font-weight: 800; color: var(--primary); min-width: 52px; }
.timeline-item div, .alert-row div { flex: 1; min-width: 0; }
.timeline-item span:not(.badge), .alert-row small { display: block; color: var(--muted); }
.alert-list { display: grid; gap: 10px; }
.alert-list.large .alert-row { align-items: flex-start; }

.patient-hero {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 22px;
  margin-bottom: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.avatar {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: #e7f0fb;
  color: var(--primary-dark);
  font-weight: 900;
  font-size: 22px;
  flex: none;
}
.patient-hero h2 { margin: 0; font-size: 28px; }
.inline-meta { display: flex; gap: 8px 14px; flex-wrap: wrap; color: var(--muted); margin-top: 8px; }
.hero-stats { margin-left: auto; min-width: 190px; }
.hero-stats strong { font-size: 30px; }

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  padding: 9px 11px;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}
.tabs button.is-active { background: #e7f0fb; color: var(--primary-dark); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }
.record-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
}
.record-grid article { padding: 14px; background: var(--panel-soft); border: 1px solid var(--line); border-radius: var(--radius); }
.demo-textarea { min-height: 120px; margin-bottom: 12px; }
.detail-list {
  display: grid;
  grid-template-columns: minmax(110px, .45fr) 1fr;
  gap: 8px 14px;
  margin: 0;
}
.detail-list dt { color: var(--muted); font-weight: 700; }
.detail-list dd { margin: 0; }

.calendar-grid {
  display: grid;
  grid-template-columns: 80px 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.calendar-hour, .calendar-slot {
  min-height: 86px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.calendar-hour { background: var(--panel-soft); color: var(--muted); font-weight: 800; }
.appointment-card {
  display: inline-grid;
  gap: 3px;
  width: min(320px, 100%);
  padding: 10px;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  background: #eef7ff;
}
.status-cancelada, .status-no-asistio { border-left-color: var(--danger); background: #fff1f1; }
.status-confirmada, .status-completada { border-left-color: var(--success); background: #effaf4; }
.status-en-sesion { border-left-color: var(--primary); }
.status-en-espera, .status-reagendada { border-left-color: var(--warning); background: #fff8ed; }

.permission-table td, .permission-table th { text-align: center; }
.permission-table td:first-child, .permission-table th:first-child { text-align: left; position: sticky; left: 0; background: #fff; }
.access-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #d6dde7;
}
.access-dot.on { background: var(--success); }
.clean-list { padding-left: 18px; margin: 0; }

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: grid;
  gap: 10px;
}
.toast {
  max-width: 360px;
  padding: 12px 14px;
  background: #102a43;
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.icon-button {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}
.icon-button span { display: block; height: 2px; background: var(--text); margin: 5px 0; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(15,108,189,.12), transparent 34%),
    linear-gradient(315deg, rgba(22,132,91,.12), transparent 34%),
    var(--bg);
}
.login-wrap {
  width: min(1180px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr);
  gap: 18px;
}
.login-panel, .credentials-card { padding: 28px; }
.login-panel h1 { margin: 8px 0 4px; font-size: 44px; }
.login-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 24px;
}
.role-card {
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--text);
}
.role-card:hover { border-color: var(--primary); box-shadow: 0 8px 18px rgba(15, 108, 189, .12); }

.empty-state {
  display: grid;
  place-items: center;
  min-height: 48vh;
  text-align: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
}
code { background: #eef2f7; border-radius: 5px; padding: 2px 5px; }
label { display: grid; gap: 7px; color: var(--muted); font-weight: 700; }

@media (max-width: 1180px) {
  .metric-grid, .three-column, .card-grid, .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .record-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-102%); transition: transform .2s ease; }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(8, 20, 34, .45); }
  .main { width: 100%; margin-left: 0; }
  .icon-button { display: block; }
  .topbar { align-items: flex-start; padding: 14px 16px; }
  .topbar-actions { width: 100%; margin-left: 0; }
  .content { padding: 18px 14px; }
  .page-heading, .patient-hero { align-items: flex-start; flex-direction: column; }
  .hero-stats { margin-left: 0; width: 100%; }
  .metric-grid, .metric-grid.compact, .three-column, .card-grid, .settings-grid, .portal-layout, .login-wrap, .login-grid, .filters { grid-template-columns: 1fr; }
  .record-grid { grid-template-columns: 1fr; }
  .login-panel h1 { font-size: 34px; }
  .calendar-grid { grid-template-columns: 62px 1fr; }
  .calendar-hour, .calendar-slot { padding: 10px; }
}
