:root {
  --bg: #e4e6e9;
  --bg-2: #eceef0;
  --card: #f7f8f9;
  --surface: #ffffff;
  --sunken: #eef0f2;
  --ink: #111214;
  --ink-2: #33363b;
  --muted: #71767e;
  --faint: #a3a8af;
  --line: #e2e4e8;
  --line-2: #d6d9de;
  --lime: #d4f25a;
  --lime-soft: #eefbc0;
  --lime-ink: #4a6300;
  --red: #e5484d;
  --red-soft: #fdecec;
  --red-ink: #b4232a;
  --amber: #e9a23b;
  --amber-soft: #fdf3e1;
  --blue-soft: #e8eefb;
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 0 rgba(255,255,255,.9) inset, 0 1px 2px rgba(16,18,22,.04), 0 12px 32px -12px rgba(16,18,22,.12);
  --shadow-pop: 0 1px 0 rgba(255,255,255,1) inset, 0 2px 4px rgba(16,18,22,.05), 0 14px 30px -10px rgba(16,18,22,.18);
  --font: "Outfit", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #f3f4f6 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #eef0f2 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic-sm { width: 14px; height: 14px; }

.app { max-width: 1520px; margin: 0 auto; padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 18px; min-height: 100vh; }
.card { background: var(--card); border-radius: var(--radius-xl); box-shadow: var(--shadow-card); border: 1px solid rgba(255,255,255,.7); }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: flex-start; gap: 18px; padding: 12px 14px 12px 16px; position: sticky; top: 12px; z-index: 20; backdrop-filter: blur(12px); background: rgba(247,248,249,.88); }
.brand { flex: none; padding: 0 6px 0 8px; font-family: var(--font); font-size: 34px; font-weight: 400; letter-spacing: -.02em; line-height: 1; color: var(--ink); }

