/* PRET web ui. Colors: reference palette of the dataviz method (sequential blue for progress, status palette for
   the diagnosis, which always comes with an icon and a text label). Light and dark are each selected. */
:root {
  color-scheme: light;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #dddcd7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6d6c67;
  --accent: #2a78d6;          /* blue 450 */
  --accent-strong: #1c5cab;   /* blue 550 */
  --accent-track: #cde2fb;    /* blue 100, lighter step of the same ramp */
  --good: #0ca30c;
  --good-text: #006300;
  --critical: #d03b3b;
  --critical-text: #b02a2a;
  --warning: #fab219;
  --tumor-line: #00c800;      /* the green of the contours drawn into the images */
  --roi-line: #e34948;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 1px rgba(0, 0, 0, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border: #383835;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9c9b94;
    --accent: #3987e5;        /* blue 400 */
    --accent-strong: #6da7ec;
    --accent-track: #184f95;  /* blue 600 */
    --good-text: #4cc94c;
    --critical-text: #ef7a7a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--surface-0);
  color: var(--text-primary);
}
h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
.muted { color: var(--text-secondary); }
.small { font-size: 12.5px; }
.error { color: var(--critical-text); min-height: 1em; margin: 8px 0 0; }
.error:empty { display: none; }

/* ---------- buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled):not(.disabled) { border-color: var(--accent); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { background: transparent; }
.btn:disabled, .btn.disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn .size { font-weight: 400; }
input[type=url], input[type=password], select {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); font: inherit;
}
label { display: block; font-weight: 500; margin: 14px 0 6px; }
.row { display: flex; gap: 8px; margin-top: 16px; }

/* ---------- layout ---------- */
.app { display: flex; flex-direction: column; min-height: 100%; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px; background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.brand { font-size: 18px; font-weight: 700; letter-spacing: .02em; }
.brand .muted { font-size: 13px; font-weight: 400; letter-spacing: 0; margin-left: 8px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-right select { width: 300px; height: 32px; }
.history-label { margin: 0; font-weight: 400; color: var(--text-secondary); }
.columns {
  display: grid; grid-template-columns: minmax(320px, 380px) minmax(0, 1fr); gap: 16px;
  padding: 16px 20px 24px; flex: 1;
}
.left, .right { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
@media (max-width: 900px) {
  .columns { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .topbar-right select { width: 200px; }
}

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 380px; }
.login-card .brand { font-size: 26px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 16px; }

/* ---------- source tabs / drop zone ---------- */
.tabs { display: flex; gap: 4px; margin-top: 12px; padding: 3px; background: var(--surface-2); border-radius: 9px; }
.tab {
  flex: 1; height: 30px; border: 0; border-radius: 7px; background: transparent; color: var(--text-secondary);
  font: inherit; font-weight: 500; cursor: pointer;
}
.tab.active { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); }
.drop {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 104px;
  margin: 12px 0 0; padding: 14px; border: 1.5px dashed var(--border); border-radius: 9px;
  font-weight: 400; cursor: pointer; overflow-wrap: anywhere;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--surface-2); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop.has-file { border-style: solid; }

/* ---------- progress steps (meters) ---------- */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.step-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.step-name { font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.step-name::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--border); flex: none;
}
.step-val { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.meter { height: 8px; border-radius: 4px; background: var(--accent-track); overflow: hidden; }
.fill { height: 100%; width: 0; border-radius: 4px; background: var(--accent); transition: width .6s ease; }
.step-detail { margin-top: 4px; min-height: 1.2em; }
.step.pending .meter { background: var(--surface-2); }
.step.active .step-name::before { border-color: var(--accent); border-top-color: transparent; animation: spin 1s linear infinite; }
.step.active .fill.indeterminate { width: 30% !important; animation: slide 1.4s ease-in-out infinite; }
.step.done .step-name::before { border-color: var(--good); background: var(--good) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/12px no-repeat; }
.step.failed .step-name::before, .step.cancelled .step-name::before { border-color: var(--critical); background: var(--critical); }
.step.failed .fill { background: var(--critical); }
.step.cancelled .fill { background: var(--text-muted); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) {
  .fill { transition: none; }
  .step.active .step-name::before, .step.active .fill.indeterminate { animation: none; }
}
.pill { font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); }
.pill.done { color: var(--good-text); }
.pill.failed { color: var(--critical-text); }
details pre { white-space: pre-wrap; font-size: 11.5px; max-height: 220px; overflow: auto; background: var(--surface-2); padding: 8px; border-radius: 6px; }

/* ---------- result: diagnosis tile + summary ---------- */
.result-top { display: grid; grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1100px) { .result-top { grid-template-columns: 1fr; } }
.label { font-size: 12.5px; color: var(--text-secondary); font-weight: 500; }
.diagnosis { border-left: 4px solid var(--border); }
.diagnosis .value { display: flex; align-items: center; gap: 10px; margin: 6px 0 4px; font-size: 26px; font-weight: 600; }
.dx-icon { width: 28px; height: 28px; border-radius: 50%; flex: none; display: none; }
.diagnosis.benign { border-left-color: var(--good); }
.diagnosis.benign .dx-icon { display: block; background: var(--good) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/18px no-repeat; }
.diagnosis.malignant { border-left-color: var(--critical); }
.diagnosis.malignant .dx-icon { display: block; background: var(--critical) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 4v5' stroke='white' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='8' cy='11.8' r='1.2' fill='white'/%3E%3C/svg%3E") center/18px no-repeat; }
.diagnosis.benign .dx-text { color: var(--good-text); }
.diagnosis.malignant .dx-text { color: var(--critical-text); }
.diagnosis.empty .value, .diagnosis.na .value { font-size: 18px; color: var(--text-secondary); }
.sum-name { font-weight: 600; margin: 4px 0 10px; overflow-wrap: anywhere; }
.sum-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 16px; margin: 0; }
.sum-grid dt { font-size: 12px; color: var(--text-secondary); }
.sum-grid dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- viewer ---------- */
.viewer-card { display: flex; flex-direction: column; }
.viewer-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.viewer {
  position: relative; display: grid; place-items: center; min-height: 360px; height: 52vh;
  background: var(--surface-2); border-radius: 8px; overflow: hidden;
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; }
.viewer-empty { padding: 24px; text-align: center; }
.legend { display: inline-flex; gap: 14px; font-size: 12.5px; color: var(--text-secondary); }
.key { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 16px; height: 0; border-top: 3px solid; border-radius: 2px; }
.swatch.tumor { border-color: var(--tumor-line); }
.swatch.roi { width: 12px; height: 12px; border: 2px solid var(--roi-line); border-radius: 2px; }
.downloads { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- top patch strip ---------- */
.top-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-top: 14px; }
.top-strip:empty { display: none; }
.patch { position: relative; border-radius: 6px; overflow: hidden; background: var(--surface-2); aspect-ratio: 1; }
.patch img { width: 100%; height: 100%; object-fit: cover; display: block; }
.patch .rank {
  position: absolute; left: 4px; top: 4px; font-size: 11px; font-weight: 600; padding: 0 5px; border-radius: 4px;
  background: rgba(0, 0, 0, .62); color: #fff; font-variant-numeric: tabular-nums;
}
.patch.below { outline: 1px dashed var(--border); }
.strip-note { grid-column: 1 / -1; margin: 0; }

/* ---------- full screen WSI ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: #0d0d0c; }
.modal-bar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 8px 14px;
  background: #1a1a19; color: #f0efec; border-bottom: 1px solid #383835;
}
.modal-bar .muted { color: #c3c2b7; }
.modal-bar .btn { margin-left: auto; background: #242422; color: #f0efec; border-color: #383835; }
.modal-title { font-weight: 600; overflow-wrap: anywhere; }
.toggle { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; cursor: pointer; }
.osd { flex: 1; }
.osd-tooltip {
  position: absolute; pointer-events: none; z-index: 60; padding: 4px 8px; border-radius: 6px; font-size: 12px;
  background: #f0efec; color: #0b0b0b; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); white-space: nowrap;
}

/* OpenSeadragon injects this rule as an inline <style> (blocked by the page CSP) unless a
   style[data-openseadragon-mobile-css] element exists, see the matching <link> in index.html */
@media (hover: none) { .openseadragon-canvas:focus { outline: none !important; } }
