/* Prussian Bot — chat application styling.
   Builds on styles.css (palette + .weave/.prussian/.lang-pill etc). */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background:
    radial-gradient(ellipse at 22% 12%, rgba(255,250,235,0.55), transparent 60%),
    radial-gradient(ellipse at 85% 95%, rgba(122,74,16,0.08), transparent 70%),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(90,69,32,0.022) 3px 4px),
    var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}
#root { height: 100vh; }

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* ---- top bar ---- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--ink-2);
  background: linear-gradient(var(--paper-2), var(--paper));
  z-index: 5;
}
.brand { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand .title {
  font-style: italic; font-weight: 700; font-size: 21px; color: var(--ink);
  display: flex; align-items: baseline; gap: 9px;
}
.brand .title .prs { color: var(--amber-deep); }
.brand .sub {
  font-variant: small-caps; letter-spacing: 0.14em; font-size: 11px; color: var(--ink-2);
  margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .spacer { flex: 1; }

.iconbtn {
  font-family: var(--serif);
  font-variant: small-caps; letter-spacing: 0.08em; font-size: 12.5px;
  border: 1px solid var(--ink-2); background: var(--paper); color: var(--ink);
  padding: 6px 13px; cursor: pointer; border-radius: 1px;
  box-shadow: 1px 1px 0 rgba(42,29,10,0.12);
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.iconbtn:hover { background: var(--paper-2); }
.iconbtn:active { transform: translate(1px,1px); box-shadow: none; }
.iconbtn .glyph { font-size: 14px; line-height: 1; }

/* connection chip */
.conn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  border: 1px solid var(--ink-faint); padding: 4px 10px; border-radius: 1px;
  background: rgba(255,255,255,0.4); cursor: pointer;
}
.conn:hover { border-color: var(--ink-2); }
.conn .led { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); flex: 0 0 auto; }
.conn.ok .led { background: var(--inner); }
.conn.warn .led { background: var(--amber); }
.conn.err .led { background: #a5341f; }
.conn.busy .led { background: var(--amber); animation: pulse 1.1s ease-in-out infinite; }

/* ---- chat scroll region ---- */
.scroll {
  flex: 1 1 auto; overflow-y: auto; overflow-x: hidden;
  scroll-behavior: smooth;
}
.thread {
  max-width: 760px; margin: 0 auto; padding: 26px 22px 30px;
  display: flex; flex-direction: column; gap: 22px;
}

/* ---- empty / welcome state ---- */
.welcome {
  max-width: 620px; margin: 7vh auto 0; padding: 0 22px; text-align: center;
}
.welcome h1 { font-style: italic; font-weight: 700; font-size: 30px; margin: 0 0 6px; }
.welcome h1 .prs { color: var(--amber-deep); }
.welcome p { font-size: 15px; line-height: 1.55; color: var(--ink-2); margin: 0 auto 14px; max-width: 480px; }
.welcome .weave { max-width: 220px; margin: 16px auto; }
.suggests { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; }
.suggest {
  font-family: var(--serif); font-size: 13.5px; color: var(--ink);
  border: 1px dashed var(--ink-2); background: rgba(255,255,255,0.4);
  padding: 8px 14px; cursor: pointer; border-radius: 1px; text-align: left;
}
.suggest:hover { background: var(--paper-2); border-style: solid; }
.suggest .q { font-style: italic; }
.suggest .prs { color: var(--amber-deep); font-weight: 700; }

/* ---- messages ---- */
.msg { display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg.bot { align-items: flex-stretch; }
.who {
  font-variant: small-caps; letter-spacing: 0.12em; font-size: 10.5px;
  color: var(--ink-faint); margin-bottom: 5px;
}
.msg.user .bubble-user { max-width: 78%; font-size: 15px; }
.bot-stack { display: flex; flex-direction: column; gap: 10px; width: 100%; }

/* reasoning — always-visible muted teal notebook block */
.reason {
  border-left: 2px solid var(--inner);
  background:
    repeating-linear-gradient(0deg, transparent 0 19px, rgba(47,93,90,0.08) 19px 19.5px),
    var(--inner-bg);
  padding: 9px 13px 10px; position: relative;
}
.reason-head {
  display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none;
  font-variant: small-caps; letter-spacing: 0.12em; font-size: 10.5px; color: var(--inner);
}
.reason-head .tw { font-size: 9px; transition: transform 0.15s ease; color: var(--inner); }
.reason-head.closed .tw { transform: rotate(-90deg); }
.reason-head .ms { margin-left: auto; font-family: var(--mono); font-size: 10px; opacity: 0.7; text-transform: none; letter-spacing: 0; }
.reason-body {
  font-style: italic; font-size: 12.5px; line-height: 1.55; color: var(--inner);
  margin-top: 7px; white-space: pre-wrap; word-break: break-word;
}

/* tool calls — compact, collapsible */
.tools { display: flex; flex-direction: column; gap: 7px; }
.toolcard { border: 1px solid var(--inner); background: rgba(255,255,255,0.5); border-radius: 1px; }
.toolcard.error { border-color: #a5341f; background: rgba(165,52,31,0.05); }
.tool-head {
  display: flex; align-items: center; gap: 9px; padding: 7px 11px;
  cursor: pointer; font-family: var(--mono); font-size: 12px; user-select: none;
}
.tool-head .tw { font-size: 9px; color: var(--inner); transition: transform 0.15s ease; }
.tool-head.open .tw { transform: rotate(90deg); }
.tool-head .nm { color: var(--ink); font-weight: 600; }
.tool-head .nm::after { content: '()'; color: var(--ink-faint); }
.tool-head .preview { color: var(--amber-deep); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.tool-head .stat { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.tool-head .ms { font-size: 10.5px; color: var(--ink-faint); }
.led-s { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.led-s.run { background: var(--amber); animation: pulse 1.1s ease-in-out infinite; }
.led-s.ok { background: var(--inner); }
.led-s.err { background: #a5341f; }
.tool-body { border-top: 1px solid var(--inner); padding: 9px 11px; display: flex; flex-direction: column; gap: 8px; }
.toolcard.error .tool-body { border-top-color: #a5341f; }
.kv { font-family: var(--mono); font-size: 11px; line-height: 1.5; }
.kv .k { font-variant: small-caps; letter-spacing: 0.1em; color: var(--inner); display: block; margin-bottom: 2px; }
.kv pre {
  margin: 0; white-space: pre-wrap; word-break: break-word; color: var(--ink);
  background: rgba(42,29,10,0.04); border: 1px solid var(--ink-faint); padding: 7px 9px;
  max-height: 260px; overflow: auto;
}
.kv.err pre { color: #8a2418; border-color: #c98; background: rgba(165,52,31,0.06); }

/* answer body */
.answer { font-size: 15px; line-height: 1.55; }
.answer p { margin: 0 0 9px; }
.answer p:last-child { margin-bottom: 0; }
.answer ul, .answer ol { margin: 4px 0 9px; padding-left: 22px; }
.answer li { margin: 2px 0; }
.answer code { font-family: var(--mono); font-size: 0.86em; background: rgba(42,29,10,0.06); padding: 1px 4px; border-radius: 1px; }
.answer strong { font-weight: 700; }
.answer em { font-style: italic; }
.answer .prussian { white-space: nowrap; }
.answer h1, .answer h2, .answer h3, .answer h4 {
  font-weight: 700; margin: 18px 0 8px; line-height: 1.3;
}
.answer h1 { font-size: 22px; }
.answer h2 { font-size: 19px; }
.answer h3 { font-size: 17px; }
.answer h4 { font-size: 15px; }
.answer pre {
  background: rgba(42,29,10,0.06); border: 1px solid var(--ink-faint);
  padding: 10px 13px; overflow-x: auto; font-family: var(--mono);
  font-size: 0.86em; line-height: 1.5; margin: 0 0 9px; border-radius: 1px;
}
.answer pre code {
  background: none; padding: 0; border: none; font-size: inherit;
}
.answer blockquote {
  border-left: 3px solid var(--amber-soft); margin: 0 0 9px;
  padding: 4px 0 4px 14px; color: var(--ink-2); font-style: italic;
}
.answer a { color: var(--amber-deep); text-decoration: underline; }
.answer hr { border: none; border-top: 1px solid var(--ink-faint); margin: 14px 0; }
.answer table { border-collapse: collapse; margin: 0 0 9px; font-size: 0.93em; }
.answer th, .answer td { border: 1px solid var(--ink-faint); padding: 5px 9px; text-align: left; }
.answer th { background: rgba(42,29,10,0.06); font-weight: 700; }

/* error card */
.errcard {
  border: 1px solid #a5341f; background: rgba(165,52,31,0.06); padding: 10px 13px; border-radius: 1px;
}
.errcard .hd { display: flex; align-items: center; gap: 8px; }
.errcard .et {
  font-variant: small-caps; letter-spacing: 0.1em; font-size: 10px; color: #fff; background: #a5341f;
  padding: 1px 8px; border-radius: 1px;
}
.errcard .msg-txt { color: #8a2418; font-style: italic; font-size: 13.5px; }
.errcard .actions { display: flex; gap: 9px; margin-top: 9px; }

/* ---- composer ---- */
.composer-wrap { flex: 0 0 auto; border-top: 1px solid var(--ink-2); background: linear-gradient(var(--paper), var(--paper-2)); }
.composer { max-width: 760px; margin: 0 auto; padding: 13px 22px 16px; }
.composer .row { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; font-family: var(--serif); font-size: 15px; line-height: 1.45;
  color: var(--ink); background: #f7eed4; border: 1px solid var(--ink-2); border-radius: 1px;
  padding: 11px 13px; max-height: 180px; min-height: 46px;
  box-shadow: inset 1px 1px 0 rgba(42,29,10,0.06);
}
.composer textarea:focus { outline: none; border-color: var(--amber-deep); }
.composer textarea::placeholder { color: var(--ink-faint); font-style: italic; }
.sendbtn {
  flex: 0 0 auto; font-family: var(--serif); font-variant: small-caps; letter-spacing: 0.1em;
  font-size: 14px; border: 1px solid var(--amber-deep); background: var(--amber-deep); color: var(--paper);
  padding: 0 18px; height: 46px; cursor: pointer; border-radius: 1px;
  box-shadow: 1px 1px 0 rgba(42,29,10,0.2); display: inline-flex; align-items: center; gap: 8px;
}
.sendbtn:hover { background: var(--amber); border-color: var(--amber); }
.sendbtn:active { transform: translate(1px,1px); box-shadow: none; }
.sendbtn.stop { background: #a5341f; border-color: #a5341f; }
.sendbtn:disabled { opacity: 0.45; cursor: not-allowed; }
.composer .hint { font-size: 11px; color: var(--ink-faint); margin-top: 7px; display: flex; gap: 14px; flex-wrap: wrap; }
.composer .hint b { font-weight: 700; color: var(--ink-2); }

/* ---- settings drawer ---- */
.backdrop { position: fixed; inset: 0; background: rgba(42,29,10,0.32); z-index: 20; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 440px; max-width: 92vw; z-index: 21;
  background:
    radial-gradient(ellipse at 80% 0%, rgba(255,250,235,0.5), transparent 60%),
    var(--paper);
  border-left: 1px solid var(--ink-2); box-shadow: -4px 0 18px rgba(42,29,10,0.18);
  display: flex; flex-direction: column; animation: slidein 0.2s ease;
}
@keyframes slidein { from { transform: translateX(30px); opacity: 0.4; } }
.drawer-head {
  flex: 0 0 auto; display: flex; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--ink-2);
}
.drawer-head h2 { margin: 0; font-style: italic; font-weight: 700; font-size: 19px; }
.drawer-head .x { margin-left: auto; cursor: pointer; font-size: 20px; color: var(--ink-2); border: none; background: none; line-height: 1; }
.drawer-head .x:hover { color: var(--ink); }
.drawer-body { flex: 1; overflow-y: auto; padding: 6px 20px 24px; }

.sec { padding: 15px 0; border-bottom: 1px dotted var(--ink-faint); }
.sec:last-child { border-bottom: none; }
.sec > h3 {
  margin: 0 0 11px; font-variant: small-caps; letter-spacing: 0.13em; font-size: 12px; color: var(--amber-deep);
  display: flex; align-items: center; gap: 9px;
}
.sec > h3 .ln { flex: 1; border-top: 1px solid var(--ink-faint); opacity: 0.6; }

.fld { margin-bottom: 13px; }
.fld:last-child { margin-bottom: 0; }
.fld label { display: block; font-variant: small-caps; letter-spacing: 0.08em; font-size: 11px; color: var(--ink-2); margin-bottom: 4px; }
.fld input[type=text], .fld input[type=password], .fld input[type=number], .fld select, .fld textarea {
  width: 100%; font-family: var(--mono); font-size: 12.5px; color: var(--ink);
  background: #f7eed4; border: 1px solid var(--ink-2); border-radius: 1px; padding: 8px 10px;
}
.fld textarea { font-family: var(--serif); font-size: 13.5px; line-height: 1.45; resize: vertical; min-height: 80px; }
.fld input:focus, .fld select:focus, .fld textarea:focus { outline: none; border-color: var(--amber-deep); }
.fld .desc { font-size: 11px; color: var(--ink-faint); margin-top: 4px; line-height: 1.4; }
.row2 { display: flex; gap: 12px; }
.row2 > .fld { flex: 1; }

/* slider */
.slider-fld .top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; }
.slider-fld .val { font-family: var(--mono); font-size: 12px; color: var(--amber-deep); }
.slider-fld input[type=range] { width: 100%; accent-color: var(--amber-deep); }

/* segmented */
.seg { display: flex; border: 1px solid var(--ink-2); border-radius: 1px; overflow: hidden; }
.seg button {
  flex: 1; font-family: var(--serif); font-variant: small-caps; letter-spacing: 0.06em; font-size: 12px;
  border: none; background: var(--paper); color: var(--ink-2); padding: 7px 6px; cursor: pointer;
  border-right: 1px solid var(--ink-2);
}
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--amber-deep); color: var(--paper); }

/* mcp tool list */
.mcp-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin: 4px 0 10px; }
.mcp-status .led { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-faint); flex: 0 0 auto; }
.mcp-status.ok .led { background: var(--inner); }
.mcp-status.err .led { background: #a5341f; }
.mcp-status.busy .led { background: var(--amber); animation: pulse 1.1s ease-in-out infinite; }
.mcp-status .txt { color: var(--ink-2); }
.mcp-status.err .txt { color: #8a2418; }
.toollist { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.toollist .t {
  border: 1px solid var(--inner); background: rgba(47,93,90,0.06); padding: 6px 10px; border-radius: 1px;
}
.toollist .t .n { font-family: var(--mono); font-size: 12px; color: var(--ink); font-weight: 600; }
.toollist .t .d { font-size: 11.5px; color: var(--ink-2); margin-top: 2px; line-height: 1.4; }
.btn-line { display: flex; gap: 9px; margin-top: 4px; }

/* toggle */
.toggle-fld { display: flex; align-items: center; gap: 11px; }
.toggle-fld label { margin: 0; flex: 1; }
.tog { width: 42px; height: 23px; border: 1px solid var(--ink-2); border-radius: 12px; background: var(--paper); position: relative; cursor: pointer; flex: 0 0 auto; }
.tog .knob { position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: var(--ink-2); transition: all 0.15s ease; }
.tog.on { background: var(--amber-soft); border-color: var(--amber-deep); }
.tog.on .knob { left: 21px; background: var(--amber-deep); }
.tog.dis { opacity: 0.5; cursor: default; }
.fld input:disabled, .fld textarea:disabled, .fld select:disabled { opacity: 0.5; cursor: default; }
.seg button:disabled { opacity: 0.5; cursor: default; }
.iconbtn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }

/* grammar resource list */
.gramlist { display: flex; flex-direction: column; gap: 5px; margin-top: 2px; }
.gram-item {
  display: flex; align-items: flex-start; gap: 8px; cursor: pointer; padding: 5px 8px;
  border: 1px solid var(--ink-faint); border-radius: 1px; background: rgba(255,255,255,0.3);
}
.gram-item:hover { background: var(--paper-2); }
.gram-item.on { border-color: var(--amber-deep); background: rgba(212,148,58,0.08); }
.gram-item .check { font-size: 15px; line-height: 1.3; flex: 0 0 auto; }
.gram-item .gi-body { display: flex; flex-direction: column; min-width: 0; }
.gram-item .gi-name { font-family: var(--mono); font-size: 12px; color: var(--ink); font-weight: 600; }
.gram-item .gi-desc { font-size: 11px; color: var(--ink-2); line-height: 1.35; margin-top: 1px; }

/* ---- language toggle ---- */
.lang-toggle {
  display: flex;
  border: 1px solid var(--ink-2);
  border-radius: 1px;
  overflow: hidden;
  flex: 0 0 auto;
}
.lang-toggle button {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  border: none;
  background: var(--paper);
  color: var(--ink-2);
  padding: 4px 8px;
  cursor: pointer;
  line-height: 1;
  min-width: 32px;
}
.lang-toggle button.on {
  background: var(--amber-deep);
  color: var(--paper);
}
.lang-toggle button:not(.on):hover {
  background: var(--paper-2);
}

/* ---- responsive ---- */
@media (max-width: 640px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .brand .title { font-size: 18px; }
  .conn .label-txt { display: none; }
  .iconbtn .label-txt { display: none; }
  .iconbtn { padding: 7px 10px; }
  .thread { padding: 18px 14px 24px; gap: 18px; }
  .composer { padding: 11px 14px 14px; }
  .msg.user .bubble-user { max-width: 90%; }
  .drawer { width: 100%; max-width: 100%; }
  .welcome { margin-top: 5vh; }
}
