/* Material Assistant — calm, instrument-like: deep ink surfaces, safety-amber
   accent used sparingly, mono for references and metadata, one centered column,
   large soft radii. */

:root {
  --paper: #f2f3f1;
  --surface: #ffffff;
  --surface-2: #f8f9f8;
  --ink: #1b2430;
  --muted: #5e6b7a;
  --line: #dce0e4;
  --amber: #d99a06;
  --amber-soft: rgba(217, 154, 6, .12);
  --accent-fg: #2b2000;
  --user-bubble: #e4ebf3;
  --error: #b3261e;
  --shadow-1: 0 1px 2px rgba(27, 36, 48, .06), 0 4px 16px rgba(27, 36, 48, .06);
  --shadow-2: 0 2px 4px rgba(27, 36, 48, .08), 0 12px 32px rgba(27, 36, 48, .12);
  --radius: 18px;
  --radius-sm: 12px;
  --col: 46rem;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #11151b; --surface: #1a2028; --surface-2: #161c23;
    --ink: #e8ecf1; --muted: #97a2b0; --line: #2a323d;
    --amber: #f2b63c; --amber-soft: rgba(242, 182, 60, .14); --accent-fg: #201700;
    --user-bubble: #23324a; --error: #ff8a80;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
    --shadow-2: 0 2px 4px rgba(0, 0, 0, .35), 0 12px 32px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); }
[hidden] { display: none !important; }

/* Soft ambient backdrop */
.backdrop {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60rem 40rem at 85% -10%, var(--amber-soft), transparent 60%),
    radial-gradient(50rem 36rem at -10% 110%, rgba(94, 107, 122, .10), transparent 60%);
}

.mono { font-family: var(--mono); font-size: .85em; letter-spacing: .01em; }

button {
  font: inherit; cursor: pointer; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: .5rem 1.05rem;
  transition: border-color .15s, box-shadow .15s, transform .15s, background .15s;
}
button:hover { border-color: var(--amber); box-shadow: var(--shadow-1); }
button:active { transform: translateY(1px); }
button[type=submit] { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 600; }
button[type=submit]:hover { box-shadow: var(--shadow-2); border-color: var(--ink); }
button:disabled { opacity: .5; cursor: default; box-shadow: none; transform: none; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: .4rem .7rem; }
button.ghost:hover { color: var(--ink); border-color: var(--line); box-shadow: none; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

input, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .65rem .85rem; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
a { color: inherit; text-decoration-color: var(--amber); text-underline-offset: 2px; }
a:hover { color: var(--amber); }

/* ---------- gate views (login, language) ---------- */

.gate { min-height: 100%; display: grid; place-items: center; padding: 1.25rem; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px); padding: 2.25rem 2rem;
  max-width: 28.5rem; width: 100%; display: grid; gap: .8rem;
  box-shadow: var(--shadow-2);
}
.eyebrow {
  margin: 0; font-family: var(--mono); font-size: .72rem; text-transform: uppercase;
  letter-spacing: .14em; color: var(--amber);
}
.eyebrow::before { content: "▮ "; }
.card h1 { margin: 0; font-size: 1.55rem; line-height: 1.25; letter-spacing: -.01em; }
.card .lede { margin: 0 0 .4rem; color: var(--muted); }
.card label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.error { color: var(--error); margin: 0; font-size: .9rem; }
.wait { margin: 0; color: var(--muted); display: flex; align-items: center; gap: .5rem; }
.spinner {
  width: 1rem; height: 1rem; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--amber);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* view transitions */
.view { animation: view-in .24s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- chat ---------- */

#chat { height: 100%; display: grid; grid-template-rows: auto 1fr; grid-template-columns: 1fr auto; }
#chat header {
  grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between;
  padding: .55rem clamp(.75rem, 3vw, 1.5rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 650; letter-spacing: -.01em; }
.mark {
  width: .8rem; height: .8rem; border-radius: 3px; background: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}
.actions { display: flex; gap: .25rem; }

main { display: grid; grid-template-rows: 1fr auto; min-height: 0; }
#messages {
  overflow-y: auto; padding: 1.5rem clamp(.75rem, 3vw, 1.5rem) 1rem;
  display: flex; flex-direction: column; gap: 1rem; scroll-behavior: smooth;
}
#messages > * { width: 100%; max-width: var(--col); margin-inline: auto; }

