* { box-sizing: border-box; margin: 0; }
:root {
  --bg: #14120f; --panel: #1e1b17; --card: #262219; --line: #3a342c;
  --text: #f0e9dd; --muted: #a89d8c; --accent: #d9755a;
  --ok: #6fbf73; --bad: #e05d5d; --error-text: #e87c7c;
  --tabbar-h: 0px;
}
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, sans-serif; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; margin: -1px; border: 0; padding: 0;
}
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .9em; margin-top: .35rem; }
.error { color: var(--error-text); margin-top: .75rem; }
.error:empty, .success:empty { margin: 0; padding: 0; }
.success { color: var(--ok); margin-top: .75rem; }
.tag { font-size: .7em; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 4px; }

:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.skip-link { position: absolute; top: -48px; left: 0; background: var(--panel); color: var(--text); padding: 8px 16px; z-index: 30; border-radius: 0 0 8px 0; }
.skip-link:focus { top: 0; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); padding: 2rem; border-radius: 14px; width: min(92vw, 380px); }
.login-card h1 { margin-bottom: .25rem; }
.login-card form { display: grid; gap: .75rem; margin-top: 1.25rem; }

input, textarea, button { font: inherit; border-radius: 8px; padding: .65rem .9rem; }
input, textarea { background: var(--card); color: var(--text); border: 1px solid var(--muted); width: 100%; }
input::placeholder { color: var(--muted); }
textarea.mono, textarea#brain-editor { font-family: ui-monospace, Consolas, monospace; font-size: .9em; }
button { background: var(--accent); color: #14120f; font-weight: 600; border: none; cursor: pointer; }
button.secundair { background: var(--card); color: var(--text); border: 1px solid var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button[aria-disabled="true"], button.is-busy {
  background: var(--line); color: var(--text); border: 1px solid var(--muted);
  cursor: progress; opacity: 1;
}
.knoppenrij { display: flex; gap: .5rem; margin-top: .75rem; flex-wrap: wrap; }
form label { display: block; margin: .75rem 0 .3rem; font-weight: 600; }

/* layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.nav { background: var(--panel); padding: 1rem .75rem; display: flex; flex-direction: column; gap: .35rem; }
.brand { font-weight: 700; margin-bottom: 1rem; padding: .25rem .5rem; }
.nav-item { background: none; border: none; color: var(--text); text-align: left; padding: .55rem .75rem; border-radius: 8px; font-weight: 400; }
.nav-item[aria-current] { background: var(--card); font-weight: 600; }
.nav-item:not(:disabled):hover { background: var(--card); }
.logout { margin-top: auto; color: var(--muted); background: none; }
.content { padding: 1.5rem; max-width: 1100px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin-top: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.card.wide { grid-column: 1 / -1; }
.card h3 { margin-bottom: .5rem; }
.card .body { white-space: pre-wrap; overflow-x: auto; }
.dot { display: inline-block; width: .6em; height: .6em; border-radius: 50%; margin-right: .5em; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }
pre.log { background: var(--bg); padding: .5rem; border-radius: 8px; font-size: .8em; max-height: 260px; overflow: auto; }

/* sub-navigatie binnen Agents */
.section-intro { margin-top: .5rem; max-width: 65ch; }
.subnav { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1rem 0; border-bottom: 1px solid var(--line); padding-bottom: .6rem; }
.subnav-item { background: var(--card); border: 1px solid var(--line); color: var(--text); padding: .45rem .8rem; border-radius: 999px; font-weight: 500; font-size: .9em; }
.subnav-item[aria-current] { background: var(--accent); color: #14120f; border-color: var(--accent); font-weight: 700; }
.subnav-item:not([aria-current]):hover { border-color: var(--muted); }
.subview h3 { margin-bottom: .3rem; }
.subview { animation: fade .2s ease; }
@keyframes fade { from { opacity: .4; } to { opacity: 1; } }

/* formulierregels */
.checkrij { display: flex; align-items: center; gap: .5rem; font-weight: 400; margin-top: 1rem; }
.checkrij input { width: auto; accent-color: var(--accent); }
#nieuwform, #template-cards .card { max-width: 720px; }
input[type="search"] { max-width: 420px; }

/* bibliotheek */
#bib-resultaten { max-height: 60vh; overflow: auto; margin-top: .75rem; }
#bib-resultaten h4 { position: sticky; top: 0; background: var(--bg); padding: .4rem 0; margin-top: .5rem; color: var(--muted); }
.lib-item { padding: .5rem .2rem; border-bottom: 1px solid var(--line); }
.lib-item dt { font-weight: 600; }
.lib-item dd { margin: .1rem 0 0; color: var(--muted); font-size: .9em; }
#bib-telling { margin-top: .5rem; font-size: .9em; }

/* uitleg */
.uitleg { max-width: 68ch; }
.uitleg h4 { margin: 1.1rem 0 .35rem; }
.uitleg ul, .uitleg ol { padding-left: 1.4rem; }
.uitleg li { margin: .3rem 0; }
.uitleg code { background: var(--bg); padding: .1em .35em; border-radius: 4px; font-size: .9em; }

/* kaart-polish: hover én focus-within (S8) */
.card { transition: box-shadow .15s ease, border-color .15s ease, transform .15s ease; }
.card.is-interactive:hover, .card.is-interactive:focus-within {
  box-shadow: 0 4px 16px rgba(0,0,0,.45); border-color: var(--muted); transform: translateY(-2px);
}

/* statgetallen */
.statgetal { font-size: 1.6em; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.statlabel { color: var(--muted); font-size: .85em; }

/* key-value lijsten (agents/projecten) */
dl.kv { display: grid; gap: .25rem; margin: .5rem 0; }
dl.kv div { display: flex; gap: .5rem; }
dl.kv dt { color: var(--muted); min-width: 8.5em; }
dl.kv dd { margin: 0; }

/* schakelaar */
.switch {
  min-width: 64px; min-height: 28px; border-radius: 999px; padding: 2px 10px 2px 26px;
  position: relative; font-weight: 600; font-size: .85em; color: var(--bg);
}
.switch::before {
  content: ""; position: absolute; left: 4px; top: 50%; translate: 0 -50%;
  width: 18px; height: 18px; border-radius: 50%; background: var(--bg);
  transition: left .15s ease;
}
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="false"] { background: var(--muted); padding: 2px 26px 2px 10px; }
.switch[aria-checked="false"]::before { left: calc(100% - 22px); }

/* actief-badge */
.badge-active { color: var(--ok); border: 1px solid var(--ok); border-radius: 6px; padding: 0 .4em; font-size: .75em; margin-left: .5em; vertical-align: middle; }

/* geschiedenis-tabel */
.history { width: 100%; table-layout: fixed; border-collapse: collapse; margin-top: .5rem; }
.history th, .history td { text-align: left; padding: .4em .6em; border-bottom: 1px solid var(--line); }
.history th { color: var(--muted); font-weight: 600; }
.history .col-tijd { width: 7.5em; }
.history .col-duur { width: 5.5em; }
.history .col-kosten { width: 6em; }
.history td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history td.cost, .history td.duur { font-variant-numeric: tabular-nums; }

/* usage-grafiek */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 90px; margin-top: .5rem; }
.spark .bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.spark-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: .75em; }

/* brain */
.brain-layout { display: grid; grid-template-columns: 280px 1fr; gap: 1.25rem; margin-top: 1rem; }
.brain-tree ul { list-style: none; padding-left: .9rem; }
.brain-tree > ul { padding-left: 0; }
.brain-tree .tree-folder { display: block; color: var(--muted); font-weight: 600; margin-top: .6rem; }
.brain-tree button.tree-file {
  background: none; border: none; color: var(--text); font-weight: 400;
  padding: .25rem .5rem; border-radius: 6px; text-align: left; width: 100%;
}
.brain-tree button.tree-file:hover { background: var(--card); }
.brain-tree button.tree-file[aria-current] { background: var(--card); font-weight: 600; }
.brain-content { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; min-height: 300px; }
#brain-back { display: none; margin-bottom: .75rem; }
#brain-file-body { margin-top: .75rem; max-height: 65vh; overflow: auto; }
.md-content h4, .md-content h5, .md-content h6 { margin: .9em 0 .35em; }
.md-content p, .md-content ul, .md-content ol, .md-content blockquote { margin: .5em 0; }
.md-content ul, .md-content ol { padding-left: 1.4em; }
.md-content li.taak { list-style: none; margin-left: -1.4em; }
.md-content li.taak input { width: auto; margin-right: .5em; accent-color: var(--accent); }
.md-content li.taak input:disabled { opacity: 1; }
.md-content a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md-content a:hover { text-decoration-thickness: 2px; }
.md-content code { background: var(--bg); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.md-content pre { background: var(--bg); padding: .6rem; border-radius: 8px; overflow-x: auto; }
.md-content hr { border: none; border-top: 1px solid var(--line); margin: 1em 0; }
.md-content .wikilink { color: var(--accent); }
.md-content .frontmatter { color: var(--muted); font-size: .85em; background: var(--bg); padding: .5rem; border-radius: 8px; }

/* beweging beperken */
#agent-cron-veld[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
  .card.is-interactive:hover, .card.is-interactive:focus-within { transform: none !important; }
}

/* mobiel: 2x4 grid-tabbalk onderin, uitloggen bereikbaar als laatste tab */
@media (max-width: 900px) {
  :root { --tabbar-h: calc(2 * 48px + .8rem + 1px); }
  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  html { scroll-padding-bottom: calc(var(--tabbar-h) + 8px + env(safe-area-inset-bottom)); }
  .layout { grid-template-columns: 1fr; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: .25rem;
    padding: .4rem calc(.4rem + env(safe-area-inset-right)) calc(.4rem + env(safe-area-inset-bottom)) calc(.4rem + env(safe-area-inset-left));
    border-top: 1px solid var(--line);
  }
  .brand { display: none; }
  .nav-item { white-space: nowrap; font-size: .8em; min-height: 44px; text-align: center; padding: .35rem .3rem; }
  .logout { margin-top: 0; }
  .content { padding: 1rem; }
  .brain-layout { grid-template-columns: 1fr; }
  .brain-layout.toon-bestand .brain-tree { display: none; }
  .brain-layout:not(.toon-bestand) .brain-content { display: none; }
  #brain-back { display: inline-block; }
}
