:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0e7490;
  --accent-ink: #ffffff;
  --accent-soft: #cffafe;
  --admin: #7c3aed;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 8px 24px rgba(15,23,42,.06);
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- LOGIN ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #d9eef2, var(--bg)); padding: 1rem; }
.login-card { background: var(--card); width: 100%; max-width: 380px; padding: 2.2rem 2rem 1.6rem;
  border-radius: 18px; box-shadow: var(--shadow); text-align: center; }
.login-mark { font-size: 2.6rem; }
.login-card h1 { font-size: 1.35rem; margin: .4rem 0 .1rem; }
.login-sub { color: var(--muted); margin: 0 0 1.4rem; font-size: .92rem; }
.login-card form { text-align: left; display: flex; flex-direction: column; }
.login-card label { font-size: .82rem; color: var(--muted); margin: .5rem 0 .25rem; font-weight: 600; }
.login-card input { padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px; font-size: 1rem; }
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.login-card button { margin-top: 1.3rem; padding: .75rem; background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer; }
.login-card button:disabled { opacity: .6; cursor: default; }
.login-msg { color: var(--danger); font-size: .85rem; min-height: 1.1rem; margin: .7rem 0 0; text-align: center; }
.login-foot { color: var(--muted); font-size: .72rem; margin: 1.3rem 0 0; }

/* ---------- TOPBAR ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem;
  background: var(--card); border-bottom: 1px solid var(--line); padding: .55rem 1rem; box-shadow: var(--shadow); }
.hamburger { display: none; background: none; border: 0; font-size: 1.3rem; cursor: pointer; color: var(--ink); }
.topbar-id { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 0; }
.topbar-mark { font-size: 1.5rem; }
.topbar-name { font-weight: 700; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-meta { font-size: .78rem; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.userchip { font-size: .8rem; color: var(--muted); background: var(--bg); padding: .3rem .6rem; border-radius: 999px; white-space: nowrap; }
.userchip b { color: var(--ink); }

/* ---------- LAYOUT ---------- */
.layout { display: flex; align-items: flex-start; }
.sidebar { position: sticky; top: 56px; height: calc(100vh - 56px); width: 220px; flex: none;
  background: var(--card); border-right: 1px solid var(--line); padding: 1rem .6rem; display: flex; flex-direction: column; gap: .2rem; }
.navlink { display: block; padding: .6rem .7rem; border-radius: 10px; color: var(--ink); text-decoration: none;
  font-size: .92rem; cursor: pointer; font-weight: 500; }
