/* Agents – Leitstelle für Tims Agents. Ruhig im Normalfall, laut nur bei Entscheidungen. */

@font-face {
  font-family: 'Bricolage';
  src: url('/fonts/bricolage-grotesque-latin-standard-normal.woff2') format('woff2-variations');
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Bricolage';
  src: url('/fonts/bricolage-grotesque-latin-ext-standard-normal.woff2') format('woff2-variations');
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light dark;
  --bg: #f2f3f8;
  --surface: #ffffff;
  --surface-2: #e8eaf2;
  --ink: #151726;
  --muted: #646a80;
  --line: rgba(21, 23, 38, 0.08);
  --signal: #4747eb;
  --signal-soft: rgba(71, 71, 235, 0.1);
  --on-signal: #ffffff;
  --decide: #d88f00;
  --decide-soft: #fff2d2;
  --decide-edge: #f5b335;
  --go: #0e9f6e;
  --stop: #d93f3f;
  --stop-soft: rgba(217, 63, 63, 0.08);
  --bubble-user: #4747eb;
  --on-bubble-user: #ffffff;
  --glass: rgba(242, 243, 248, 0.72);
  --shadow-lift: 0 1px 0 rgba(21, 23, 38, 0.04), 0 12px 32px -12px rgba(21, 23, 38, 0.18);

  --display: 'Bricolage', ui-rounded, system-ui, sans-serif;
  --text: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, 'Segoe UI', Roboto, sans-serif;
  --r-s: 10px;
  --r-m: 16px;
  --r-l: 26px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --gutter: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e16;
    --surface: #151826;
    --surface-2: #1e2234;
    --ink: #eceef7;
    --muted: #8e94ab;
    --line: rgba(236, 238, 247, 0.08);
    --signal: #8f8fff;
    --signal-soft: rgba(143, 143, 255, 0.14);
    --on-signal: #0c0e16;
    --decide: #ffb938;
    --decide-soft: rgba(255, 185, 56, 0.1);
    --decide-edge: #ffb938;
    --go: #34d399;
    --stop: #ff6b6b;
    --stop-soft: rgba(255, 107, 107, 0.1);
    --bubble-user: #5b5bf0;
    --on-bubble-user: #ffffff;
    --glass: rgba(12, 14, 22, 0.7);
    --shadow-lift: 0 0 0 1px rgba(236, 238, 247, 0.06), 0 18px 40px -16px rgba(0, 0, 0, 0.7);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Kopfzeile ---------- */
.bar {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--safe-top) + 10px) var(--gutter) 10px;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.bar.scrolled { border-bottom-color: var(--line); }
.bar h1 {
  margin: 0; flex: 1; min-width: 0;
  font: 650 34px/1.05 var(--display);
  font-variation-settings: 'opsz' 96, 'wdth' 92;
  letter-spacing: -0.02em;
}
.bar .crumb { flex: 1; min-width: 0; }
.bar .crumb h2 {
  margin: 0; font: 600 18px/1.2 var(--display); letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar .crumb small { color: var(--muted); font-size: 13px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
  color: var(--ink); background: var(--surface-2);
  transition: transform .15s;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 20px; height: 20px; }

main { flex: 1; padding: 6px var(--gutter) calc(110px + var(--safe-bottom)); }

/* ---------- Abschnittsüberschriften ---------- */
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 22px 2px 10px;
}
.section-head h3 { margin: 0; font: 600 15px/1.2 var(--text); color: var(--muted); }
.section-head .count { font: 600 13px var(--text); color: var(--muted); }

