:root {
  --bg: #eef2f4;
  --card: #ffffff;
  --ink: #0f2230;
  --muted: #5d7280;
  --line: #dde5ea;
  --brand: #0b5f5a;
  --brand-2: #0e7a73;
  --brand-soft: #e6f2f1;
  --accent: #c8912f;
  --danger: #b23a3a;
  --ok: #2e7d5b;
  --warn: #b07714;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(15, 34, 48, 0.08);
  font-size: 15px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }
button, input, select, textarea { font: inherit; }

/* ---------- Login ---------- */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 15% -10%, #cfe7e4 0%, transparent 55%),
    radial-gradient(900px 500px at 90% 110%, #d8e6ef 0%, transparent 60%),
    var(--bg);
}

.login-card {
  width: min(420px, 92vw);
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(11, 95, 90, 0.18);
  padding: 34px 32px 26px;
  border: 1px solid var(--line);
}

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; color: #fff; font-weight: 700; letter-spacing: .5px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
  flex: none;
}
.brand h1 { font-size: 1.02rem; margin: 0; line-height: 1.25; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: .82rem; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--line); background: #fbfcfd; color: var(--ink);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(14, 122, 115, .15); background: #fff;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px; padding: 10px 16px;
  background: var(--brand); color: #fff; cursor: pointer; font-weight: 600;
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { border-color: #c4d2da; }
.btn.small { padding: 6px 11px; font-size: .85rem; border-radius: 8px; }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

.login-card .btn { width: 100%; padding: 12px; margin-top: 6px; }

.error { color: var(--danger); font-size: .86rem; min-height: 1.2em; margin: 12px 0 0; }
.footnote { color: var(--muted); font-size: .74rem; text-align: center; margin-top: 18px; line-height: 1.5; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  grid-template-rows: 62px 1fr;
  min-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}

.topbar .brand { margin: 0; }
.topbar .brand-mark { width: 38px; height: 38px; border-radius: 10px; font-size: .8rem; }
.topbar .brand h1 { font-size: .98rem; }
.topbar .brand p { font-size: .74rem; }
.topbar .spacer { flex: 1; }

.userbox { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .86rem; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}

.sidebar {
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 62px; height: calc(100vh - 62px);
}

.navlink {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; color: var(--ink);
  text-decoration: none; font-size: .92rem; cursor: pointer; border: 0; background: none; text-align: left;
}
.navlink:hover { background: #f2f7f8; }
.navlink.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.navlink .ico { width: 18px; height: 18px; opacity: .85; }
.sidebar .bottom { margin-top: auto; }

.main { padding: 22px 26px 40px; min-width: 0; }

.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { font-size: 1.15rem; margin: 0; }
.page-head .sub { color: var(--muted); font-size: .84rem; }
.page-head .spacer { flex: 1; }

.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; min-width: 280px;
}
.search input { border: 0; outline: none; background: transparent; width: 100%; color: var(--ink); }
.search svg { opacity: .5; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}

table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: .74rem; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fafcfd;
  white-space: nowrap;
}
table.data td { padding: 12px 14px; border-bottom: 1px solid #edf2f5; vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { cursor: pointer; transition: background .12s; }
table.data tbody tr:hover { background: #f6fafb; }
.patient-name { font-weight: 600; }
.patient-id { color: var(--muted); font-size: .8rem; }
.study-desc { font-size: .88rem; }
.study-acc { color: var(--muted); font-size: .76rem; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; padding: 3px 9px; font-size: .74rem; font-weight: 600;
  background: var(--brand-soft); color: var(--brand);
}
.chip.gray { background: #eef2f4; color: var(--muted); }
.chip.warn { background: #fdf3e0; color: var(--warn); }

.state {
  display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.state.nuevo { background: #e8f1fd; color: #2b62b0; }
.state.leido { background: #fdf3e0; color: var(--warn); }
.state.informado { background: #e7f5ec; color: var(--ok); }
.state.enviado { background: #eef2f4; color: var(--muted); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 32px; height: 32px;
  display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { color: var(--brand); border-color: #bfd3d1; }

.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: 1.1fr 1.4fr; gap: 18px; }

.card-body { padding: 18px; }
.card-title { font-size: .95rem; font-weight: 700; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.card-title .hint { font-weight: 400; color: var(--muted); font-size: .78rem; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: 10px 2px; border-bottom: 1px solid #edf2f5; font-size: .88rem;
}
.list li:last-child { border-bottom: 0; }
.list .meta { color: var(--muted); font-size: .78rem; }

dialog.share-dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(520px, 94vw);
  box-shadow: 0 30px 80px rgba(15, 34, 48, .35);
}
dialog.share-dialog::backdrop { background: rgba(8, 20, 28, .45); }
.dialog-head { padding: 20px 22px 8px; }
.dialog-head h3 { margin: 0 0 4px; font-size: 1.02rem; }
.dialog-head p { margin: 0; color: var(--muted); font-size: .84rem; }
.dialog-body { padding: 10px 22px 4px; }
.dialog-foot { padding: 12px 22px 20px; display: flex; justify-content: flex-end; gap: 8px; }
.link-box {
  display: flex; gap: 8px; margin-top: 6px; background: #f5f8f9;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px; align-items: center;
}
.link-box input { flex: 1; border: 0; background: transparent; font-size: .82rem; color: var(--ink); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: #102b37; color: #eaf3f6; padding: 11px 18px; border-radius: 10px;
  font-size: .88rem; box-shadow: 0 10px 30px rgba(0,0,0,.25); opacity: 0;
  transition: opacity .2s, transform .2s; z-index: 100; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #5b1f1f; }

/* ---------- Visor ---------- */
body.viewer-page { background: #070b0f; color: #d6e2ea; overflow: hidden; height: 100vh; }
.viewer-app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }

.v-top {
  display: flex; align-items: center; gap: 14px; padding: 8px 14px; min-height: 54px;
  background: #0d151b; border-bottom: 1px solid #1b2a34;
}
.v-top .back { color: #9fb4c2; text-decoration: none; font-size: .85rem; display: inline-flex; gap: 6px; align-items: center; }
.v-top .back:hover { color: #fff; }
.v-study { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; max-width: 560px; }
.v-study .pname { font-weight: 700; font-size: .92rem; color: #fff; }
.v-study .pmeta { font-size: .74rem; color: #8fa5b4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-top .spacer { flex: 1; }
.v-tools { display: flex; align-items: center; gap: 4px; }

.vbtn {
  background: #16232c; color: #c7d6e0; border: 1px solid #23333e; border-radius: 8px;
  padding: 7px 10px; font-size: .8rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.vbtn:hover { background: #1d2f3a; }
.vbtn.active { background: #0e7a73; border-color: #0e7a73; color: #fff; }
.vbtn:disabled { opacity: .45; cursor: default; }
.vbtn.share { background: #123b38; border-color: #1e5a55; color: #d9f3f0; }

.v-body { display: grid; grid-template-columns: 246px 1fr; min-height: 0; }
.v-side {
  background: #0b1218; border-right: 1px solid #1b2a34; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.v-side h4 { margin: 2px 0 4px; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: #7d94a3; }
.instance-item {
  display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 9px;
  cursor: pointer; border: 1px solid transparent; background: #0f1920;
}
.instance-item:hover { border-color: #24404b; }
.instance-item.active { border-color: #0e7a73; background: #0c2126; }
.thumb {
  width: 52px; height: 52px; border-radius: 6px; background: #05090c; flex: none;
  object-fit: cover; border: 1px solid #1b2a34;
}
.instance-labels { min-width: 0; }
.instance-labels .t1 { font-size: .8rem; font-weight: 600; color: #d7e5ee; }
.instance-labels .t2 { font-size: .7rem; color: #7d94a3; }

.v-grid { position: relative; background: #05090c; min-width: 0; min-height: 0; }
.v-cell {
  position: absolute; overflow: hidden; background: #05090c;
  box-shadow: inset 0 0 0 1px #16232c;
}
.v-cell .cell-label {
  position: absolute; top: 6px; left: 8px; z-index: 3; font-size: .72rem;
  color: #b9cbd7; background: rgba(6, 12, 17, .7); padding: 2px 8px; border-radius: 6px;
  pointer-events: none; white-space: nowrap;
}
.v-cell .cell-warn {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 24px; color: #f0c674; background: rgba(5, 9, 12, .92); font-size: .85rem; z-index: 4;
}
.v-cell .cell-load {
  position: absolute; top: 8px; right: 10px; z-index: 3; font-size: .7rem; color: #8fa5b4;
}
.v-cell canvas.vp { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.v-cell canvas.overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }

.v-status {
  position: absolute; left: 10px; bottom: 8px; z-index: 5;
  display: flex; gap: 12px; align-items: center; font-size: .72rem; color: #8fa5b4;
  background: rgba(6, 12, 17, .75); padding: 5px 10px; border-radius: 8px;
  pointer-events: none;
}
.v-hint {
  position: absolute; right: 12px; bottom: 8px; z-index: 5; font-size: .7rem;
  color: #5e7382; background: rgba(6, 12, 17, .6); padding: 5px 9px; border-radius: 8px;
  pointer-events: none;
}

.badge-warn {
  display: inline-flex; gap: 6px; align-items: center; font-size: .74rem;
  background: #3a2a10; color: #f0c674; border: 1px solid #6b4e1a; padding: 4px 9px; border-radius: 999px;
  max-width: 440px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  flex: none;
}

@media (max-width: 980px) {
  .app { grid-template-columns: 70px 1fr; }
  .sidebar .label, .sidebar .bottom .label { display: none; }
  .navlink { justify-content: center; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .v-body { grid-template-columns: 1fr; }
  .v-side { display: none; }
}

@media print {
  .topbar, .sidebar, .page-head .btn, .page-head .search { display: none !important; }
  .app { grid-template-columns: 1fr; }
  .main { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}


.pw-warning {
  background: #fdf3e0; color: #7a4c00; border: 1px solid #ecd3a5;
  padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-size: .9rem;
}
.pw-warning a { color: #7a4c00; font-weight: 700; }


.v-cell.active { box-shadow: inset 0 0 0 2px #0e7a73; }


.orthanc-down {
  background: #fdecec; color: #8a1f1f; border: 1px solid #f0c2c2;
  padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-size: .9rem;
}


.v-cell { touch-action: none; }
@media (max-width: 820px) {
  .v-top { flex-wrap: wrap; height: auto; padding: 8px; }
  .v-tools { width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .v-tools .vbtn { flex: 0 0 auto; }
  .v-hint { display: none; }
  .v-study { max-width: calc(100% - 8px); }
}


@media (max-width: 1500px) {
  .v-top { flex-wrap: wrap; height: auto; padding: 8px 14px; }
  .v-tools { width: 100%; justify-content: flex-end; overflow-x: auto; padding-bottom: 2px; }
}