.navlink:hover { background: var(--bg); }
.navlink.active { background: var(--accent-soft); color: #075866; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: .6rem .7rem; font-size: .72rem; color: var(--muted); }
.content { flex: 1; padding: 1.4rem; max-width: 1100px; margin: 0 auto; width: 100%; }

/* ---------- COMPONENTES ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1.2rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap; }

.paciente-card { background: linear-gradient(135deg, #0e7490, #155e75); color: #fff; border-radius: var(--radius);
  padding: 1.3rem 1.4rem; margin-bottom: 1.2rem; box-shadow: var(--shadow); }
.paciente-card .pc-nombre { font-size: 1.5rem; font-weight: 700; }
.paciente-card .pc-datos { display: flex; flex-wrap: wrap; gap: 1.2rem; margin-top: .7rem; font-size: .9rem; opacity: .95; }
.paciente-card .pc-datos b { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; opacity: .8; font-weight: 600; }

.badges { display: flex; flex-wrap: wrap; gap: .5rem; }
.badge { background: var(--accent-soft); color: #075866; padding: .3rem .7rem; border-radius: 999px; font-size: .82rem; font-weight: 600; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.info { background: #e0e7ff; color: #3730a3; }

.dx-item { border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; margin-bottom: .8rem; background: var(--card); }
.dx-item h3 { margin: 0 0 .3rem; font-size: 1rem; }
.dx-item .dx-fecha { font-size: .78rem; color: var(--muted); }
.dx-item p { margin: .5rem 0 0; font-size: .92rem; line-height: 1.5; color: #334155; }
.dx-item .dx-fuente { font-size: .76rem; color: var(--muted); margin-top: .4rem; font-style: italic; }

.estudios-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.estudio-card { border: 1px solid var(--line); border-radius: 12px; padding: 1rem; cursor: pointer; background: var(--card); transition: transform .08s, box-shadow .12s; }
.estudio-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.estudio-card .ec-mod { display: inline-block; background: var(--ink); color: #fff; font-size: .7rem; font-weight: 700; padding: .15rem .5rem; border-radius: 6px; letter-spacing: .05em; }
.estudio-card h3 { margin: .6rem 0 .2rem; font-size: 1.02rem; }
.estudio-card .ec-meta { font-size: .8rem; color: var(--muted); }
.estudio-card .ec-series { font-size: .8rem; color: var(--accent); margin-top: .5rem; font-weight: 600; }

.timeline .nota { border-left: 3px solid var(--accent); padding: .2rem 0 1rem 1rem; margin-left: .4rem; position: relative; }
.timeline .nota::before { content:''; position:absolute; left:-7px; top:5px; width:11px; height:11px; border-radius:50%; background:var(--accent); }
.nota .nota-fecha { font-size: .78rem; color: var(--muted); font-weight: 600; }
.nota .nota-titulo { font-weight: 600; margin: .2rem 0; }
.nota p { margin: .2rem 0; font-size: .92rem; line-height: 1.5; white-space: pre-wrap; }
.nota .nota-del { font-size: .75rem; color: var(--danger); cursor: pointer; }

.reporte-box { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.1rem; white-space: pre-wrap;
  font-size: .9rem; line-height: 1.55; color: #334155; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

.docs-lista { display: flex; flex-direction: column; gap: .5rem; }
.doc-row { display: flex; align-items: center; gap: .8rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; }
.doc-row .doc-ic { font-size: 1.3rem; }
.doc-row .doc-nombre { flex: 1; font-weight: 500; font-size: .92rem; word-break: break-word; }
.doc-row .doc-meta { font-size: .76rem; color: var(--muted); }

.btn-primary { background: var(--accent); color: #fff; border: 0; padding: .55rem .95rem; border-radius: 10px; font-weight: 600; cursor: pointer; font-size: .88rem; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: none; border: 1px solid var(--line); padding: .45rem .8rem; border-radius: 10px; cursor: pointer; color: var(--ink); font-size: .85rem; }
.btn-ghost:hover { background: var(--bg); }
.link-danger { color: var(--danger); cursor: pointer; font-size: .82rem; background: none; border: 0; }
.link-report { margin-top: .7rem; display: inline-block; background: var(--accent-soft); color: #075866; border: 0; padding: .4rem .7rem; border-radius: 8px; font-size: .8rem; font-weight: 600; cursor: pointer; }
.link-report:hover { filter: brightness(.97); }
.empty { color: var(--muted); font-size: .9rem; padding: .5rem 0; }
body.rol-visor .admin-only { display: none !important; }

/* ---------- VISOR ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; background: #0b0f14; color: #e5e7eb; display: flex; flex-direction: column; }
.viewer-top { display: flex; align-items: center; justify-content: space-between; padding: .5rem .9rem; background: #11161d; border-bottom: 1px solid #1f2937; }
.viewer-title { font-weight: 600; font-size: .95rem; }
.viewer-actions { display: flex; gap: .3rem; }
.viewer-actions button { background: #1f2937; color: #e5e7eb; border: 0; width: 38px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 1rem; }
.viewer-actions button:hover { background: #374151; }
.viewer-close { background: #7f1d1d !important; }
.viewer-body { flex: 1; display: flex; min-height: 0; }
.viewer-series { width: 200px; flex: none; overflow-y: auto; background: #0e131a; border-right: 1px solid #1f2937; padding: .5rem; }
.viewer-series .vs-study { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: #64748b; margin: .6rem .3rem .3rem; }
.viewer-series .vs-serie { padding: .5rem .6rem; border-radius: 8px; cursor: pointer; font-size: .84rem; margin-bottom: .2rem; }
.viewer-series .vs-serie:hover { background: #1f2937; }
.viewer-series .vs-serie.active { background: var(--accent); color: #fff; }
.viewer-series .vs-serie small { display: block; opacity: .7; font-size: .72rem; }
.viewer-stage { flex: 1; position: relative; overflow: hidden; display: grid; place-items: center; background: #000; }
#viewerImg { max-width: 100%; max-height: 100%; user-select: none; transform-origin: center center; will-change: transform; }
.viewer-overlay { position: absolute; font-size: .75rem; color: #9ca3af; text-shadow: 0 1px 2px #000; padding: .5rem .7rem; pointer-events: none; line-height: 1.4; }
.viewer-overlay.tl { top: 0; left: 0; } .viewer-overlay.tr { top: 0; right: 0; text-align: right; }
.viewer-overlay.bl { bottom: 0; left: 0; }
.viewer-hint { position: absolute; bottom: .6rem; left: 50%; transform: translateX(-50%); font-size: .74rem; color: #6b7280; background: rgba(0,0,0,.5); padding: .3rem .7rem; border-radius: 999px; }
.viewer-slider { width: 60px; flex: none; background: #0e131a; border-left: 1px solid #1f2937; display: flex; flex-direction: column; align-items: center; padding: 1rem .3rem; gap: .6rem; }
.viewer-slider input[type=range] { writing-mode: vertical-lr; direction: rtl; width: 8px; height: 100%; accent-color: var(--accent); }
.corte-num { font-size: .8rem; color: #9ca3af; }
.viewer-controls { display: flex; gap: 1.5rem; justify-content: center; padding: .5rem; background: #11161d; border-top: 1px solid #1f2937; font-size: .78rem; color: #9ca3af; }
.viewer-controls input { accent-color: var(--accent); vertical-align: middle; }

/* ---------- MODAL ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 60; display: grid; place-items: center; padding: 1rem; }
.modal { background: var(--card); border-radius: 14px; padding: 1.4rem; width: 100%; max-width: 520px; box-shadow: var(--shadow); }
.modal h2 { margin-top: 0; }
.modal label { display: block; font-size: .82rem; color: var(--muted); font-weight: 600; margin: .7rem 0 .25rem; }
.modal input, .modal textarea, .modal select { width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 9px; font-size: .95rem; font-family: inherit; }
.modal textarea { min-height: 130px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }

@media (max-width: 820px) {
  .grid-2 { grid-template-columns: 1fr; }
  .hamburger { display: block; }
  .sidebar { position: fixed; z-index: 30; left: 0; top: 56px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .viewer-series { position: absolute; z-index: 5; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .viewer-series.open { transform: translateX(0); }
}
