/* Ordo: mobile first, large targets, readable in daylight (Konzept §1-§2, R-08). */
:root {
  /* Light and dark in one place; the device decides unless someone chose in the footer. */
  color-scheme: light dark;
  --bg: light-dark(#ffffff, #111418);
  --fg: light-dark(#111418, #f2f4f6);
  --muted: light-dark(#555c66, #a8b0ba);
  --line: light-dark(#d4d8de, #333a42);
  --card: light-dark(#f3f5f7, #1c2127);
  --accent: light-dark(#0b5cad, #5aa7ff);
  --accent-fg: light-dark(#ffffff, #0b1220);
  --here: light-dark(#fff4c2, #3a3214);
  --warn: light-dark(#8a4b00, #ffc27a);
  --warn-bg: light-dark(#fff1dc, #3a2a12);
  --cancel-bg: light-dark(#e3e6eb, #33373f);
  --error: light-dark(#a3161b, #ff8a8f);
  --ok: light-dark(#17663a, #6fd69a);
  --radius: 12px;
  --tap: 52px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 18px/1.45 Montserrat, sans-serif;
}
main { max-width: 40rem; margin: 0 auto; padding: 0 16px 2rem; }
h1 { font-size: 1.5rem; margin: 1rem 0 .5rem; overflow-wrap: anywhere; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .9rem; }

/* Top bar and navigation */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 40rem; margin: 0 auto; padding: 8px 16px; }
.nav { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.nav a {
  display: flex; align-items: center; justify-content: center; min-height: 44px; border-radius: 10px;
  text-decoration: none; color: var(--fg); background: var(--card); font-weight: 600; font-size: .95rem;
}
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-fg); }

/* "Ich bin hier" line at the top (E-128, E-129) */
.iam {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 44px; margin-top: 6px;
  padding: 6px 12px; border-radius: 10px; background: var(--here); color: var(--fg); text-decoration: none;
}
.iam-label { font-size: .85rem; color: var(--muted); }
.iam strong { overflow-wrap: anywhere; }
.iam-with { font-size: .95rem; }
.iam-animal { font-size: .85rem; color: var(--muted); }

/* Place hierarchy: one indented line per level (E-133) */
:root { --indent: 18px; }
.tree { list-style: none; margin: 4px 0 10px; padding: 0; }
.tree li { position: relative; padding-left: calc(var(--depth) * var(--indent)); }
/* The hook: a line straight below the text of the level above, bending right to this one. It starts below
   that line, so it never crosses a name that wraps. */
.tree li:not([style*="--depth:0"])::before, .front-row.nested::before {
  content: ""; position: absolute; border-left: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  border-bottom-left-radius: 6px;
}
.tree li:not([style*="--depth:0"])::before {
  top: 0; height: 18px; left: calc((var(--depth) - 1) * var(--indent) + 6px); width: calc(var(--indent) - 4px);
}
.tree-line {
  display: block; padding: 6px 0 6px 6px; color: var(--fg);
  text-decoration: none; overflow-wrap: anywhere;
}
a.tree-line { min-height: 40px; }
a.tree-line .tree-name, .tree-choice .tree-name { text-decoration: underline; text-underline-offset: 3px; }
.tree-choice {
  width: 100%; min-height: 40px; background: none; border: 0; border-radius: 0; font: inherit;
  text-align: left; cursor: pointer;
}
.tree-kind, .tree-animal { color: var(--muted); }

/* "Habe ich vor mir" */
.front-row { display: flex; align-items: center; gap: 8px; }
.front-row form { margin: 0; }
.front-row > a { flex: 1; min-width: 0; }
.front-row > form { flex: none; }
.front-row.current .name { font-weight: 800; }
.front-row > a.row-sign { flex: none; justify-content: center; min-height: 0; padding: 0; }
.front-row { --row-indent: 26px; --row-text: 4px; }  /* --row-text: the padding of the link in a list */
.front-row.nested { position: relative; padding-left: calc(var(--depth) * var(--row-indent)); }
.front-row.nested::before {
  top: 5px; height: calc(50% - 5px); left: calc((var(--depth) - 1) * var(--row-indent) + var(--row-text));
  width: calc(var(--row-indent) - 11px);
}
.front-row.current { box-shadow: inset 4px 0 0 var(--accent); padding-left: 8px; }
.front-row.current.nested { padding-left: calc(var(--depth) * var(--row-indent)); }
.row-sign {
  display: flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px; padding: 0;
  background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; font: inherit;
  font-size: 1.3rem; line-height: 1; cursor: pointer;
}
/* + turns into ×, and the offer to move it here lies over the name when there is no room */
.move-offer { margin: 0; flex: none; position: relative; }
.move-offer > summary.row-sign { min-height: 0; padding: 0; gap: 0; }
.move-offer > summary::before { content: "+"; font-size: 1.3rem; }
.move-offer[open] > summary::before { content: "×"; }
.move-offer[open] > summary { margin-bottom: 0; }
.move-offer form { position: absolute; top: 0; right: 44px; margin: 0; z-index: 2; }
.move-here {
  height: 36px; padding: 0 12px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-fg);
  font: inherit; font-size: .9rem; font-weight: 700; white-space: nowrap; cursor: pointer;
  max-width: calc(100vw - 96px); overflow: hidden; text-overflow: ellipsis;
}
.undo { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.undo form { margin: 0; }
.undo .ok { color: var(--ok); }
.undo .btn { width: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chips form { margin: 0; }
.chip {
  min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); font: inherit; font-size: 1rem;
}
.chip.current { border: 2px solid var(--fg); font-weight: 700; }

/* Buttons and forms */
.btn, button.btn {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: var(--tap);
  padding: 10px 16px; border: 0; border-radius: var(--radius); font: inherit; font-weight: 700;
  background: var(--accent); color: var(--accent-fg); text-decoration: none; cursor: pointer; margin: 8px 0;
}
.btn.secondary { background: var(--card); color: var(--fg); border: 1px solid var(--line); }
.btn.danger { background: var(--card); color: var(--error); border: 1px solid var(--line); }
.btn.cancel { background: var(--cancel-bg); color: var(--fg); border: 1px solid transparent; }
/* The field with the + numbers, below the two actions with the − numbers */
.amount-row { display: grid; grid-template-columns: minmax(0, 1fr) repeat(3, 44px); gap: 6px; margin-bottom: 8px; }
.amount-row input { min-width: 0; margin: 0; }
.amount-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.stock-head { margin: 0 0 10px; }
.stock-head h1 { margin: 0; }
.stock-head .btn { width: auto; min-height: 44px; margin: 0; padding: 0 12px; }
.amount-row .btn { min-height: 44px; margin: 0; padding: 0 4px; }
.amount-step {
  min-height: 44px; padding: 0; background: var(--card); color: var(--fg); font: inherit;
  font-size: .9rem; font-weight: 700; border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.row3 .btn { padding: 10px 6px; font-size: .95rem; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=number], input[type=search], textarea, select {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font: inherit; color: var(--fg);
  background: var(--bg); border: 2px solid var(--line); border-radius: 10px;
}
textarea { min-height: 4rem; }
input:focus, textarea:focus, select:focus { outline: 3px solid var(--accent); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-weight: 600; }
.check input { width: 28px; height: 28px; }
.errorlist { color: var(--error); margin: 4px 0; padding-left: 1rem; }
details { margin: 8px 0; }
summary {
  min-height: var(--tap); display: flex; align-items: center; gap: 10px; padding: 10px 16px; font-weight: 700;
  cursor: pointer; list-style: none; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸"; font-size: 1.1rem; }
details[open] > summary::before { content: "▾"; }
details[open] > summary { margin-bottom: 8px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list a, .list .item, .list button.link {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: var(--tap);
  padding: 8px 4px; color: var(--fg); text-decoration: none;
}
.list button.link {
  width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.list .name { font-weight: 600; overflow-wrap: anywhere; }
.badge {
  display: inline-block; font-size: .8rem; padding: 2px 8px; border-radius: 999px; background: var(--card);
  color: var(--muted); white-space: nowrap; border: 1px solid var(--line);
}
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.qty { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.path { font-size: .9rem; color: var(--muted); margin: .25rem 0; overflow-wrap: anywhere; }
.path a { color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; }
.fields { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; overflow-wrap: anywhere; }
.animal { font-weight: 700; letter-spacing: .01em; }

/* Messages */
.msg { border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; background: var(--card); }
.msg.warning { background: var(--warn-bg); color: var(--warn); }
.msg.error { background: var(--warn-bg); color: var(--error); }
.msg.success { color: var(--ok); }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

/* Category picker (E-112) */
.tag-picker { margin-bottom: 12px; }
.tag-picker .chips { margin: 6px 0; }
.new-tag { border: 1px solid var(--line); margin: 8px 0 0; }
.new-tag legend { padding: 0 4px; }
.relations p { margin: 4px 0; }

/* E-134: language switch in the footer of every page */
.foot { max-width: 40rem; margin: 0 auto; padding: 12px 16px 24px; border-top: 1px solid var(--line); }
.lang-switch { display: flex; gap: 10px; justify-content: center; }
.lang-switch button {
  min-width: var(--tap); min-height: 44px; padding: 6px 10px; border: 2px solid var(--line);
  border-radius: 10px; background: var(--card); cursor: pointer; line-height: 0;
}
.lang-switch button[aria-pressed="true"] { border-color: var(--accent); }
.lang-switch img { display: block; width: 30px; height: 18px; object-fit: cover; }
.foot-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.theme-switch { justify-self: start; }
.theme-switch .to-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-switch .to-light { display: flex; }
  :root:not([data-theme="light"]) .theme-switch .to-dark { display: none; }
}
:root[data-theme="dark"] .theme-switch .to-light { display: flex; }
:root[data-theme="dark"] .theme-switch .to-dark { display: none; }
.foot .version { margin: 8px 0 0; text-align: center; font-size: .8rem; color: var(--muted); }

/* B-008: search hits, the item on top and below it where it directly is */
.list li.hit-group { border-bottom: 0; }
.list li.hit-sub a { padding-left: 16px; }
.located { display: block; overflow-wrap: anywhere; }

/* B-020: several categories at once */
.match { border: 0; margin: 8px 0 0; padding: 0; }
.match legend { padding: 0; }

/* B-015, B-016: entry page */
.what { font-size: 1.1rem; margin: 0 0 6px; }
.where-in { margin: 4px 0; overflow-wrap: anywhere; }

/* B-026, L-164: kind next to the name, "in:" with the path to open in the same line */
.id { color: var(--muted); font-weight: 400; }
h1 .id { font-size: 1.1rem; }
details.where { margin: 4px 0; }
details.where > summary {
  min-height: 44px; padding: 4px 0; background: none; border: 0; border-radius: 0; font-weight: 400;
  justify-content: space-between; overflow-wrap: anywhere;
}
details.where > summary::before { content: none; }
.tree-toggle {
  display: flex; align-items: center; justify-content: center; flex: none; width: 44px; height: 44px;
  background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 10px;
}
details.where[open] .tree-toggle { color: var(--accent); border-color: var(--accent); }
details.where[open] > summary { margin-bottom: 0; }
/* B-041, B-043: square buttons in the line of the heading */
.title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-top: 1rem; }
.title-row h1 { margin: 0; align-self: center; }
.title-row form { margin: 0; flex: none; }
.icon-button, details.add-place > summary {
  display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; min-height: 0; padding: 0;
  background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.contents.has-add, .page-add { position: relative; }
.page-add > h1 { display: flex; align-items: center; min-height: 44px; margin-right: 52px; }
.page-add details.add-tag { margin: 0; }
.contents.has-add > h2 { display: flex; align-items: center; min-height: 44px; margin-top: 1rem; }
details.add-place { margin: 8px 0 0; }
details.add-place > summary { position: absolute; top: 0; right: 0; }
details.add-place > summary::before { content: "+"; font-size: 1.6rem; line-height: 1; }
details.add-place[open] > summary::before { content: "−"; }
details.add-place[open] > summary { margin-bottom: 0; }
.form-end { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-top: 8px; }
.form-end .check { margin: 0; }
/* L-221: all kinds side by side; without JavaScript, the radio button only marks the choice */
.type-choice { border: 0; padding: 0; margin: 8px 0; min-width: 0; }
.type-choice legend { padding: 0; margin-bottom: 4px; font-weight: 600; }
.type-options { display: flex; gap: 6px; }
.type-option { position: relative; margin: 0; }
.type-option input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.type-option span { display: flex; align-items: center; min-height: var(--tap); padding: 0 14px; border: 2px solid var(--line); border-radius: var(--radius); font-weight: 600; }
.type-option input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.type-option input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.type-option input:disabled { cursor: not-allowed; }
.type-option input:disabled + span { opacity: .5; }
.form-end .type-choice { margin: 0; }
.form-end .btn { width: auto; margin: 0 0 0 auto; }
/* B-044 */
.just-added { color: var(--ok); font-size: .9rem; white-space: nowrap; }
.last-seen { margin: 8px 0; }

/* B-032: the hint behind "Usage" opens on a tap */
details.info { display: inline; margin: 0; }
details.info > summary {
  display: inline-flex; min-height: 32px; min-width: 32px; padding: 0 6px; background: none; border: 0;
  font-weight: 400; color: var(--accent); justify-content: center;
}
details.info > summary::before { content: none; }
details.info[open] > summary { margin-bottom: 0; }
details.info > span { display: block; }

/* B-030: category picker, one field with small cards; the list opens below */
.tag-box { position: relative; }
.tag-field {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: var(--tap);
  padding: 4px 6px; background: var(--bg); border: 2px solid var(--line); border-radius: 10px;
}
.tag-field:focus-within { outline: 3px solid var(--accent); outline-offset: 1px; }
.tag-field input[type=search] {
  flex: 1 1 8rem; min-width: 6rem; min-height: 40px; padding: 4px 6px; border: 0; outline: none; background: none;
}
.tag-field input[type=search]::placeholder { font-size: .9rem; }
.tag-card {
  display: inline-flex; align-items: center; padding: 0 0 0 10px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); font-size: .95rem;
}
.tag-card button {
  min-width: 36px; min-height: 36px; border: 0; background: none; color: var(--fg); font: inherit;
  font-size: 1.15rem; cursor: pointer;
}
/* Open while the focus is in the field or the list; lies over the page, so nothing below jumps. */
/* tabindex on body: a tap on a free spot takes the focus away, which Safari does not do by itself. */
.tag-box, body { outline: none; }
.tag-list {
  display: none; position: absolute; z-index: 5; top: 100%; left: 0; right: 0; margin-top: 4px; max-height: 50vh;
  overflow-y: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 4px 12px rgb(0 0 0 / .25);
}
.tag-box:focus-within .tag-list { display: block; }
.tag-group { padding: 6px 12px 2px; }
.tag-option {
  display: block; width: 100%; min-height: 44px; padding: 8px 12px; text-align: left; border: 0;
  border-bottom: 1px solid var(--line); background: none; color: var(--fg); font: inherit; cursor: pointer;
}
/* The + next to "Kategorien": the fields open right below it */
.tag-picker.has-add { position: relative; }
.tag-picker > label { width: fit-content; }  /* a tap beside the word must not open the list */
.tag-picker.has-add > label { display: flex; align-items: center; min-height: 44px; margin: 12px 0 4px; }
details.add-tag { margin: 0 0 8px; }
.two-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.two-cols label { margin-top: 0; }