#composer {
  display: flex; gap: .6rem; align-items: flex-end;
  padding: .75rem clamp(.75rem, 3vw, 1.5rem) 1.1rem;
  width: 100%; max-width: calc(var(--col) + 2 * clamp(.75rem, 3vw, 1.5rem));
  margin-inline: auto;
}
#composer textarea {
  resize: none; max-height: 9rem; border-radius: var(--radius);
  padding: .8rem 1.05rem; box-shadow: var(--shadow-1); background: var(--surface);
}
#send {
  border-radius: 50%; width: 2.85rem; height: 2.85rem; padding: 0; flex: none;
  display: grid; place-items: center; font-size: 1.05rem;
}

/* messages */
.msg { display: flex; animation: msg-in .22s ease-out; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 100%; padding: .8rem 1.1rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow-1); overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--user-bubble); border-color: transparent;
  border-bottom-right-radius: 6px; white-space: pre-wrap; max-width: 85%;
}
.msg.assistant .bubble { border-bottom-left-radius: 6px; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.markdown table { border-collapse: collapse; margin: .5rem 0; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: .3rem .55rem; text-align: left; }
.markdown code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); border: 1px solid var(--line); padding: .1rem .35rem; border-radius: 6px; }
.markdown pre code { display: block; padding: .6rem .8rem; overflow-x: auto; }
.status { color: var(--muted); font-size: .88rem; font-style: italic; margin-top: .45rem; display: flex; align-items: center; gap: .45rem; }
.status:empty { display: none; }
.status::before {
  content: ""; width: .8rem; height: .8rem; border-radius: 50%; flex: none;
  border: 2px solid var(--line); border-top-color: var(--amber);
  animation: spin .8s linear infinite;
}
.cursor::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }
.msg.error .bubble { border-color: var(--error); }

/* intro block */
.intro { display: grid; gap: .9rem; }
.intro .bubble { background: var(--surface); }
.suggestions { display: grid; gap: .55rem; }
.suggestion {
  text-align: left; border-radius: var(--radius-sm); padding: .8rem 1rem .8rem 1.1rem;
  background: var(--surface); border: 1px solid var(--line);
  position: relative; overflow: hidden; font-weight: 500;
}
.suggestion::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--amber); transform: scaleY(.35); transform-origin: center;
  transition: transform .18s ease; border-radius: 0 2px 2px 0;
}
.suggestion:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--amber); }
.suggestion:hover::before { transform: scaleY(1); }
.suggestions.dismissed .suggestion { opacity: 0; transform: translateY(6px); pointer-events: none; transition: opacity .25s, transform .25s; }

/* sources */
.sources { margin-top: .85rem; padding-top: .7rem; border-top: 1px dashed var(--line); font-size: .92rem; }
.sources h4 {
  margin: 0 0 .35rem; font-family: var(--mono); font-size: .72rem;
  text-transform: uppercase; letter-spacing: .12em; color: var(--muted);
}
.sources ul { margin: 0 0 .5rem; padding-left: 1.2rem; }
.sources li { margin: .18rem 0; }
.sources button.link {
  background: none; border: none; padding: 0; border-radius: 0;
  color: inherit; text-decoration: underline; text-decoration-color: var(--amber);
  text-underline-offset: 2px; text-align: left;
}
.sources button.link:hover { color: var(--amber); box-shadow: none; }
.sources .pages { color: var(--muted); font-family: var(--mono); font-size: .85em; }

/* side panel */
#panel {
  width: min(430px, 100vw); border-left: 1px solid var(--line);
  background: var(--surface); overflow-y: auto; padding: 1.1rem 1.35rem 2rem;
  box-shadow: var(--shadow-2); animation: panel-in .25s ease-out;
  border-radius: var(--radius) 0 0 var(--radius);
}
@keyframes panel-in { from { opacity: 0; transform: translateX(24px); } }
.panel-head { display: flex; align-items: start; justify-content: space-between; gap: .5rem; position: sticky; top: 0; background: inherit; padding-block: .2rem .4rem; }
.panel-head h2 { font-size: 1.05rem; margin: 0; letter-spacing: -.01em; }
#panel-close { font-size: 1.25rem; line-height: 1; }
.meta { color: var(--muted); }

@media (max-width: 900px) {
  #chat { grid-template-columns: 1fr; }
  #panel { position: fixed; inset: 0; width: auto; border-left: 0; border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
