:root {
  color-scheme: light;
  --bg: #f3f7f4;
  --panel: #ffffff;
  --ink: #12211b;
  --muted: #5d7068;
  --line: #d7e2dc;
  --blue: #256b8f;
  --teal: #0f766e;
  --green: #147d4c;
  --deep-green: #0a4f34;
  --lime: #8fcf5f;
  --red: #b42318;
  --amber: #8a5a00;
  --soft-blue: #eef7fb;
  --soft-green: #edf8f1;
  --glow-green: #dff5df;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); }
button, textarea, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1540px, 100%);
  height: 100dvh;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 16px;
  overflow: hidden;
}

.debug-layout .app-shell { grid-template-columns: 290px minmax(0, 1fr) 420px; }

.control-panel, .chat-panel, .debug-panel {
  min-height: 0;
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.control-panel { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.identity-block { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 5px; color: var(--teal); font-size: 12px; font-weight: 800; letter-spacing: 0; text-transform: uppercase; }
h1, h2, h3, p { margin: 0; letter-spacing: 0; }
h1 { font-size: 24px; line-height: 1.06; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.profile-name { margin-top: 6px; color: var(--green); font-size: 15px; font-weight: 800; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.segment, .sample-button, .secondary-button, .send-button, .followup-choice, .debug-tab {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
}
.segment { min-height: 34px; font-weight: 800; }
.segment.active { border-color: #9dc6df; background: var(--soft-green); color: var(--green); }
.debug-password { display: grid; gap: 5px; margin-top: 9px; color: var(--muted); font-size: 12px; font-weight: 700; }
.debug-password input { min-height: 36px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; }

.sample-list { display: grid; gap: 7px; }
.sample-button { width: 100%; padding: 8px 9px; text-align: left; color: var(--green); background: #f4fbf6; line-height: 1.25; font-weight: 750; }
.sample-button:hover, .secondary-button:hover, .followup-choice:hover { border-color: var(--green); background: #e7f6ec; }
.session-section { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.session-id { padding: 8px 9px; border: 1px solid var(--line); border-radius: 6px; background: #f8fafb; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.session-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 9px; }
.secondary-button { min-height: 34px; font-weight: 800; }

.chat-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.chat-header { display: flex; align-items: start; justify-content: space-between; gap: 16px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.chat-header p { margin-top: 6px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.status-pill { min-width: 92px; padding: 7px 10px; border: 1px solid #9fd5b4; border-radius: 999px; background: var(--glow-green); color: var(--green); font-size: 12px; font-weight: 800; text-align: center; }
.status-pill.loading { border-color: #dfc98c; background: #fff9ea; color: var(--amber); }
.status-pill.error { border-color: #e3aaa5; background: #fff0ef; color: var(--red); }

.chat-history { min-height: 0; padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.message { max-width: 850px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #ffffff; }
.message.user { align-self: flex-end; max-width: 700px; background: var(--deep-green); color: #ffffff; border-color: var(--deep-green); }
.message.assistant { align-self: flex-start; }
.message-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 8px; font-size: 13px; }
.message-head span { color: var(--muted); font-size: 12px; }
.message.user .message-head span { color: #cfe5f4; }
.message-body { font-size: 15px; line-height: 1.48; }
.answer-bullet { position: relative; padding-left: 18px; margin: 5px 0; }
.answer-bullet::before { content: ""; position: absolute; left: 0; top: 0.68em; width: 6px; height: 6px; border-radius: 50%; background: var(--teal); }
.keyword-emphasis { color: var(--deep-green); font-weight: 850; }
.followup-choice { margin: 8px 7px 0 0; padding: 7px 10px; color: var(--green); font-weight: 800; }
.retry-button { margin-top: 8px; padding: 6px 10px; border: 1px solid #e3aaa5; border-radius: 6px; background: #fff0ef; color: var(--red); font-weight: 800; }
.typing-cursor { display: inline-block; width: 7px; height: 1em; margin-left: 2px; background: var(--teal); vertical-align: -2px; animation: blink 0.8s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer { display: grid; grid-template-columns: minmax(0, 1fr) 92px; gap: 10px; padding: 14px; border-top: 1px solid var(--line); background: #fbfcfd; }
textarea { width: 100%; min-height: 46px; max-height: 120px; resize: vertical; padding: 11px 12px; border: 1px solid var(--line); border-radius: 7px; outline: none; }
textarea:focus, input:focus { border-color: #79c695; box-shadow: 0 0 0 3px rgba(20, 125, 76, 0.14); }
.send-button { min-height: 46px; background: var(--blue); color: #ffffff; border-color: var(--green); font-weight: 850; }
.send-button:disabled { opacity: 0.55; cursor: not-allowed; }

.debug-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.debug-header { padding: 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.debug-tabs { padding: 10px; border-bottom: 1px solid var(--line); display: flex; gap: 7px; overflow-x: auto; }
.debug-tab { flex: 0 0 auto; padding: 7px 9px; color: var(--muted); font-size: 12px; font-weight: 850; }
.debug-tab.active { background: var(--soft-green); border-color: #a7cfb7; color: var(--green); }
.debug-content { min-height: 0; padding: 12px; overflow-y: auto; display: grid; gap: 10px; align-content: start; }
.debug-card { border: 1px solid var(--line); border-radius: 8px; padding: 11px; background: #ffffff; }
.debug-card h3 { margin-bottom: 9px; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.metric { min-width: 0; padding: 8px; border: 1px solid #e6ecef; border-radius: 6px; background: #f8fafb; }
.metric span { display: block; color: var(--muted); font-size: 11px; font-weight: 800; }
.metric strong { display: block; margin-top: 3px; font-size: 13px; overflow-wrap: anywhere; }
.chunk { border-top: 1px solid #edf1f3; padding: 8px 0; }
.chunk summary { cursor: pointer; color: var(--green); font-weight: 850; font-size: 13px; }
.chunk p { margin-top: 8px; color: var(--ink); font-size: 13px; line-height: 1.38; }
pre { max-height: 180px; overflow: auto; padding: 9px; border-radius: 6px; background: #0f1720; color: #d6e6f2; font-size: 12px; white-space: pre-wrap; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.4; }
.is-hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

@media (max-width: 980px) {
  html, body { overflow: auto; }
  .app-shell, .debug-layout .app-shell { height: auto; min-height: 100dvh; grid-template-columns: 1fr; overflow: visible; }
  .control-panel, .chat-panel, .debug-panel { max-height: none; }
  .chat-panel { min-height: 70dvh; }
  .metric-grid { grid-template-columns: 1fr; }
}
