:root {
  --bg: #f4f8fb;
  --surface: #ffffff;
  --surface-alt: #eef5fa;
  --primary: #0b5ed7;
  --primary-dark: #084298;
  --teal: #0f766e;
  --teal-light: #e6f4f1;
  --text: #102a43;
  --muted: #52606d;
  --border: #d9e2ec;
  --success: #15803d;
  --danger: #b91c1c;
  --warning: #b45309;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(16, 42, 67, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Barra superior */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  color: var(--primary-dark);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--teal));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 900;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.nav-links a:hover,
.nav-links button.link-btn:hover {
  color: var(--primary);
}

.link-btn {
  background: none;
  border: none;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-teal {
  background: var(--teal);
  color: #fff;
}

.btn-teal:hover {
  filter: brightness(0.92);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover {
  background: var(--surface-alt);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12px;
}

/* Hero tipo hospital / red asistencial */
.hero {
  background: linear-gradient(135deg, #0b4f8a 0%, #0f766e 100%);
  color: #fff;
  padding: 52px 0;
}

.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 28px;
  align-items: center;
}

.hero-tag {
  display: inline-block;
  background: rgba(255, 255, 255, 0.16);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 12px;
}

.hero h1 {
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.18;
  margin-bottom: 14px;
}

.hero p {
  font-size: 16px;
  opacity: 0.94;
  margin-bottom: 22px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.hero-card {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(6px);
}

.hero-card h3 {
  font-size: 17px;
  margin-bottom: 10px;
}

.hero-card ul {
  list-style: none;
  display: grid;
  gap: 8px;
  font-size: 14px;
}

/* Secciones */
section.band {
  padding: 44px 0;
}

.section-head {
  margin-bottom: 22px;
}

.section-head h2 {
  font-size: 24px;
  color: var(--text);
}

.section-head p {
  color: var(--muted);
  font-size: 14px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.service-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--teal-light);
  color: var(--teal);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 12px;
}

.card h3 {
  font-size: 17px;
  margin-bottom: 6px;
}

.card p {
  font-size: 14px;
  color: var(--muted);
}

/* Galería visual limpia */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.photo-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.photo-tile img {
  width: 100%;
  height: 175px;
  object-fit: cover;
  display: block;
}

.photo-tile .photo-caption {
  padding: 12px 14px;
}

.photo-tile strong {
  display: block;
  font-size: 15px;
}

.photo-tile span {
  font-size: 13px;
  color: var(--muted);
}

/* Portal de turnos / Paneles */
.portal-wrap {
  padding: 32px 0 56px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}

th,
td {
  text-align: left;
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 700;
}

.metric-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.metric-val {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary-dark);
}

.metric-sub {
  font-size: 12px;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-alt);
  color: var(--primary-dark);
  border: 1px solid var(--border);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Footer */
footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: 32px;
  font-size: 13px;
  color: var(--muted);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
}

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: var(--text);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 999;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

/* Barra de progreso de turno activo */
.turno-progress-wrap {
  margin-top: 6px;
  max-width: 260px;
}

.turno-progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 3px;
}

.turno-progress-track {
  width: 100%;
  height: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.turno-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--teal), var(--primary));
  transition: width 0.4s linear;
}

.turno-progress-fill.overtime {
  background: var(--warning);
}

.brand-mark-logo {
  background: #ffffff;
  border: 1px solid var(--border);
  overflow: hidden;
  padding: 2px;
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Línea de tiempo horizontal tipo esqueleto de pez en Ficha Técnica */
.fishbone-card {
  margin-bottom: 18px;
}

.fishbone-scroll {
  overflow-x: auto;
  padding: 18px 12px 18px;
}

.fishbone-track {
  position: relative;
  display: flex;
  align-items: center;
  min-width: max-content;
  padding: 64px 28px;
}

.fishbone-spine {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--teal));
  transform: translateY(-50%);
  z-index: 1;
}

.fishbone-node {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 195px;
  max-width: 220px;
  margin-right: 22px;
}

.fishbone-node:last-child {
  margin-right: 0;
}

.fishbone-rib {
  width: 2px;
  height: 22px;
  background: var(--primary);
}

.fishbone-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--teal);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.16);
}

.fishbone-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  width: 100%;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.fishbone-btn:hover,
.fishbone-btn.active {
  border-color: var(--primary);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
  transform: translateY(-2px);
}

.fishbone-date {
  font-size: 11px;
  font-weight: 700;
  color: var(--teal);
}

.fishbone-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-highlight {
  outline: 2px solid var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
}

/* Banner de Paciente en Curso y gráfico clínico */
.active-patient-banner {
  border: 1px solid var(--teal);
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.08), rgba(37, 99, 235, 0.05));
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 18px;
}

.active-patient-grid {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.patient-chart-wrap {
  margin-bottom: 18px;
}

.patient-chart-svg {
  width: 100%;
  max-height: 170px;
  display: block;
}

/* Responsive móvil para Panel Paciente */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .container,
  .main-container,
  .card {
    max-width: 100%;
    box-sizing: border-box;
  }

  .card {
    padding: 14px;
    border-radius: 12px;
  }

  .grid-2,
  .grid-3,
  .grid-4,
  .metrics-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  input,
  select,
  textarea {
    font-size: 16px !important;
    width: 100%;
    box-sizing: border-box;
  }

  .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .actions .btn,
  .btn-sm {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 13px;
  }

  table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  th,
  td {
    padding: 10px 8px;
    font-size: 13px;
  }
}
