/* Mobile-first. One column that grows into a centred column on wider screens. */

:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --ink: #1c1b19;
  --muted: #6b6862;
  --line: #e2e0da;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --user: #e8efe9;
  --warn-bg: #fdf0e3;
  --warn-ink: #8a4b1a;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --panel: #202225;
    --ink: #eceae5;
    --muted: #9a978f;
    --line: #32353a;
    --accent: #6fae9b;
    --accent-ink: #10221c;
    --user: #2a3a34;
    --warn-bg: #3a2a17;
    --warn-ink: #f0c08a;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;      /* dvh so mobile browser chrome doesn't crop the composer */
  min-height: 100%;    /* belt and braces: never under-fill the viewport */
  max-width: 780px;
  margin: 0 auto;
  background: var(--panel);
  /* Nothing inside may widen the column — a single non-shrinking element used to
     push the whole layout past the viewport and cut off Send and the last tool. */
  overflow: hidden;
}

@media (min-width: 800px) {
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* --- top bar ---
   Two rows: the title and controls, then the provider line on its own. The
   provider string is long and unbreakable, so it gets a row where truncating it
   can't affect anything else. */
.bar {
  display: flex; flex-direction: column; gap: .15rem;
  padding: .7rem .9rem; border-bottom: 1px solid var(--line);
  padding-top: max(.7rem, env(safe-area-inset-top));
}
.bar-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.title { white-space: nowrap; }
.bar-meta { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; }
.provider {
  color: var(--muted); font-size: .7rem;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip {
  font: .7rem ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: .1rem .5rem;
  max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- banner (errors / notices) --- */
.banner {
  background: var(--warn-bg); color: var(--warn-ink);
  padding: .6rem .9rem; font-size: .85rem; border-bottom: 1px solid var(--line);
}

/* --- conversation --- */
.log {
  flex: 1; overflow-y: auto; padding: 1rem .9rem;
  display: flex; flex-direction: column; gap: .7rem;
  overscroll-behavior: contain;
}

.turn { display: flex; flex-direction: column; max-width: 92%; }
.turn.bot { align-self: flex-start; }
.turn.you { align-self: flex-end; align-items: flex-end; }

.bubble {
  padding: .6rem .8rem; border-radius: var(--radius);
  /* Bot text is pre-formatted — numbered lists and bullets must survive. */
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.turn.bot .bubble { background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.turn.you .bubble { background: var(--user); border-bottom-right-radius: 4px; }

.step {
  font: .68rem ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted); margin-top: .25rem;
}

.typing { color: var(--muted); font-style: italic; }

/* --- quick replies --- */
.quick {
  display: flex; flex-wrap: wrap; gap: .4rem;
  padding: 0 .9rem .6rem;
}
.quick:empty { display: none; }
.quick button {
  background: var(--panel); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 999px;
  padding: .45rem .8rem; font-size: .88rem; cursor: pointer;
  /* Comfortable tap target on a phone. */
  min-height: 40px;
}
.quick button:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); }
.quick button:disabled { opacity: .5; cursor: default; }

/* --- composer --- */
.composer {
  display: flex; gap: .5rem; padding: .7rem .9rem;
  border-top: 1px solid var(--line); background: var(--panel);
}
.composer input {
  flex: 1; min-width: 0; padding: .7rem .8rem; font-size: 1rem;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.composer input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.composer button {
  padding: .7rem 1.1rem; font-size: 1rem; font-weight: 600; cursor: pointer;
  color: var(--accent-ink); background: var(--accent);
  border: 0; border-radius: var(--radius);
}
.composer button:disabled { opacity: .5; cursor: default; }

/* --- tools --- */
.tools {
  display: flex; flex-wrap: wrap; gap: .4rem;
  padding: 0 .9rem .8rem;
  padding-bottom: max(.8rem, env(safe-area-inset-bottom));
}
.tool, .ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 8px;
  padding: .35rem .6rem; font-size: .78rem; cursor: pointer; min-height: 34px;
}
.tool:hover:not(:disabled), .ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--muted); }
.tool.danger { color: #a5462f; border-color: #d9b4a9; }
.tool:disabled, .ghost:disabled { opacity: .5; cursor: default; }

/* --- debug --- */
.debug { border-top: 1px solid var(--line); padding: .7rem .9rem; background: var(--bg); }
.debug-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .4rem; }
.debug pre {
  margin: 0; max-height: 34vh; overflow: auto;
  font: .72rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere;
}
