:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --text: #17212b;
  --muted: #5d6b7a;
  --line: #d5dbe3;
  --brand: #12202f;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --ok: #1f7a3d;
  --err: #b42318;
  --radius: 12px;
  --tap: 52px; /* velká tlačítka – ovladatelné i v rukavicích */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1620;
    --surface: #18232f;
    --text: #e8edf2;
    --muted: #9aa8b6;
    --line: #2b3a4a;
    --brand: #0a121b;
    --accent: #f76707;
    --ok: #51cf66;
    --err: #ff8787;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.5rem; margin: 0; }
h1 span { color: var(--accent); }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .25rem; }
.muted { color: var(--muted); }
a { color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem;
  padding-top: calc(.6rem + env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.topbar form { margin: 0; }
.brand { font-weight: 700; text-decoration: none; }
.brand span { color: #ffa94d; font-weight: 600; }

main {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem 1rem 6rem;
}
main.centered { display: grid; place-items: center; padding-bottom: 1rem; }

.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
}
.card.auth { width: 100%; max-width: 420px; }
.card.auth h1 { margin-bottom: 1rem; }
.card.empty { text-align: center; padding: 2.5rem 1rem; }

form { display: grid; gap: .9rem; }
label { display: grid; gap: .3rem; font-weight: 600; font-size: .95rem; }
input {
  width: 100%;
  min-height: var(--tap);
  padding: .6rem .8rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

button, .button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap);
  padding: .6rem 1.2rem;
  font: inherit; font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
}
button.primary, .button.primary {
  background: var(--accent); color: var(--accent-text); border-color: transparent;
}
button:disabled { opacity: .5; cursor: not-allowed; }
button.link {
  min-height: 40px; padding: .3rem .5rem;
  background: none; border: 0; color: #fff; font-weight: 500; text-decoration: underline;
}

.alert { margin: 0 0 1rem; padding: .7rem .9rem; border-radius: 10px; font-weight: 600; }
.alert.error { color: var(--err); border: 1px solid var(--err); }
.alert.ok { color: var(--ok); border: 1px solid var(--ok); }

.badge {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px;
  font-size: .8rem; font-weight: 700; border: 1px solid var(--line);
}
.badge.on { color: var(--ok); border-color: var(--ok); }
.badge.off { color: var(--muted); }

ul.plain, ul.case-list { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: .35rem 0; }
dl.status { display: grid; grid-template-columns: auto 1fr; gap: .5rem 1rem; margin: 0 0 .75rem; }
dl.status dt { font-weight: 600; }
dl.status dd { margin: 0; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: grid; place-items: center;
  min-height: 60px;
  font-weight: 700; text-decoration: none; color: var(--muted);
}
.tabbar a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

/* --- Fáze 1: případ ------------------------------------------------------ */
.small { font-size: .85rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
textarea {
  width: 100%; padding: .6rem .8rem; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; resize: vertical;
}
textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input[type=file] { padding: .7rem .6rem; }
button.big, .button.big { width: 100%; min-height: 60px; font-size: 1.1rem; }
form.inline { display: inline-grid; margin-left: .5rem; }
form + #research-status { margin-top: 1rem; }

a.case-row { display: grid; gap: .4rem; text-decoration: none; }
a.case-row .meta { display: flex; align-items: center; gap: .6rem; }

.case-head h1 { margin-bottom: .25rem; }
.case-head p { margin: .35rem 0; }
.symptoms { white-space: pre-line; }
.dtcs { display: flex; flex-wrap: wrap; gap: .4rem; }
.badge.dtc { font-family: ui-monospace, monospace; font-size: .95rem; color: var(--accent); border-color: var(--accent); }

.providers { list-style: none; margin: 0 0 .75rem; padding: 0; display: grid; gap: .5rem; }
.providers li { display: flex; align-items: flex-start; gap: .6rem; }
.providers .icon {
  flex: none; width: 1.8rem; height: 1.8rem; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--line); font-weight: 700;
}
.providers small { display: block; color: var(--muted); }
.providers .st-done .icon { color: var(--ok); border-color: var(--ok); }
.providers .st-error .icon { color: var(--err); border-color: var(--err); }
.providers .st-error small { color: var(--err); }
.providers .st-running .icon { border-color: var(--accent); }
.providers .st-off, .providers .st-skipped { color: var(--muted); }

.tabs {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: .25rem;
  margin-bottom: 1rem; border-bottom: 1px solid var(--line);
}
.tabs a {
  display: grid; place-items: center; min-height: var(--tap); padding: 0 .25rem;
  font-weight: 700; text-decoration: none; color: var(--muted); text-align: center;
}
.tabs a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.tabs .count { font-weight: 500; }

.alert.warn { color: var(--text); border: 1px solid var(--accent); }
.alert.danger { color: #fff; background: var(--err); }
@media (prefers-color-scheme: dark) { .alert.danger { color: #1a0000; } }

.hypothesis header { display: flex; align-items: flex-start; gap: .7rem; margin-bottom: .6rem; }
.hypothesis header h2 { flex: 1; margin: 0; }
.rank {
  flex: none; width: 2rem; height: 2rem; display: grid; place-items: center;
  border-radius: 50%; background: var(--accent); color: var(--accent-text); font-weight: 800;
}
.conf { flex: none; font-weight: 800; color: var(--muted); }
.next { padding: .7rem .9rem; border-left: 4px solid var(--accent); background: var(--bg); border-radius: 6px; }

ol.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
ol.steps > li { padding: .9rem 0; border-top: 1px solid var(--line); }
ol.steps p { margin: .35rem 0 0 2.6rem; }
label.check { display: flex; align-items: flex-start; gap: .8rem; font-weight: 600; font-size: 1rem; cursor: pointer; }
label.check input { flex: none; width: 1.8rem; height: 1.8rem; min-height: 0; margin: 0; accent-color: var(--accent); }
.expected { padding: .5rem .7rem; background: var(--bg); border-radius: 8px; }
details.measured { margin: .6rem 0 0 2.6rem; }
details.measured summary {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 1rem;
  border: 1px solid var(--line); border-radius: 10px; font-weight: 700; cursor: pointer;
}
details.measured form { margin-top: .8rem; }

ul.rows li { display: grid; gap: .15rem; padding: .7rem 0; border-top: 1px solid var(--line); }
ul.rows li:first-child { border-top: 0; }
ul.rows .value { font-size: 1.15rem; font-weight: 700; }
.source h3 { margin: .2rem 0 .4rem; overflow-wrap: anywhere; }
.pre { white-space: pre-line; overflow-wrap: anywhere; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; }

small.ok { color: var(--ok); }
small.err { color: var(--err); }

form.variants { gap: .5rem; margin-bottom: 1rem; }
form.variants button { justify-content: flex-start; text-align: left; font-weight: 600; }
form.inline-left { display: block; }
button.link-dark { min-height: 40px; padding: .2rem 0; background: none; border: 0; color: var(--muted); font-weight: 500; text-decoration: underline; }
.providers .st-blocked .icon { color: var(--err); border-color: var(--err); }
.providers .st-blocked small { color: var(--err); }

/* --- Hypotézy jako rozbalovací seznam ----------------------------------- */
.listhint { margin: -.4rem 0 .6rem; }
.card.summary { padding-bottom: .6rem; }
.card.summary .next { margin-top: 0; }
.card.summary > details > summary,
details.hypothesis > summary {
  cursor: pointer; list-style: none; -webkit-tap-highlight-color: transparent;
}
.card.summary > details > summary::-webkit-details-marker,
details.hypothesis > summary::-webkit-details-marker { display: none; }
.card.summary > details > summary {
  min-height: 44px; display: flex; align-items: center; gap: .5rem;
  font-weight: 700; color: var(--muted);
}
.card.summary > details > summary::after { content: "▾"; }
.card.summary > details[open] > summary::after { content: "▴"; }

details.hypothesis { padding: 0; overflow: hidden; }
details.hypothesis > summary {
  display: flex; align-items: center; gap: .8rem;
  min-height: 68px; padding: .8rem 1.1rem;
}
details.hypothesis > summary::after {
  content: "▾"; flex: none; color: var(--muted); font-size: 1.1rem;
}
details.hypothesis[open] > summary::after { content: "▴"; }
details.hypothesis[open] > summary { border-bottom: 1px solid var(--line); }
.htitle { flex: 1; font-weight: 700; line-height: 1.25; }
.htitle small { display: block; font-weight: 500; font-size: .82rem; margin-top: .15rem; }
.hbody { padding: 1rem 1.1rem 1.2rem; }
.hbody > p:first-child { margin-top: 0; }
details.hypothesis .alert.danger { margin-bottom: .8rem; }

.source-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; margin: .8rem 0; }
.source-images figure { margin: 0; }
.source-images img {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; display: block;
  background: #fff; max-height: 220px; object-fit: contain;
}
.source-images figcaption { margin-top: .25rem; overflow-wrap: anywhere; }

/* --- Uzavření případu a historie ---------------------------------------- */
.card.closed { border-left: 4px solid var(--ok); }
.card.closed h2 { color: var(--ok); }
details.closing > summary {
  cursor: pointer; list-style: none; min-height: 48px; display: flex; align-items: center;
  font-weight: 700;
}
details.closing > summary::-webkit-details-marker { display: none; }
details.closing > summary::after { content: " ▾"; margin-left: auto; color: var(--muted); }
details.closing[open] > summary::after { content: " ▴"; }
details.closing form { margin-top: 1rem; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .8rem; margin: 0; }
legend { font-weight: 700; padding: 0 .4rem; }
.outcome { padding: .5rem 0; border-top: 1px solid var(--line); }
.outcome:first-of-type { border-top: 0; }
.outcome .choices { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-top: .4rem; }
.outcome label { flex-direction: row; align-items: center; display: flex; gap: .35rem; font-weight: 500; }
.outcome input { width: 1.4rem; height: 1.4rem; min-height: 0; accent-color: var(--accent); }
label.check.inline { flex-direction: row; align-items: center; }
select {
  min-height: var(--tap); padding: .6rem .8rem; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
a.case-row .found { font-size: .9rem; }
a.case-row .dtcs { gap: .3rem; }

/* Dlouhý název v seznamu zkrátíme na dva řádky; po rozbalení je vidět celý. */
details.hypothesis:not([open]) .htitle {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
details.hypothesis:not([open]) .htitle .steps-hint { display: none; }
details.hypothesis:not([open]) > summary { align-items: flex-start; }

/* --- Vyfocení diagnostiky ------------------------------------------------ */
.card.scan { border: 1px solid var(--accent); }
label.button.camera { cursor: pointer; margin-top: .4rem; }
label.button.camera.busy { opacity: .6; pointer-events: none; }
.card.scan .reading { margin: .6rem 0 0; font-weight: 600; color: var(--accent); }
