:root {
  --ink: #203431;
  --muted: #586e66;
  --green: #1d6654;
  --border: #dce3dd;
  --paper: #f6f7f2;
  --sidebar: #172e29;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}
[hidden] { display: none !important; }
button, textarea { font: inherit; }
button {
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
  padding: 8px 13px;
  color: var(--ink);
}
button:hover { background: #eaf0e9; }
button:disabled { opacity: .5; cursor: wait; }
button:focus-visible { outline: 2px solid #9cbbae; outline-offset: 2px; }
h1, h2, p { margin: 0; }

#workbench {
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}
.sidebar {
  display: flex;
  flex-direction: column;
  padding: 26px 18px 18px;
  overflow: auto;
  background: var(--sidebar);
  color: #edf2e8;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
}
.brand-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #365044;
  color: #ecf0e3;
  font: 29px Georgia, serif;
}
.brand small {
  display: block;
  color: #9aafa1;
  font-size: 8px;
  letter-spacing: .14em;
}
.new-chat {
  margin: 30px 0 26px;
  background: #31473d;
  color: #edf2e8;
  border-color: #485e4f;
  text-align: left;
}
.new-chat:hover { background: #425b4c; }
.section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .15em;
  color: var(--muted);
}
.section-label {
  margin-bottom: 8px;
  color: #95aa9d;
  text-transform: uppercase;
}
.chat-link {
  display: block;
  width: 100%;
  margin-bottom: 4px;
  padding: 11px 10px;
  border: 0;
  background: transparent;
  color: #b9c8bd;
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-link[aria-current="true"], .chat-link:hover { background: #2c4439; color: white; }

main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
header {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 12px;
  min-height: 56px;
  padding: 11px 32px;
  border-bottom: 1px solid var(--border);
}
.header-title { min-width: 0; }
header h2 {
  font: 22px/1.25 Georgia, serif;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#toggle-sessions { display: none; }

#conversation { flex: 1; overflow: auto; padding: 30px 35px; }
#welcome { max-width: 620px; margin: 5vh auto 0; }
#welcome h1 { font: 40px/1.2 Georgia, serif; letter-spacing: -.03em; }
.welcome-mark { display: block; margin-bottom: 25px; color: #bdcdbb; font: 72px Georgia, serif; }
.message { max-width: 850px; margin: 0 auto 30px; overflow-wrap: anywhere; }
.message.user { background: #e8eee5; border-radius: 10px; padding: 16px 20px; }
.message .role {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .13em;
}
.message-text { white-space: pre-wrap; }
#activity {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 850px;
  margin: 16px auto;
  color: var(--green);
  font-size: 12px;
}
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

.composer-area { padding: 15px 28px 18px; }
.composer-area form {
  background: white;
  border: 1px solid #bdcdbf;
  border-radius: 12px;
  box-shadow: 0 4px 18px #1c3b2210;
}
.composer-area form:focus-within { border-color: var(--green); }
.composer-area textarea {
  display: block;
  width: 100%;
  min-height: 78px;
  max-height: 25vh;
  resize: vertical;
  padding: 15px 17px;
  border: 0;
  outline: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink);
}
.composer-actions { display: flex; justify-content: flex-end; padding: 5px 10px 10px; }
button.primary { background: var(--green); color: white; border-color: var(--green); }
button.primary:hover { background: #164d41; }
#chat-error { color: #a84336; margin-bottom: 8px; }

@media (max-width: 1100px) {
  #workbench { grid-template-columns: 190px minmax(0, 1fr); }
  .sidebar { padding: 22px 12px; }
}
@media (max-width: 650px) {
  #workbench { grid-template-columns: minmax(0, 1fr); }
  #workbench.sessions-open { grid-template-rows: minmax(0, 42vh) minmax(0, 1fr); }
  #workbench:not(.sessions-open) .sidebar { display: none; }
  #toggle-sessions { display: block; }
  header { padding: 10px 16px; }
  header h2 { font-size: 18px; }
  #conversation { padding: 25px 18px; }
  .composer-area { padding: 10px; }
  #welcome { margin-top: 15px; }
  #welcome h1 { font-size: 32px; }
  .welcome-mark { font-size: 50px; margin-bottom: 15px; }
}

.chat-row { display: flex; align-items: flex-start; gap: 4px; margin-bottom: 4px; }
.chat-row .chat-link { flex: 1; min-width: 0; margin-bottom: 0; }
.delete-chat {
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
  display: grid;
  place-items: start end;
  padding: 4px 8px;
  border: 0;
  background: transparent;
  color: #b9c8bd;
  font-size: 19px;
  line-height: 1;
}
.delete-chat:hover, .delete-chat:focus-visible { background: #425b4c; color: white; }

.markdown { white-space: normal; }
.markdown > * { margin: 0 0 .8em; }
.markdown > :last-child { margin-bottom: 0; }
.markdown :is(h1, h2, h3, h4, h5, h6) {
  line-height: 1.3;
  font-weight: 650;
}
.markdown h1 { font-size: 1.65em; }
.markdown h2 { font-size: 1.4em; }
.markdown ul, .markdown ol { padding-inline-start: 1.75em; }
.markdown li + li { margin-top: .25em; }
.markdown blockquote {
  margin-inline: 0;
  padding-inline-start: 1em;
  border-inline-start: 3px solid #9daf9c;
  color: var(--muted);
}
.markdown a { color: var(--green); }
.markdown code {
  font: .9em/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
  background: #e9eee7;
  border-radius: 4px;
  padding: .15em .3em;
}
.markdown pre {
  overflow: auto;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #e9eee7;
  white-space: pre;
  overflow-wrap: normal;
}
.markdown pre code { padding: 0; background: none; }
.markdown table { border-collapse: collapse; }
.markdown th, .markdown td { padding: 6px; border: 1px solid var(--border); }
