/* ==========================================================================
   Lab UI — shared design system for the portfolio web apps
   Zero dependencies. Dark "instrument panel" aesthetic.
   ========================================================================== */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(../fonts/inter-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(../fonts/inter-greek.woff2) format('woff2');
  unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url(../fonts/jetbrains-mono-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url(../fonts/jetbrains-mono-greek.woff2) format('woff2');
  unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
}

:root {
  --bg: #070b15;
  --bg-2: #0a1020;
  --panel: #0e1528;
  --panel-2: #0b1122;
  --panel-3: #141d36;
  --inset: #060a14;
  --border: #1b2542;
  --border-2: #26335a;
  --text: #e8edfb;
  --text-2: #a9b4d6;
  --muted: #6b779f;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --info: #60a5fa;
  --accent: #60a5fa;
  --accent-2: #a78bfa;
  --accent-ink: #06101f;
  --accent-soft: rgba(96, 165, 250, 0.14);
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --sidebar-w: 312px;
  color-scheme: dark;
}

body[data-domain='mechatronics'] { --accent: #fbbf24; --accent-2: #fb923c; --accent-soft: rgba(251, 191, 36, 0.13); }
body[data-domain='medical']      { --accent: #2dd4bf; --accent-2: #38bdf8; --accent-soft: rgba(45, 212, 191, 0.13); }
body[data-domain='assistive']    { --accent: #a78bfa; --accent-2: #34d399; --accent-soft: rgba(167, 139, 250, 0.14); }
body[data-domain='ai']           { --accent: #f472b6; --accent-2: #818cf8; --accent-soft: rgba(244, 114, 182, 0.13); }
body[data-domain='research']     { --accent: #22d3ee; --accent-2: #a3e635; --accent-soft: rgba(34, 211, 238, 0.13); }
body[data-domain='health']       { --accent: #34d399; --accent-2: #fbbf24; --accent-soft: rgba(52, 211, 153, 0.13); }
body[data-domain='tools']        { --accent: #818cf8; --accent-2: #38bdf8; --accent-soft: rgba(129, 140, 248, 0.14); }

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 110% -10%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, color-mix(in srgb, var(--accent-2) 6%, transparent), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

code, kbd, .mono { font-family: var(--font-mono); font-size: 0.92em; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--panel-3);
  color: var(--text);
  font-size: 11px;
  text-align: center;
  line-height: 1.5;
}

::selection { background: color-mix(in srgb, var(--accent) 40%, transparent); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 10px; border: 2px solid var(--bg-2); }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------- Layout */

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
  min-height: 560px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(14, 21, 40, 0.92), rgba(10, 16, 32, 0.92));
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 5;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  white-space: nowrap;
}
.back-link:hover { color: var(--text); text-decoration: none; border-color: var(--border-2); }
.back-link svg { width: 15px; height: 15px; flex: none; }

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 30%, transparent), color-mix(in srgb, var(--accent-2) 20%, transparent));
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
}
.brand-icon svg { width: 20px; height: 20px; }
.brand-text { min-width: 0; }
.brand-title { font-size: 17px; font-weight: 700; letter-spacing: -0.015em; white-space: nowrap; }
.brand-title .accent { color: var(--accent); }
.brand-sub { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  white-space: nowrap;
}
.chip.neutral { color: var(--text-2); background: var(--panel-3); border-color: var(--border-2); }
.chip.good { color: var(--good); background: rgba(52, 211, 153, 0.12); border-color: rgba(52, 211, 153, 0.35); }
.chip.warn { color: var(--warn); background: rgba(251, 191, 36, 0.12); border-color: rgba(251, 191, 36, 0.35); }
.chip.bad { color: var(--bad); background: rgba(251, 113, 133, 0.12); border-color: rgba(251, 113, 133, 0.35); }

.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(13, 20, 38, 0.75), rgba(9, 14, 28, 0.75));
  overflow-y: auto;
  padding: 6px 0 24px;
  min-height: 0;
}

.main {
  min-width: 0;
  min-height: 0;
  padding: 14px;
  overflow: auto;
}

/* ---------------------------------------------------------------- Sidebar sections */

.section { padding: 12px 16px 14px; border-bottom: 1px solid var(--border); }
.section:last-child { border-bottom: none; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.section-title .hint { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted); }

.field { margin: 10px 0 12px; }
.field:first-child { margin-top: 0; }
.field-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.field label, .field .label { font-size: 12.5px; color: var(--text-2); }
.field .value { font-family: var(--font-mono); font-size: 12px; color: var(--text); background: var(--inset); border: 1px solid var(--border); padding: 1px 7px; border-radius: 6px; white-space: nowrap; }
.field .help { font-size: 11.5px; color: var(--muted); margin-top: 5px; }

.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row > .grow { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* Range inputs */
input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  margin: 0;
  cursor: pointer;
  --pct: 50%;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--accent) 0 var(--pct), var(--border-2) var(--pct) 100%);
}
input[type='range']::-moz-range-track { height: 5px; border-radius: 5px; background: var(--border-2); }
input[type='range']::-moz-range-progress { height: 5px; border-radius: 5px; background: var(--accent); }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
input[type='range']::-moz-range-thumb {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
}
input[type='range']:focus-visible { outline: none; }
input[type='range']:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 35%, transparent); }