.cats { display: flex; gap: 10px; overflow-x: auto; flex: 0 1 auto; min-width: 0; padding: 14px 16px 22px; margin: -14px -16px -22px; scrollbar-width: none; scroll-snap-type: x proximity; }
.cats::-webkit-scrollbar { display: none; }
.cat-chip { width: 200px; flex: none; display: flex; align-items: center; gap: 12px; padding: 7px 14px 7px 7px; border-radius: 999px; border: 1px solid transparent; background: transparent; text-align: left; transition: background .15s, box-shadow .15s, border-color .15s; scroll-snap-align: start; }
.cat-chip:hover { background: rgba(255,255,255,.65); }
.cat-chip.active { background: var(--surface); box-shadow: var(--shadow-pop); }
.cat-chip .avatar { width: 48px; height: 48px; }
.cat-chip.active .avatar { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--lime); }
.cat-chip .meta { display: flex; flex-direction: column; min-width: 0; }
.cat-chip .name { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-chip .sub { font-family: var(--mono); font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.cat-chip.add { border: 1px dashed var(--line-2); width: auto; padding-right: 18px; color: var(--muted); }
.cat-chip.add:hover { color: var(--ink); border-color: var(--faint); }
.cat-chip.add .avatar { background: var(--sunken); display: grid; place-items: center; }

.avatar { border-radius: 50%; background: linear-gradient(135deg, #dfe2e6, #c9cdd3); overflow: hidden; display: grid; place-items: center; flex: none; color: var(--ink-2); font-weight: 600; font-size: 18px; transition: box-shadow .15s; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.topbar-actions { display: flex; gap: 8px; flex: none; margin-left: auto; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 500; font-size: 14px; white-space: nowrap; transition: transform .08s, background .15s, box-shadow .15s; box-shadow: 0 1px 2px rgba(16,18,22,.05); }
.btn:hover { box-shadow: 0 4px 12px -4px rgba(16,18,22,.15); }
.btn:active { transform: translateY(1px); }
.btn-dark { background: var(--ink); color: #fff; border-color: var(--ink); box-shadow: 0 8px 18px -8px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-dark:hover { background: #24262a; }
.btn-ghost { background: transparent; box-shadow: none; }
.btn-dashed { background: transparent; border: 1px dashed var(--line-2); box-shadow: none; height: 34px; padding: 0 14px; font-size: 13.5px; }
.btn-dashed:hover { border-color: var(--faint); background: rgba(255,255,255,.5); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn-icon { width: 40px; padding: 0; justify-content: center; }
.btn-icon.btn-sm { width: 30px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.kbd { font-family: var(--mono); font-size: 10.5px; padding: 2px 6px; border-radius: 6px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.2); }
.only-mobile { display: none; }

/* ---------- Segmented ---------- */
.seg { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--sunken); border: 1px solid var(--line); gap: 2px; }
.seg button { border: 0; background: transparent; height: 34px; padding: 0 16px; border-radius: 999px; color: var(--muted); font-size: 14px; display: inline-flex; align-items: center; gap: 8px; transition: background .15s, color .15s, box-shadow .15s; }
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); font-weight: 500; }
.count { font-family: var(--mono); font-size: 11px; min-width: 22px; height: 22px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: 999px; background: var(--lime); color: var(--lime-ink); font-weight: 500; box-shadow: 0 0 0 3px rgba(212,242,90,.25); }
.seg button:not(.active) .count { background: var(--line); color: var(--muted); box-shadow: none; }

/* ---------- Context header ---------- */
.context { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 6px 6px 4px; flex-wrap: wrap; }
#main { display: flex; flex-direction: column; gap: 18px; flex: 1; }
.context h1 { font-size: 40px; font-weight: 400; letter-spacing: -.02em; margin: 4px 0 2px; line-height: 1.05; }
.context .subtitle { color: var(--muted); font-size: 14px; }
.context-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- Workspace ---------- */
.workspace { display: grid; grid-template-columns: minmax(300px, 30%) 1fr; gap: 18px; align-items: start; flex: 1; }
.panel { padding: 18px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 4px 14px; }
.panel-head h2 { font-size: 19px; font-weight: 500; margin: 0; display: flex; align-items: center; gap: 10px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.list-scroll { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; padding: 4px; margin: -4px; }
.item { position: relative; text-align: left; width: 100%; border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px 16px 14px 36px; display: flex; flex-direction: column; gap: 5px;
  background: repeating-linear-gradient(135deg, rgba(0,0,0,.018) 0 6px, transparent 6px 12px), var(--sunken);
  transition: background .15s, box-shadow .15s, transform .15s, border-color .15s; }
.item:hover { background: var(--surface); border-color: var(--line-2); }
.item.active { background: var(--surface); box-shadow: var(--shadow-pop), 0 6px 0 -3px var(--lime); border-color: transparent; }
.item .grip { position: absolute; left: 13px; top: 17px; width: 10px; height: 16px; background-image: radial-gradient(circle, var(--faint) 1.2px, transparent 1.6px); background-size: 5px 5px; opacity: .8; }
.item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tag { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-family: var(--mono); font-size: 11px; color: var(--ink-2); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tag .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink); flex: none; }
.tag.lime { background: var(--lime-soft); border-color: #dcef9a; color: var(--lime-ink); }
.tag.red { background: var(--red-soft); border-color: #f6c9ca; color: var(--red-ink); }
.tag.red .dot { background: var(--red); }
.tag.amber { background: var(--amber-soft); border-color: #f3d9a8; color: #8a5a00; }
.tag.amber .dot { background: var(--amber); }
.tag.green .dot { background: transparent; border: 1.5px solid #6aa83a; }
.item-date { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.item-title { font-weight: 500; font-size: 15.5px; line-height: 1.3; }
.item-reason { font-size: 13.5px; color: var(--ink-2); }
.item-sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.list-foot { font-family: var(--mono); font-size: 11px; color: var(--muted); padding: 8px 4px 0; letter-spacing: .02em; }

/* ---------- Detail ---------- */
.detail { min-height: 520px; }
.detail-inner { padding: 8px 10px 10px; }
.detail-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.crumbs { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.detail h2.title { font-size: 30px; font-weight: 400; letter-spacing: -.015em; margin: 6px 0 10px; line-height: 1.15; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.chip .ic { width: 15px; height: 15px; color: var(--muted); }
.reason-box { margin-top: 16px; display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 16px; border-radius: var(--radius-md); background: var(--lime-soft); border: 1px solid #e1f2a4; }
.reason-box .label { font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--lime-ink); flex: none; }
.reason-box .text { flex: 1; font-weight: 500; }
.reason-box .btn { background: rgba(255,255,255,.7); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0; margin-top: 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stats { overflow: hidden; }
.stat { padding: 12px 14px; margin-left: -1px; border-left: 1px dashed var(--line-2); display: flex; flex-direction: column; gap: 2px; }
.stat .k { font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-size: 15px; font-weight: 500; }

.block { margin-top: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.block-head { flex-wrap: wrap; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: linear-gradient(#fff, #fbfbfc); }
.block-head h3 { margin: 0; font-size: 16px; font-weight: 500; }
.block-head .mono { font-size: 10.5px; }
.block-body { padding: 4px 18px; }

.entry { display: grid; grid-template-columns: minmax(140px, 28%) 1fr; gap: 6px 18px; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.entry:last-child { border-bottom: 0; }
.entry.nolabel { grid-template-columns: 1fr; }
.entry-label { font-weight: 500; font-size: 14px; color: var(--ink); }
.entry-label .anat { display: block; font-family: var(--mono); font-size: 10.5px; color: var(--muted); font-weight: 400; margin-top: 3px; letter-spacing: .02em; }
.entry-body { font-size: 14.5px; color: var(--ink-2); }
.entry-body .txt { white-space: pre-line; }
.entry-body .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.entry-status { margin-right: 6px; vertical-align: 1px; }
.entry.abnormal .entry-label { color: var(--red-ink); }
.measure { display: inline-flex; gap: 6px; align-items: baseline; padding: 3px 9px; border-radius: 8px; background: var(--sunken); font-size: 12.5px; }
.measure b { font-family: var(--mono); font-weight: 500; font-size: 12px; }
.note { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; margin-top: 6px; white-space: normal; }
.note::before { content: "i"; flex: none; width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--faint); font-family: var(--mono); font-size: 9.5px; display: grid; place-items: center; margin-top: 2px; }

.meds { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; white-space: normal; }
.med { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--card); display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.med-name { font-weight: 500; color: var(--ink); }
.med-detail { font-size: 13px; color: var(--muted); margin-top: 2px; }

.page-sep { display: flex; align-items: center; gap: 10px; margin: 26px 0 -6px; font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; color: var(--muted); }
.page-sep::after { content: ""; flex: 1; border-top: 1px dashed var(--line-2); }

.alert { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-md); background: var(--amber-soft); border: 1px solid #f3dcb0; font-size: 13.5px; color: #6e4b07; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

details.source { margin-top: 22px; border: 1px dashed var(--line-2); border-radius: var(--radius-lg); padding: 0 16px; }
details.source summary { cursor: pointer; padding: 14px 0; font-weight: 500; font-size: 14px; color: var(--ink-2); list-style: none; display: flex; align-items: center; gap: 8px; }
details.source summary::-webkit-details-marker { display: none; }
details.source summary::before { content: "+"; font-family: var(--mono); width: 20px; height: 20px; border-radius: 6px; border: 1px solid var(--line-2); display: grid; place-items: center; font-size: 12px; }
details.source[open] summary::before { content: "−"; }
details.source pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; line-height: 1.6; color: var(--ink-2); background: var(--sunken); padding: 14px; border-radius: 12px; margin: 0 0 16px; }

/* ---------- Results ---------- */
.res-table { width: 100%; border-collapse: collapse; }
.res-table th { font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 400; text-align: left; padding: 12px 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.res-table td { padding: 10px; border-bottom: 1px dashed var(--line); vertical-align: middle; font-size: 14px; }
.res-table tr:last-child td { border-bottom: 0; }
.res-table th:first-child, .res-table td:first-child { padding-left: 18px; }
.res-table th:last-child, .res-table td:last-child { padding-right: 14px; text-align: right; }
.res-table tr.out td { background: linear-gradient(90deg, rgba(229,72,77,.05), transparent 60%); }
.res-table tr.child td:first-child { padding-left: 38px; }
.p-name { font-weight: 500; }
.p-code { display: block; font-family: var(--mono); font-size: 10.5px; color: var(--faint); margin-top: 1px; }
.p-val { font-family: var(--mono); font-size: 14px; font-weight: 500; white-space: nowrap; }
.p-val .unit { color: var(--muted); font-weight: 400; font-size: 11.5px; margin-left: 4px; }
.p-val .arrow { color: var(--red); margin-left: 4px; font-size: 13px; }
.out .p-val { color: var(--red-ink); }
.p-range { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.p-text { font-size: 13.5px; color: var(--ink-2); }

.scale { position: relative; width: 100%; min-width: 110px; max-width: 260px; height: 30px; }
.res-table td:last-child { width: 1%; white-space: nowrap; }
.res-table td:nth-child(2) { white-space: nowrap; }
.panel-head h2 { white-space: nowrap; }
.scale .track { position: absolute; left: 0; right: 0; top: 9px; height: 8px; border-radius: 999px; background: var(--sunken); box-shadow: inset 0 1px 2px rgba(0,0,0,.06); }
.scale .norm { position: absolute; top: 9px; height: 8px; background: linear-gradient(#e4f5a2, #d4ee7a); border-left: 2px solid #8fae2a; border-right: 2px solid #8fae2a; }
.scale .norm.open-left { border-left: 0; border-radius: 999px 0 0 999px; }
.scale .norm.open-right { border-right: 0; border-radius: 0 999px 999px 0; }
.scale .mk { position: absolute; top: 5px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: var(--ink); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.scale .mk.out { background: var(--red); box-shadow: 0 0 0 4px rgba(229,72,77,.18), 0 1px 4px rgba(0,0,0,.3); }
.scale .mk.clamped::after { content: ""; position: absolute; top: 2px; width: 0; height: 0; border: 3px solid transparent; }
.scale .lbl { position: absolute; top: 20px; font-family: var(--mono); font-size: 9.5px; color: var(--muted); transform: translateX(-50%); white-space: nowrap; }
.scale .lbl.out { color: var(--red-ink); }

.summary-bar { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 18px; }

/* All parameters */
.search { position: relative; }
.search input { width: 100%; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 12px 0 38px; outline: none; }
.search input:focus { border-color: var(--faint); box-shadow: 0 0 0 4px rgba(212,242,90,.35); }
.search .ic { position: absolute; left: 12px; top: 11px; color: var(--muted); }
.spark { width: 110px; height: 30px; display: block; }

/* ---------- Empty states ---------- */
.empty { display: grid; place-items: center; text-align: center; padding: 60px 20px; color: var(--muted); gap: 10px; }
.empty .glyph { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; background: var(--sunken); border: 1px dashed var(--line-2); color: var(--faint); }
.empty .glyph .ic { width: 28px; height: 28px; }
.empty h3 { margin: 6px 0 0; color: var(--ink); font-weight: 500; font-size: 18px; }
.empty p { margin: 0; max-width: 380px; }
.hero-empty { padding: 90px 20px; }

/* ---------- Modals ---------- */
.modal-root { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(20,22,26,.28); backdrop-filter: blur(6px); animation: fade .15s ease-out; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--card); border-radius: var(--radius-xl); box-shadow: 0 30px 80px -20px rgba(0,0,0,.35); padding: 22px; animation: pop .18s cubic-bezier(.2,.9,.3,1.2); }
.modal.wide { width: min(940px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.modal-head h3 { margin: 4px 0 0; font-size: 24px; font-weight: 400; letter-spacing: -.01em; }
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field > span { font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.field input[type=text], .field select { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; outline: none; }
.field input[type=text]:focus, .field select:focus { border-color: var(--faint); box-shadow: 0 0 0 4px rgba(212,242,90,.35); }
.drop { border: 1.5px dashed var(--line-2); border-radius: var(--radius-lg); padding: 22px; text-align: center; background: var(--surface); color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.drop:hover, .drop.over { border-color: #9dbb2f; background: var(--lime-soft); color: var(--lime-ink); }
.drop.has { border-style: solid; border-color: #bcd65b; background: var(--lime-soft); color: var(--ink); }
.drop input { display: none; }
.drop b { color: var(--ink); font-weight: 500; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.form-error { color: var(--red-ink); background: var(--red-soft); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.photo-pick { display: flex; align-items: center; gap: 16px; }
.photo-pick .avatar { width: 84px; height: 84px; font-size: 28px; box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--lime); }

/* Chart */
.chart-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 10px 10px 4px; position: relative; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { font-family: var(--mono); font-size: 10.5px; fill: var(--muted); }
.chart .refline { stroke: var(--ink); stroke-width: 1.2; stroke-dasharray: 5 5; fill: none; opacity: .5; }
.chart .refband { fill: #e8f6b0; opacity: .45; }
.chart .reflabel { font-family: var(--mono); font-size: 10.5px; fill: var(--ink-2); }
.chart .series { stroke: var(--ink); stroke-width: 2; fill: none; }
.chart .area { fill: url(#areaGrad); }
.chart .pt { fill: var(--ink); stroke: #fff; stroke-width: 2.5; cursor: pointer; transition: r .1s; }
.chart .pt.out { fill: var(--red); }
.chart .pt:hover { r: 8; }
.chart .ptlabel { font-family: var(--mono); font-size: 11px; fill: var(--ink); font-weight: 500; }
.chart .ptlabel.out { fill: var(--red-ink); }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; padding: 8px 10px; border-radius: 10px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, calc(-100% - 12px)); box-shadow: 0 10px 20px -8px rgba(0,0,0,.4); }
.chart-tip .mono { color: #c9cdd3; font-size: 10px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; padding: 10px 4px 0; font-family: var(--mono); font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.legend i.red { background: var(--red); }
.legend i.dash { width: 18px; height: 0; border-top: 1.5px dashed var(--ink-2); border-radius: 0; }
.hist-table { margin-top: 16px; }

/* Toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.toast { background: var(--ink); color: #fff; border-radius: 14px; padding: 12px 16px; max-width: 420px; box-shadow: 0 16px 40px -12px rgba(0,0,0,.45); font-size: 14px; animation: pop .2s ease-out; display: flex; gap: 10px; align-items: flex-start; }
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); margin-top: 6px; flex: none; }
.toast.err .dot { background: var(--red); }
.toast small { display: block; color: #c4c8ce; margin-top: 4px; }

.loading { padding: 50px; text-align: center; color: var(--muted); font-family: var(--mono); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.back-btn { display: none; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Desktop: panele do dołu okna, przewijanie w środku ---------- */
@media (min-width: 821px) {
  .app { height: 100vh; height: 100dvh; min-height: 560px; padding-bottom: 24px; }
  #main { min-height: 0; }
  .workspace { min-height: 0; grid-template-rows: minmax(0, 1fr); align-items: stretch; }
  .workspace > .panel { display: flex; flex-direction: column; min-height: 0; }
  .list { flex: 1; min-height: 0; }
  .list-scroll { flex: 1; min-height: 0; }
  .detail { min-height: 0; overflow: hidden; }
  .detail-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding-right: 6px; }
  /* Nagłówek na tej samej siatce co panele: zakładki zaczynają się równo z lewą krawędzią prawego panelu */
  .context { display: grid; grid-template-columns: minmax(300px, 30%) 1fr; column-gap: 18px; align-items: end; padding: 6px 0 4px; }
  .context > div:first-child { padding-left: 6px; min-width: 0; }
  .context-actions { justify-content: space-between; }
}
@media (min-width: 821px) and (max-width: 1100px) {
  .context { grid-template-columns: minmax(280px, 36%) 1fr; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(280px, 36%) 1fr; }
  .res-table .col-range { display: none; }
  .hide-xs { display: none; }
  .res-table td:last-child .btn { width: 30px; padding: 0; justify-content: center; }
}
@media (min-width: 821px) and (max-width: 1100px) {
  .panel-head { flex-wrap: wrap; }
}
@media (max-width: 820px) {
  body { font-size: 14.5px; }
  .app { padding: 10px 12px 30px; gap: 12px; }
  .only-mobile { display: inline-flex; }
  .topbar { flex-wrap: wrap; position: relative; top: 0; padding: 10px; gap: 10px; border-radius: 22px; }
  .topbar-actions .btn { height: 38px; padding: 0 14px; }
  .cats { order: 3; flex-basis: 100%; margin: -10px -10px -18px; padding: 10px 10px 18px; }
  .cat-chip { width: auto; min-width: 150px; padding-right: 16px; }
  .cat-chip .avatar { width: 40px; height: 40px; }
  .context h1 { font-size: 30px; }
  .brand { font-size: 28px; padding-left: 6px; }
  .context { padding: 0 2px; }
  .context-actions { width: 100%; }
  .context-actions .seg { flex: 1; }
  .context-actions .seg button { flex: 1; justify-content: center; padding: 0 10px; }
  .workspace { grid-template-columns: 1fr; }
  .list-scroll { overflow: visible; }
  .workspace.show-detail .list-panel { display: none; }
  .workspace:not(.show-detail) .detail { display: none; }
  .back-btn { display: inline-flex; margin-bottom: 12px; }
  .panel { padding: 14px; border-radius: 22px; }
  .detail-inner { padding: 2px; }
  .detail h2.title { font-size: 24px; }
  .entry { grid-template-columns: 1fr; gap: 4px; }
  .block-body { padding: 2px 14px; }
  .res-table th.col-range, .res-table td.col-range { display: none; }
  .res-table td, .res-table th { padding: 9px 6px; }
  .res-table th:first-child, .res-table td:first-child { padding-left: 12px; }
  .res-table td.col-scale { min-width: 0; }
  .scale { min-width: 90px; }
  .modal { padding: 18px; border-radius: 22px; }
  .modal-root { padding: 10px; align-items: end; }
  .toasts { left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
}
.scale-inline { display: none; }
.btn-dashed.active { border-style: solid; border-color: var(--ink); background: var(--surface); }
.btn-params { height: 34px; padding: 0 14px; font-size: 13.5px; }
.btn-params.active { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--lime); }
@media (max-width: 560px) {
  .panel-head { flex-wrap: wrap; }
  .topbar-actions .btn { padding: 0 12px; }
  .res-table .col-scale { display: none; }
  .scale-inline { display: block; margin-top: 6px; }
  .scale-inline .scale { max-width: none; }
  .hide-xs { display: none; }
  .res-table td:last-child .btn { width: 30px; padding: 0; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Dane (lista plików) ---------- */
.files { display: flex; flex-direction: column; gap: 8px; }
.file-row { display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center; padding: 12px 12px 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.file-row .fi { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--sunken); color: var(--ink-2); }
.file-row .fi.res { background: var(--lime-soft); color: var(--lime-ink); }
.file-name { font-weight: 500; font-size: 14.5px; word-break: break-all; }
.file-meta { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.file-meta .mono { font-size: 11px; letter-spacing: .02em; text-transform: none; }
.file-group { font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 14px 2px 2px; }
.file-group:first-child { margin-top: 0; }
.btn-danger { color: var(--red-ink); }
.btn-danger.confirm { background: var(--red); border-color: var(--red); color: #fff; }
@media (max-width: 560px) {
  .exit-form .lbl { display: none; }
  .exit-form .btn { width: 38px; padding: 0; justify-content: center; }
  .topbar-actions { gap: 6px; }
  .file-row { grid-template-columns: 1fr auto; }
  .file-row .fi { display: none; }
}

/* ---------- Wyjście / bramka tokenu ---------- */
.exit-form { display: contents; }
