:root {
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #0d5e58;
  --primary-soft: #ccfbf1;
  --primary-soft-text: #115e59;
  --accent: #2563eb;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Botones e inputs ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.06s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-xs { padding: 4px 8px; font-size: 12px; }
.btn-full { width: 100%; padding: 11px 16px; font-size: 14.5px; }

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

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--text-muted); }

.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: #e9eff4; }

.btn-dark { background: rgba(255,255,255,0.14); color: #fff; border-color: rgba(255,255,255,0.2); }
.btn-dark:hover { background: rgba(255,255,255,0.24); }

.btn-ok { background: var(--ok-soft); color: var(--ok); border-color: #bbf7d0; }
.btn-ok:hover { background: #bbf7d0; }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 2px 4px;
}
.link-btn:hover { text-decoration: underline; }

.icon-btn, .icon-btn-dark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn { color: var(--text-muted); }
.icon-btn:hover { background: #e2e8f0; color: var(--text); }
.icon-btn-dark { color: #e2e8f0; }
.icon-btn-dark:hover { background: rgba(255,255,255,0.16); color: #fff; }

/* ── Login ── */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top left, #e6f6f4 0%, #f4f7f9 55%, #e8eef5 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}
.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0f766e, #0ea5a0);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.login-brand h1 { margin: 0; font-size: 20px; font-weight: 700; }
.login-brand p { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field input {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15); }
.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.login-foot {
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
  color: var(--text);
}
.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #0f766e, #0ea5a0);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; font-weight: 700; }
.brand-text small { font-size: 11px; color: var(--text-muted); }

.topnav { display: flex; align-items: center; gap: 4px; margin-left: 8px; }
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--primary-soft); color: var(--primary-soft-text); font-weight: 600; }

.badge-pill {
  background: var(--warn);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}
.badge-pill.badge-muted { background: #e2e8f0; color: #475569; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-chip {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
}

/* ── Main container ── */
.main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 18px 18px 60px;
}

/* ── KPI strip ── */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  text-align: left;
  font-family: inherit;
}
.kpi-card:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.kpi-card.active { border-color: var(--primary); background: #f0fdfa; }
.kpi-label { font-size: 11.5px; color: var(--text-muted); font-weight: 500; }
.kpi-val { font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.kpi-sub { font-size: 11px; color: var(--text-muted); }

/* ── Toolbar búsqueda y filtros ── */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  gap: 8px;
  color: var(--text-muted);
}
.search-box:focus-within {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}
.search-box input {
  width: 100%;
  border: none;
  background: transparent;
  padding: 10px 0;
  font-size: 14.5px;
  font-family: inherit;
  color: var(--text);
  outline: none;
}
.search-box-sm { max-width: 300px; width: 100%; }
.search-box-sm input { padding: 7px 0; font-size: 13.5px; }
.icon-clear {
  background: #e2e8f0;
  color: #475569;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.select {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.select:focus { border-color: var(--primary); }

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.toggle-chip input { accent-color: var(--primary); margin: 0; }

.results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Grid de pacientes ── */
.patients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.patient-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s, border-color 0.15s;
}
.patient-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: #99f6e4;
}

.card-cover {
  height: 148px;
  background: linear-gradient(135deg, #e8f1f3, #eef4f7);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-cover-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #94a3b8;
  font-size: 12px;
}
.card-years {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.year-pill {
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  backdrop-filter: blur(4px);
}
.hist-pill {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}
.card-sub {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.type-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 6px;
  background: #f1f5f9;
  color: #334155;
}
.type-badge.foto { background: #ecfeff; color: #0e7490; }
.type-badge.stl { background: #eef2ff; color: #4338ca; }
.type-badge.dicom { background: #f3e8ff; color: #7e22ce; }
.type-badge.plan { background: #fef3c7; color: #92400e; }
.type-badge.pdf { background: #fee2e2; color: #b91c1c; }
.type-badge.html { background: #dcfce7; color: #166534; }

.tag-row { display: flex; flex-wrap: wrap; gap: 5px; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-soft-text);
}
.tag-chip button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0 0 0 2px;
  font-size: 13px;
  line-height: 1;
}

.load-more-wrap { display: flex; justify-content: center; margin-top: 20px; }

/* ── Ficha de paciente ── */
.ficha-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}
.ficha-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.ficha-header-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}
.ficha-name {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.ficha-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 13px;
}
.ficha-meta strong { color: var(--text); }

.ficha-tags-bar {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.tag-suggest {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px dashed var(--border-strong);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
}
.tag-suggest:hover { border-color: var(--primary); color: var(--primary); background: #f0fdfa; }
.tag-input-inline {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  width: 135px;
  outline: none;
  font-family: inherit;
}
.tag-input-inline:focus { border-color: var(--primary); }

.ficha-folders {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.folder-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.folder-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.folder-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
  word-break: break-all;
}
.folder-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
.state-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
}
.state-pill.exacto, .state-pill.manual { background: var(--ok-soft); color: var(--ok); }
.state-pill.probable { background: var(--warn-soft); color: var(--warn); }

.ficha-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  padding-bottom: 2px;
}
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-count {
  font-size: 11.5px;
  background: #e2e8f0;
  color: #334155;
  padding: 1px 6px;
  border-radius: 999px;
}
.tab-btn.active .tab-count { background: var(--primary-soft); color: var(--primary-soft-text); }

/* ── Galería de fotos ── */
.photo-group { margin-bottom: 20px; }
.photo-group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}
.photo-tile {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #e2e8f0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
}
.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}
.photo-tile:hover img { transform: scale(1.04); }
.photo-caption {
  position: absolute;
  inset: auto 0 0 0;
  padding: 16px 8px 6px;
  background: linear-gradient(transparent, rgba(15, 23, 42, 0.78));
  color: #fff;
  font-size: 11px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
}
.photo-caption span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Modelos 3D y documentos ── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}
.file-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.file-card-head { display: flex; gap: 10px; align-items: flex-start; }
.file-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
}
.file-icon.stl { background: #eef2ff; color: #4338ca; }
.file-icon.pdf { background: #fee2e2; color: #b91c1c; }
.file-icon.planificacion { background: #fef3c7; color: #92400e; }
.file-icon.interactivo { background: #dcfce7; color: #166534; }
.file-icon.dicom { background: #f3e8ff; color: #7e22ce; }
.file-icon.doc, .file-icon.video, .file-icon.archivo, .file-icon.otro { background: #f1f5f9; color: #475569; }
.file-name { font-weight: 600; font-size: 13.5px; word-break: break-word; }
.file-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.file-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }

/* ── Timeline ── */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-left: 2px solid var(--border-strong);
  margin-left: 10px;
  padding-left: 18px;
}
.tl-node {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.tl-node::before {
  content: '';
  position: absolute;
  left: -25px;
  top: 16px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.tl-date { font-weight: 700; font-size: 13.5px; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.tl-thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tl-thumb {
  width: 68px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
  cursor: pointer;
  border: 1px solid var(--border);
}

/* ── Pendientes & Sueltos ── */
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.section-head h2 { margin: 0; font-size: 19px; }
.section-head p { margin: 3px 0 0; color: var(--text-muted); font-size: 13px; }

.pendientes-list { display: flex; flex-direction: column; gap: 14px; }
.pend-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.pend-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.pend-photos {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.pend-photos img {
  height: 92px;
  width: auto;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
}
.cand-list { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}
table.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
table.data-table tr:last-child td { border-bottom: none; }

/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(9, 13, 22, 0.96);
  display: flex;
  flex-direction: column;
  color: #fff;
}
.lightbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.8);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.lightbox-info { display: flex; flex-direction: column; min-width: 0; }
.lightbox-info strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox-info span { font-size: 12px; color: #94a3b8; }
.lightbox-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.lightbox-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 12px;
}
.lb-img-wrap {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-img-wrap img {
  max-width: 100%;
  max-height: calc(100dvh - 150px);
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
}
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 56px;
  border: none;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.65);
  color: #fff;
  font-size: 30px;
  cursor: pointer;
  z-index: 2;
}
.lb-nav:hover { background: rgba(15, 118, 110, 0.85); }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }

.lb-strip {
  display: flex;
  gap: 6px;
  padding: 8px 14px 12px;
  overflow-x: auto;
  justify-content: safe center;
  background: rgba(15, 23, 42, 0.75);
}
.lb-strip img {
  width: 54px;
  height: 40px;
  object-fit: cover;
  border-radius: 5px;
  opacity: 0.45;
  cursor: pointer;
  border: 2px solid transparent;
  flex-shrink: 0;
}
.lb-strip img.active { opacity: 1; border-color: #2dd4bf; }

/* ── Modales genéricos (STL, Asignar, Doc) ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-panel {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 92dvh;
}
.modal-md { max-width: 560px; }
.modal-xl { max-width: 1120px; height: 86dvh; }
.modal-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-head strong { display: block; font-size: 15px; }
.modal-head small { display: block; font-size: 12px; color: var(--text-muted); }
.modal-head-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.modal-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

.stl-viewport {
  flex: 1;
  position: relative;
  background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
  min-height: 360px;
}
.stl-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #cbd5e1;
  font-size: 13px;
  z-index: 2;
}
.stl-hint {
  padding: 7px 14px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  text-align: center;
}

.doc-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #f8fafc;
}

.assign-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 380px;
  overflow-y: auto;
}
.assign-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.assign-row:hover { background: var(--surface-2); border-color: var(--primary); }

/* ── Spinner & empty & toast ── */
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255,255,255,0.22);
  border-top-color: #2dd4bf;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  color: var(--text-muted);
}

.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.18s ease-out;
}
.toast.ok { background: #0f766e; }
.toast.err { background: #b91c1c; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Responsive móvil ── */
@media (max-width: 900px) {
  .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hide-md { display: none; }
}
@media (max-width: 640px) {
  .topbar-inner { padding: 8px 12px; gap: 8px; }
  .brand-text small { display: none; }
  .nav-btn { padding: 6px 8px; font-size: 12.5px; }
  .hide-sm { display: none; }
  .main { padding: 12px 12px 50px; }
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi-val { font-size: 17px; }
  .patients-grid { grid-template-columns: 1fr; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .lb-nav { width: 36px; height: 44px; font-size: 24px; }
  .modal-xl { height: 92dvh; }
}