/* Selects & text inputs */
select, input[type='text'], input[type='number'] {
  width: 100%;
  background: var(--inset);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  outline: none;
}
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
  cursor: pointer;
}
select:focus, input[type='text']:focus, input[type='number']:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
option { background: var(--panel); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 13px;
  border-radius: 9px;
  border: 1px solid var(--border-2);
  background: var(--panel-3);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s, box-shadow 0.15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border-2)); background: #18223f; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 100%, #fff 8%), var(--accent));
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 700;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 25%, transparent);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

/* Segmented control */
.seg {
  display: flex;
  padding: 3px;
  gap: 3px;
  border-radius: 10px;
  background: var(--inset);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}
.seg button {
  flex: 1 1 auto;
  padding: 6px 8px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.seg button:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.seg button.active { background: var(--panel-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-2), 0 1px 0 rgba(255, 255, 255, 0.04); }
.seg button.active::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: 1px; }
.seg.no-dot button.active::before { display: none; }

/* Toggle switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; margin: 8px 0; font-size: 12.5px; color: var(--text-2); user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { position: relative; width: 34px; height: 19px; border-radius: 20px; background: var(--border-2); flex: none; transition: background 0.15s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 13px; height: 13px; border-radius: 50%; background: #cfd6ee; transition: transform 0.15s, background 0.15s; }
.switch input:checked + .track { background: color-mix(in srgb, var(--accent) 75%, #000 10%); }
.switch input:checked + .track::after { transform: translateX(15px); background: #fff; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- Panels */

.panel {
  background: linear-gradient(180deg, rgba(16, 24, 45, 0.9), rgba(12, 18, 35, 0.9));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  min-height: 40px;
}
.panel-title { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.panel-title .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.panel-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-head .spacer { flex: 1; }
.panel-body { position: relative; flex: 1; min-height: 0; }
.panel-body.pad { padding: 12px; }

.canvas-wrap { position: relative; width: 100%; height: 100%; min-height: 0; }
.canvas-wrap > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
canvas.interactive { cursor: crosshair; touch-action: none; }

.overlay-label {
  position: absolute;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(6, 10, 20, 0.72);
  border: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-2);
  pointer-events: none;
  backdrop-filter: blur(4px);
}
.overlay-label.tl { top: 10px; left: 10px; }
.overlay-label.tr { top: 10px; right: 10px; }
.overlay-label.bl { bottom: 10px; left: 10px; }
.overlay-label.br { bottom: 10px; right: 10px; }

/* Metric tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }
.stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  min-width: 0;
}
.stat .k { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v { font-family: var(--font-mono); font-size: 18px; font-weight: 600; color: var(--text); margin-top: 3px; white-space: nowrap; }
.stat .v .u { font-size: 11px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.stat.accent .v { color: var(--accent); }
.stat.good .v { color: var(--good); }
.stat.warn .v { color: var(--warn); }
.stat.bad .v { color: var(--bad); }

/* Legend */
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.box { width: 10px; height: 10px; border-radius: 3px; }

/* Progress bars */
.bar { height: 8px; border-radius: 8px; background: var(--inset); border: 1px solid var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 8px; transition: width 0.12s linear; }

/* Notes / callouts */
.note { font-size: 12px; color: var(--text-2); background: var(--panel-2); border: 1px dashed var(--border-2); border-radius: 9px; padding: 9px 11px; }
.note b { color: var(--text); }
.muted { color: var(--muted); }
.dim { color: var(--text-2); }
.accent-text { color: var(--accent); }

/* ---------------------------------------------------------------- Drawer ("How it works") */

.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(2, 5, 12, 0.55);
  backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
  z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(560px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--border-2);
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.45);
  transform: translateX(102%);
  transition: transform 0.25s ease;
  z-index: 41;
  display: flex; flex-direction: column;
}
body.drawer-open .drawer { transform: none; }
body.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 16px; }
.drawer-body { padding: 6px 22px 30px; overflow-y: auto; font-size: 13.5px; line-height: 1.62; color: var(--text-2); }
.drawer-body h3 { color: var(--text); font-size: 14.5px; margin: 20px 0 6px; }
.drawer-body p { margin: 8px 0; }
.drawer-body ul, .drawer-body ol { padding-left: 20px; margin: 8px 0; }
.drawer-body li { margin: 4px 0; }
.drawer-body strong { color: var(--text); }
.eq {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
  background: var(--inset);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 9px 12px;
  margin: 10px 0;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.55;
}

/* Toast */
.toast-host { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; }
.toast {
  background: rgba(15, 22, 42, 0.96);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Tooltip-ish inline info */
.info-dot { display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--border-2); color: var(--muted); font-size: 10px; font-weight: 700; cursor: help; }

/* Tables */
table.table { width: 100%; border-collapse: collapse; font-size: 12px; }
table.table th, table.table td { padding: 5px 6px; border-bottom: 1px solid var(--border); text-align: right; font-family: var(--font-mono); }
table.table th { color: var(--muted); font-weight: 600; font-family: var(--font-sans); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }
table.table td:first-child, table.table th:first-child { text-align: left; }

/* ---------------------------------------------------------------- Responsive */

@media (max-width: 1100px) {
  :root { --sidebar-w: 280px; }
  .brand-sub { display: none; }
}

@media (max-width: 860px) {
  .app { height: auto; min-height: 100vh; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { order: 2; border-right: none; border-top: 1px solid var(--border); overflow: visible; }
  .main { order: 1; overflow: visible; padding: 10px; }
  .topbar { flex-wrap: wrap; padding: 10px 12px; }
  .topbar .chip { display: none; }
  .back-link span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