/* ---------- Entscheidungen (das laute Element) ---------- */
.decisions { display: grid; gap: 14px; }
.decision {
  position: relative; overflow: hidden;
  background: var(--surface);
  border-radius: var(--r-l);
  padding: 18px 18px 16px 22px;
  box-shadow: var(--shadow-lift);
}
.decision::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 6px;
  background: linear-gradient(180deg, var(--decide-edge), color-mix(in srgb, var(--decide-edge) 40%, transparent));
}
.decision.enter { animation: decide-in .5s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes decide-in { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.decision .who { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.decision .who svg { width: 14px; height: 14px; color: var(--decide); }
.decision h4 { margin: 6px 0 0; font: 600 19px/1.25 var(--display); letter-spacing: -0.01em; }
.decision .amount {
  margin: 10px 0 2px;
  font: 700 46px/1 var(--display);
  font-variation-settings: 'opsz' 96, 'wdth' 85;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.decision .amount span { font-size: 22px; font-weight: 600; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.decision .body { margin: 8px 0 0; color: var(--muted); font-size: 15px; }
.decision .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.decision .actions.many { grid-template-columns: 1fr; }
.decision.done { opacity: .62; }
.decision.done::before { background: var(--line); }
.decision .outcome { margin-top: 12px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.decision .outcome.ok { color: var(--go); }
.decision .outcome.no { color: var(--stop); }
.decision .outcome svg { width: 18px; height: 18px; }

.btn {
  height: 54px; border-radius: 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font-weight: 600; font-size: 16px;
  transition: transform .12s, background-color .2s, color .2s, opacity .2s;
  position: relative;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 22px; height: 22px; flex: none; }
.btn-go { background: var(--go); color: #fff; }
.btn-primary { background: var(--signal); color: var(--on-signal); }
.btn-stop { background: var(--stop-soft); color: var(--stop); }
.btn-ghost { background: var(--surface-2); color: var(--ink); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.busy { pointer-events: none; }
.btn.busy .label { opacity: 0; }
.btn.busy::after {
  content: ''; position: absolute; width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
.btn.confirmed { background: var(--go); color: #fff; }
.btn.confirmed .label { animation: pop .35s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.btn-wide { width: 100%; }

/* ---------- Thread-Liste ---------- */
.threads { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--r-m); overflow: hidden; }
.threads li + li .row { border-top: 1px solid var(--line); }
.threads li { position: relative; }
.row {
  display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: start;
  padding: 14px 16px; width: 100%; text-align: left;
  margin-left: 0;
}
.row:active { background: var(--surface-2); }
.row .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--line); }
.row .dot.working { background: var(--signal); animation: breathe 1.6s ease-in-out infinite; }
.row .dot.waiting { background: var(--decide); }
.row .dot.done { background: var(--go); }
.row .dot.failed { background: var(--stop); }
.row .dot.open { background: color-mix(in srgb, var(--muted) 45%, transparent); }
@keyframes breathe { 50% { opacity: .35; transform: scale(.8); } }
.row .main { min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .preview {
  color: var(--muted); font-size: 14.5px; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row .meta { text-align: right; font-size: 13px; color: var(--muted); display: grid; justify-items: end; gap: 6px; }
.row .badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--signal); color: var(--on-signal); font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
}
.row .kind { font-size: 12px; color: var(--muted); }

/* ---------- Leere Zustände ---------- */
.empty { text-align: center; padding: 48px 12px 24px; color: var(--muted); }
.empty h3 { margin: 0 0 6px; font: 600 22px/1.2 var(--display); color: var(--ink); }
.empty p { margin: 0 auto; max-width: 30ch; }
.suggestions { display: grid; gap: 8px; margin-top: 20px; }
.suggestion {
  text-align: left; padding: 12px 14px; border-radius: 14px;
  background: var(--surface); color: var(--ink); font-size: 15px;
  border: 1px solid var(--line);
}
.suggestion:active { background: var(--surface-2); }

/* ---------- Hinweis-Banner ---------- */
.notice {
  display: flex; gap: 12px; align-items: center;
  background: var(--signal-soft); border-radius: var(--r-m);
  padding: 12px 14px; margin-top: 12px; font-size: 14.5px;
}
.notice svg { width: 22px; height: 22px; color: var(--signal); flex: none; }
.notice .txt { flex: 1; }
.notice button { color: var(--signal); font-weight: 600; white-space: nowrap; }

/* ---------- Nachrichtenverlauf ---------- */
.timeline { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
.msg { max-width: 86%; font-size: 16px; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end; background: var(--bubble-user); color: var(--on-bubble-user);
  padding: 10px 14px; border-radius: 20px 20px 6px 20px; white-space: pre-wrap;
}
.msg.agent { align-self: flex-start; max-width: 100%; padding: 2px 2px; }
.msg.agent p { margin: 0 0 .6em; }
.msg.agent p:last-child { margin-bottom: 0; }
.msg.agent ul, .msg.agent ol { margin: .2em 0 .6em; padding-left: 1.3em; }
.msg.agent li { margin: .15em 0; }
.msg.agent h4 { margin: .8em 0 .3em; font: 600 17px var(--display); }
.msg.agent code { font: 14px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }
.msg.agent pre { background: var(--surface-2); padding: 10px 12px; border-radius: 12px; overflow-x: auto; }
.msg.agent pre code { background: none; padding: 0; }
.msg.agent a { color: var(--signal); }
.msg.system {
  align-self: center; font-size: 13px; color: var(--muted);
  background: var(--surface-2); padding: 5px 12px; border-radius: 999px; text-align: center;
}
.msg-time { font-size: 12px; color: var(--muted); margin: 6px 4px 0; }
.msg-time.right { align-self: flex-end; }
.day { align-self: center; font-size: 12.5px; color: var(--muted); margin: 10px 0 2px; }
.typing { align-self: flex-start; display: flex; gap: 5px; padding: 12px 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: none; opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------- Eingabe ---------- */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px var(--gutter) calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 55%, transparent);
}
.composer form {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border-radius: 26px; padding: 6px 6px 6px 18px;
  box-shadow: var(--shadow-lift);
}
.composer textarea {
  flex: 1; border: 0; outline: 0; background: none; resize: none;
  padding: 9px 0; max-height: 160px; line-height: 1.35; font-size: 16px;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--signal); color: var(--on-signal);
  display: grid; place-items: center; transition: transform .15s, opacity .2s;
}
.send:disabled { opacity: .3; }
.send:active { transform: scale(.9); }
.send svg { width: 20px; height: 20px; }

/* ---------- Anmeldung ---------- */
.gate {
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(var(--safe-top) + 64px) 28px calc(var(--safe-bottom) + 28px);
}
.gate .mark { width: 64px; height: 64px; border-radius: 18px; }
.gate h1 {
  margin: 28px 0 10px;
  font: 700 54px/0.95 var(--display);
  font-variation-settings: 'opsz' 96, 'wdth' 80;
  letter-spacing: -0.035em;
}
.gate p { margin: 0; color: var(--muted); font-size: 17px; max-width: 30ch; }
.gate .stack { display: grid; gap: 12px; }
.gate .link { color: var(--signal); font-weight: 600; padding: 12px; }
.field {
  width: 100%; height: 56px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 16px; font-size: 20px; letter-spacing: .12em;
  text-transform: uppercase; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.error { color: var(--stop); font-size: 14.5px; min-height: 1.4em; }
.code-box {
  margin-top: 24px; padding: 20px; border-radius: var(--r-m); background: var(--surface);
  font: 600 24px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; text-align: center;
  user-select: all;
}

/* ---------- Einstellungen ---------- */
.group { background: var(--surface); border-radius: var(--r-m); overflow: hidden; }
.group + .section-head { margin-top: 26px; }
.item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; width: 100%; text-align: left; }
.group .item + .item { border-top: 1px solid var(--line); }
.item .grow { flex: 1; min-width: 0; }
.item small { display: block; color: var(--muted); font-size: 13.5px; }
.item.danger { color: var(--stop); }
.item svg { width: 20px; height: 20px; color: var(--muted); flex: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 12px); z-index: 50;
  transform: translate(-50%, -140%); transition: transform .35s cubic-bezier(.2, .9, .3, 1.2);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 14.5px; font-weight: 600; max-width: calc(100% - 32px);
}
.toast.show { transform: translate(-50%, 0); }

/* ---------- Seitenwechsel ---------- */
.view { animation: view-in .28s cubic-bezier(.2, .8, .2, 1) backwards; }
.view.back { animation-name: view-back; }
@keyframes view-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes view-back { from { transform: translateX(-24px); opacity: 0; } }

@media (min-width: 720px) {
  #app { max-width: 680px; margin: 0 auto; }
  .composer { max-width: 680px; margin: 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
