:root {
  color-scheme: dark;
  --bg: #090c10;
  --panel: #11161d;
  --panel-2: #151b23;
  --panel-3: #1a222c;
  --line: #27313d;
  --text: #f4f7fa;
  --muted: #93a0ae;
  --accent: #4bc1ae;
  --accent-strong: #67d7c5;
  --focus: #90e8da;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { min-width: 320px; overflow: hidden; }
button, a { font: inherit; }
button, .stage, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }

.app-shell {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: radial-gradient(circle at 50% -20%, #17212a 0%, #090c10 38%, #07090c 100%);
}
.topbar { flex: 0 0 auto; min-height: 74px; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); background: rgba(14, 18, 24, .96); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 42px; height: 42px; border: 1px solid #2c7f73; border-radius: 12px; background: #112824; display: grid; place-items: center; flex: 0 0 auto; }
.brand-mark svg { width: 23px; height: 23px; stroke: var(--accent); stroke-width: 2.3; fill: none; stroke-linecap: round; }
.brand h1 { margin: 0; font-size: 16px; line-height: 1.2; font-weight: 680; letter-spacing: .01em; }
.brand p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 8px; color: #c7d0d9; font-size: 12px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(75,193,174,.11); }

.view-tabs { flex: 0 0 auto; min-height: 44px; padding: 5px 12px; display: flex; align-items: center; gap: 5px; border-bottom: 1px solid var(--line); background: #0d1218; }
.view-tab, .pdf-shortcut { min-height: 34px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: #9da9b5; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 11px; font-size: 12px; text-decoration: none; cursor: pointer; }
.view-tab svg, .pdf-shortcut svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.view-tab.active { color: #e9fffb; background: #112824; border-color: #276d63; }
.pdf-shortcut { margin-left: auto; border-color: #2b3540; background: #151b23; color: #cdd6df; }
.view-tab:hover, .pdf-shortcut:hover { color: #fff; border-color: #43505d; }

.content-area { flex: 1 1 auto; min-height: 0; overflow: hidden; }
.images-view, .report-view { width: 100%; height: 100%; min-height: 0; }
.viewer-layout { width: 100%; height: 100%; min-height: 0; display: grid; grid-template-columns: 170px minmax(0, 1fr); overflow: hidden; }
.thumb-panel { min-height: 0; border-right: 1px solid var(--line); background: #0d1117; display: flex; flex-direction: column; overflow: hidden; }
.thumb-panel-head { flex: 0 0 46px; padding: 0 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.thumb-panel-head strong { background: var(--panel-3); color: #cfd7df; border-radius: 999px; min-width: 28px; text-align: center; padding: 4px 8px; font-size: 11px; }
.thumb-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 10px; scrollbar-width: thin; scrollbar-color: #394654 transparent; }
.thumb { width: 100%; padding: 0; margin: 0 0 9px; display: block; border: 1px solid #26303b; border-radius: 8px; overflow: hidden; background: #050608; color: inherit; cursor: pointer; position: relative; transition: border-color .15s ease, transform .15s ease; }
.thumb:last-child { margin-bottom: 0; }
.thumb img { width: 100%; height: auto; aspect-ratio: 1260 / 910; object-fit: contain; display: block; background: #000; }
.thumb span { position: absolute; left: 6px; bottom: 5px; min-width: 24px; height: 20px; padding: 0 6px; border-radius: 5px; background: rgba(5,8,11,.82); display: grid; place-items: center; font-size: 10px; color: #dbe3ea; }
.thumb.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.thumb.active span { background: var(--accent); color: #07110f; font-weight: 700; }
@media (hover:hover) and (pointer:fine) { .thumb:hover { border-color: #526170; transform: translateY(-1px); } }

.workspace { min-width: 0; min-height: 0; height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.toolbar { min-height: 54px; padding: 7px 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel); flex-wrap: wrap; }
.toolbar-group { display: flex; align-items: center; gap: 6px; }
.toolbar-divider { width: 1px; height: 28px; background: var(--line); margin-left: auto; }
.tool-btn, .icon-btn, .zoom-value { min-height: 38px; border: 1px solid #303b47; border-radius: 8px; background: #171e26; color: #dce4eb; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .15s ease, border-color .15s ease, color .15s ease; }
.tool-btn { padding: 0 11px; font-size: 12px; }
.tool-btn.compact { padding: 0 10px; }
.icon-btn { width: 38px; padding: 0; }
.zoom-value { min-width: 62px; padding: 0 8px; color: #aeb9c4; font-size: 11px; }
.tool-btn svg, .icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.counter { min-width: 62px; height: 38px; padding: 0 8px; display: flex; align-items: center; justify-content: center; gap: 5px; color: var(--muted); font-size: 12px; }
.counter strong { color: var(--text); font-size: 14px; }
.tool-btn:hover, .icon-btn:hover, .zoom-value:hover { border-color: #526170; background: #1d2630; color: #fff; }
.tool-btn:focus-visible, .icon-btn:focus-visible, .zoom-value:focus-visible, .thumb:focus-visible, .stage:focus-visible, .edge-nav:focus-visible, .view-tab:focus-visible, .pdf-shortcut:focus-visible, .pdf-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.stage { min-height: 0; position: relative; overflow: hidden; background: #000; touch-action: none; user-select: none; cursor: grab; }
.stage.dragging { cursor: grabbing; }
.image-wrap { position: absolute; inset: 0; padding: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.main-image {
  display: block;
  width: auto !important;
  height: auto !important;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1260 / 910;
  object-fit: contain;
  object-position: center center;
  transform-origin: center center;
  will-change: transform;
  pointer-events: none;
}
.edge-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 66px; border: 1px solid rgba(255,255,255,.13); border-radius: 10px; color: rgba(255,255,255,.72); background: rgba(12,16,21,.62); display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(6px); opacity: .58; transition: opacity .15s ease, background .15s ease; }
.edge-nav svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.edge-prev { left: 14px; }
.edge-next { right: 14px; }
.edge-nav:hover { opacity: 1; background: rgba(20,28,35,.88); }
.interaction-hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); max-width: calc(100% - 28px); padding: 7px 10px; border-radius: 999px; background: rgba(11,15,20,.72); border: 1px solid rgba(255,255,255,.1); color: rgba(225,232,239,.66); font-size: 10px; white-space: nowrap; pointer-events: none; transition: opacity .35s ease; }
.interaction-hint.hidden { opacity: 0; }

.viewer-footer { min-height: 48px; padding: 8px 14px; border-top: 1px solid var(--line); background: #0f141a; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 11px; }
.viewer-footer p { margin: 0; text-align: right; }
.study-info { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.study-label { color: #7e8b99; }
.study-info strong { color: #e9eef3; }
.separator { color: #4d5965; }

/* Informe */
.report-view { background: #0b0f14; }
.report-scroll { width: 100%; height: 100%; overflow-y: auto; padding: 28px 20px 40px; scrollbar-width: thin; scrollbar-color: #394654 transparent; }
.report-card { width: min(980px, 100%); margin: 0 auto; border: 1px solid #28323d; border-radius: 14px; overflow: hidden; background: #11171e; box-shadow: 0 16px 40px rgba(0,0,0,.18); }
.report-header { padding: 24px 26px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid #27313d; background: linear-gradient(145deg, #151d25 0%, #11171e 100%); }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.report-header h2 { margin: 0; font-size: clamp(20px, 2.4vw, 28px); line-height: 1.15; }
.report-subtitle { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.pdf-btn { min-height: 42px; padding: 0 14px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid #307d71; border-radius: 9px; background: #12302b; color: #e9fffb; text-decoration: none; font-size: 12px; font-weight: 650; }
.pdf-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pdf-btn:hover { background: #173b35; border-color: #49a596; }
.patient-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-bottom: 1px solid #27313d; }
.data-item { min-width: 0; padding: 15px 20px; border-bottom: 1px solid #232c36; }
.data-item:nth-child(odd) { border-right: 1px solid #232c36; }
.data-item:nth-last-child(-n+2) { border-bottom: 0; }
.data-item span { display: block; margin-bottom: 5px; color: #83919f; font-size: 10px; text-transform: uppercase; letter-spacing: .07em; }
.data-item strong { display: block; color: #e9eef3; font-size: 13px; font-weight: 620; line-height: 1.4; overflow-wrap: anywhere; }
.report-sections { padding: 4px 26px 12px; }
.report-section { padding: 22px 0; border-bottom: 1px solid #27313d; }
.report-section:last-child { border-bottom: 0; }
.report-section h3 { margin: 0 0 13px; font-size: 15px; }
.report-section p { margin: 0 0 9px; color: #c6d0d9; font-size: 13px; line-height: 1.65; }
.report-section p:last-child { margin-bottom: 0; }
.section-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.section-heading-row h3 { margin: 0; }
.birads-badge { display: inline-flex; align-items: center; justify-content: center; min-height: 28px; padding: 0 10px; border: 1px solid #8f6641; border-radius: 999px; background: #2f2419; color: #f3cc9d; font-size: 11px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.report-meta { padding: 18px 26px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; border-top: 1px solid #27313d; background: #0e141a; }
.report-meta div { display: flex; flex-direction: column; gap: 4px; }
.report-meta span { color: #7f8b97; font-size: 10px; text-transform: uppercase; letter-spacing: .07em; }
.report-meta strong { color: #e5ebf0; font-size: 12px; }
.report-meta small { color: #909daa; font-size: 11px; }
.report-note { margin: 0; padding: 12px 26px; border-top: 1px solid #27313d; color: #7f8b97; font-size: 10px; line-height: 1.5; }

@media (max-width: 820px) {
  .viewer-layout { display: flex; flex-direction: column; }
  .workspace { order: 1; flex: 1 1 auto; height: auto; min-height: 0; }
  .thumb-panel { order: 2; flex: 0 0 108px; min-height: 108px; border-right: 0; border-top: 1px solid var(--line); }
  .thumb-panel-head { display: none; }
  .thumb-list { display: flex; overflow-x: auto; overflow-y: hidden; gap: 8px; padding: 8px 10px; }
  .thumb { flex: 0 0 116px; width: 116px; margin: 0; }
  .toolbar-divider { display: none; }
  .toolbar { justify-content: center; }
  .viewer-footer { flex-direction: column; align-items: flex-start; gap: 4px; }
  .viewer-footer p { text-align: left; }
  .report-scroll { padding: 18px 12px 28px; }
  .report-card { border-radius: 11px; }
}

@media (max-width: 560px) {
  .topbar { padding: 9px 11px; min-height: 62px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 10px; }
  .brand h1 { font-size: 14px; }
  .brand p { max-width: 245px; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .status { display: none; }
  .view-tabs { min-height: 42px; padding: 4px 7px; }
  .view-tab, .pdf-shortcut { min-height: 33px; padding: 0 9px; font-size: 11px; }
  .view-tab svg, .pdf-shortcut svg { width: 15px; height: 15px; }
  .pdf-shortcut span { display: none; }
  .toolbar { min-height: 50px; padding: 5px 7px; gap: 5px; flex-wrap: nowrap; }
  .tool-btn span { display: none; }
  .tool-btn { width: 36px; min-height: 36px; padding: 0; }
  .icon-btn { width: 36px; min-height: 36px; }
  .zoom-value { min-width: 55px; min-height: 36px; }
  .counter { min-width: 48px; height: 36px; padding: 0 3px; }
  .fullscreen-btn { display: none; }
  .stage { min-height: 0; }
  .image-wrap { padding: 6px; }
  .main-image { max-width: 100%; max-height: 100%; }
  .edge-nav { width: 38px; height: 52px; opacity: .48; }
  .edge-prev { left: 6px; }
  .edge-next { right: 6px; }
  .interaction-hint { display: none; }
  .viewer-footer { min-height: 43px; font-size: 9px; padding: 6px 9px; }
  .thumb-panel { flex-basis: 92px; min-height: 92px; }
  .thumb { flex-basis: 102px; width: 102px; }
  .thumb-list { padding: 6px 8px; }
  .report-scroll { padding: 10px 8px 20px; }
  .report-header { padding: 18px 16px; align-items: flex-start; flex-direction: column; }
  .report-header h2 { font-size: 20px; }
  .pdf-btn { width: 100%; }
  .patient-grid { grid-template-columns: 1fr; }
  .data-item, .data-item:nth-child(odd), .data-item:nth-last-child(-n+2) { border-right: 0; border-bottom: 1px solid #232c36; }
  .data-item:last-child { border-bottom: 0; }
  .data-item { padding: 12px 16px; }
  .report-sections { padding: 2px 16px 8px; }
  .report-section { padding: 18px 0; }
  .report-section p { font-size: 12px; line-height: 1.6; }
  .report-meta { grid-template-columns: 1fr; gap: 15px; padding: 16px; }
  .report-note { padding: 11px 16px; }
}

@media (max-height: 650px) and (min-width: 561px) {
  .topbar { min-height: 60px; padding-block: 8px; }
  .brand-mark { width: 38px; height: 38px; }
  .view-tabs { min-height: 40px; }
  .toolbar { min-height: 48px; }
  .viewer-footer { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
