/* visu-dicom — style.css : thème sombre, adapté à la lecture d'images médicales */
:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14171c;
  --panel-2: #1b1f26;
  --border: #2a2f38;
  --text: #e6e8eb;
  --muted: #9aa3ae;
  --accent: #4ea1ff;
  --accent-soft: rgba(78, 161, 255, 0.18);
  --overlay: #f0f0f0;
  --warn: #ffd23f;
  --toolbar-h: 46px;
  --library-w: 300px;
  --tags-w: 440px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* --- Barre d'outils ------------------------------------------------------- */
.toolbar {
  height: var(--toolbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.brand { font-weight: 650; letter-spacing: 0.01em; white-space: nowrap; margin-right: 4px; }
.group { display: flex; gap: 4px; align-items: center; }
.spacer { flex: 1; }
.toolbar button, .toolbar select {
  height: 30px;
  padding: 0 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: nowrap;
  cursor: pointer;
}
.toolbar button:hover:not(:disabled), .toolbar select:hover { border-color: #3c4350; }
.toolbar button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #fff;
}
.toolbar button:disabled { opacity: 0.45; cursor: default; }
.toolbar select option:disabled { color: #666; }
button:focus-visible, select:focus-visible, input:focus-visible, .ds-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
#play { min-width: 40px; }
.only-narrow { display: none; }

/* --- Disposition générale ------------------------------------------------- */
main {
  flex: 1;
  min-height: 0;
  display: flex;
}
#library {
  width: var(--library-w);
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#library-status { padding: 10px 12px 6px; border-bottom: 1px solid var(--border); }
#library-status:empty { display: none; }
.status-text { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.status-bar { height: 4px; background: var(--panel-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.status-bar > div { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.problems { margin-top: 6px; font-size: 12px; color: var(--warn); }
.problems ul { margin: 4px 0 0; padding-left: 16px; max-height: 160px; overflow: auto; color: var(--muted); }
#library-tree { flex: 1; overflow-y: auto; padding-bottom: 16px; }
.library-empty { padding: 16px; color: var(--muted); line-height: 1.5; }

.patient { padding: 12px 12px 8px; }
.patient-name { font-weight: 650; font-size: 15px; }
.patient-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.study { border-top: 1px solid var(--border); }
.study-header {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 8px;
  text-align: left;
  padding: 9px 12px 9px 24px;
  background: none;
  border: 0;
  cursor: pointer;
  position: relative;
}
.study-header:hover { background: var(--panel-2); }
.study-date { font-weight: 600; }
.study-desc { grid-column: 1; color: var(--muted); font-size: 12.5px; }
.study-count { grid-row: 1; grid-column: 2; color: var(--muted); font-size: 12px; }
.study-header::before {
  content: "▾";
  position: absolute;
  left: 9px;
  top: 10px;
  color: var(--muted);
  font-size: 11px;
}
.study-header[aria-expanded="false"]::before { content: "▸"; }
.series-list { padding: 0 6px 8px; display: flex; flex-direction: column; gap: 2px; }

.ds-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 6px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  position: relative;
  user-select: none;
}
.ds-card:hover { background: var(--panel-2); }
.ds-card.shown { border-color: var(--border); background: var(--panel-2); }
.thumb {
  width: 64px;
  height: 64px;
  flex: none;
  background: #000;
  border-radius: 4px;
}
.ds-text { min-width: 0; flex: 1; }
.ds-title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-sub { font-size: 12px; color: var(--text); opacity: 0.8; }
.ds-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.ds-badges { display: flex; gap: 3px; position: absolute; top: 5px; right: 6px; }
.badge {
  font-size: 11px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--border);
  color: var(--text);
  text-align: center;
  line-height: 18px;
}
.badge.active { background: var(--accent); color: #001; }

/* --- Zones d'affichage ---------------------------------------------------- */
#viewports {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
  background: var(--border);
}
#viewports.layout-1x1 { grid-template: 1fr / 1fr; }
#viewports.layout-1x2 { grid-template: 1fr / 1fr 1fr; }
#viewports.layout-2x2 { grid-template: 1fr 1fr / 1fr 1fr; }
#viewports.layout-2x4 { grid-template: 1fr 1fr / repeat(4, 1fr); }
#viewports.layout-2x4 .ov { font-size: 11px; }
#viewports.layout-2x4 .ov-tl { display: none; }
#viewports.has-maximized { grid-template: 1fr / 1fr; }
#viewports.has-maximized .viewport:not(.maximized) { display: none; }

.viewport {
  position: relative;
  background: #000;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  outline: none;
  border: 1px solid transparent;
}
#viewports:not(.layout-1x1) .viewport.active { border-color: var(--accent); }
.viewport canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
.viewport[data-tool="pan"] canvas { cursor: grab; }
.viewport[data-tool="zoom"] canvas { cursor: zoom-in; }
.viewport[data-tool="wl"] canvas { cursor: crosshair; }
.viewport.drop-target { border-color: var(--warn); }

.ov {
  position: absolute;
  color: var(--overlay);
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-line;
  pointer-events: none;
  text-shadow: 0 0 3px #000, 0 0 2px #000;
  font-variant-numeric: tabular-nums;
  max-width: 48%;
}
.ov-tl { top: 8px; left: 10px; }
.ov-tr { top: 8px; right: 10px; text-align: right; }
.ov-bl { bottom: 34px; left: 10px; }
.ov-br { bottom: 34px; right: 10px; text-align: right; }
.viewport.single .ov-bl, .viewport.single .ov-br { bottom: 10px; }
.orient {
  position: absolute;
  color: var(--warn);
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  text-shadow: 0 0 3px #000;
}
.orient-top { top: 6px; left: 50%; transform: translateX(-50%); }
.orient-bottom { bottom: 30px; left: 50%; transform: translateX(-50%); }
.viewport.single .orient-bottom { bottom: 6px; }
.orient-left { left: 8px; top: 50%; transform: translateY(-50%); }
.orient-right { right: 8px; top: 50%; transform: translateY(-50%); }
body.hide-overlays .ov, body.hide-overlays .orient { display: none; }

.vp-message {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  pointer-events: none;
}
.vp-message.visible { display: flex; }
.vp-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  display: none;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}
.vp-progress.visible { display: block; }
.vp-progress > div { height: 100%; width: 0; background: var(--accent); }
.vp-slider {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 6px;
  width: calc(100% - 20px);
  margin: 0;
  accent-color: var(--accent);
  opacity: 0.55;
}
.vp-slider:hover, .vp-slider:focus-visible { opacity: 1; }
.viewport.single .vp-slider { display: none; }

/* --- Métadonnées ---------------------------------------------------------- */
#tags-panel {
  width: var(--tags-w);
  flex: none;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#tags-filter {
  margin: 10px;
  padding: 6px 9px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
#tags-content { flex: 1; overflow: auto; padding: 0 10px 16px; }
.tags-file { color: var(--muted); font-size: 12px; margin-bottom: 8px; word-break: break-all; }
.tags-table { border-collapse: collapse; width: 100%; font-size: 12px; table-layout: fixed; }
.tags-table td { padding: 2px 6px 2px 0; vertical-align: top; border-bottom: 1px solid rgba(255, 255, 255, 0.04); }
.tags-table .tag { width: 92px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--muted); white-space: nowrap; }
.tags-table .vr { width: 28px; color: var(--muted); }
.tags-table .name { width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tags-table .value { overflow-wrap: anywhere; }
.tags-table tr.seq .name { color: var(--accent); }
.tags-table tr.item td { color: var(--muted); font-style: italic; }
.depth-1 { padding-left: 12px !important; }
.depth-2 { padding-left: 24px !important; }
.depth-3 { padding-left: 36px !important; }
.depth-4 { padding-left: 48px !important; }
.depth-5 { padding-left: 60px !important; }
.depth-6 { padding-left: 72px !important; }

/* --- Dépôt de dossier, aide ----------------------------------------------- */
#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 13, 16, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}
#drop-overlay > div {
  border: 2px dashed var(--accent);
  border-radius: 14px;
  padding: 40px 56px;
  font-size: 18px;
}
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: min(860px, calc(100vw - 32px));
  padding: 20px 24px;
  line-height: 1.45;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog h3 { margin: 14px 0 6px; font-size: 14px; color: var(--accent); }
.help-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; }
dialog dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 13px; }
dialog dt { color: var(--muted); white-space: nowrap; }
dialog dd { margin: 0; }
dialog p { font-size: 13px; margin: 6px 0; }
dialog form { text-align: right; margin-top: 12px; }
dialog form button {
  padding: 6px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

/* --- Écrans étroits ------------------------------------------------------- */
@media (max-width: 1750px) {
  .toolbar .label.secondary { display: none; }
}
@media (max-width: 1250px) {
  .toolbar .label { display: none; }
  .brand { display: none; }
}
@media (max-width: 820px) {
  .only-narrow { display: inline-block; }
  .brand { display: none; }
  #library {
    position: fixed;
    top: var(--toolbar-h);
    bottom: 0;
    left: 0;
    z-index: 5;
    width: min(320px, 85vw);
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  body.library-open #library { transform: none; box-shadow: 4px 0 18px rgba(0, 0, 0, 0.5); }
  #tags-panel { position: fixed; top: var(--toolbar-h); bottom: 0; right: 0; z-index: 5; width: min(440px, 95vw); }
  .help-columns { grid-template-columns: 1fr; }
  .ov { font-size: 11px; }
}
