:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --ink: #1a1d21;
  --muted: #6b7280;
  --hint: #9aa1aa;
  --border: #e3e6ea;
  --border-strong: #cfd4da;
  --accent-bg: #e1f5ee;
  --accent: #0f6e56;
  --accent-ink: #04342c;
  --ok-bg: #e1f5ee;
  --ok: #0f6e56;
  --warn-bg: #faeeda;
  --warn: #854f0b;
  --danger-bg: #fdebea;
  --danger: #b42318;
  --radius: 12px;
  --radius-sm: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  white-space: nowrap;
}

textarea {
  resize: vertical;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.brand-row,
.header-actions,
.button-row,
.actions,
.badges,
.tab-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.advanced-options {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  padding: 9px 11px;
}

.advanced-options summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.advanced-options[open] summary {
  margin-bottom: 10px;
}

.header-actions {
  flex-wrap: nowrap;
}

.brand {
  font-size: 16px;
  font-weight: 700;
}

.identity {
  color: var(--muted);
  font-size: 12.5px;
}

.pill,
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 3px 10px;
  font-size: 12px;
  line-height: 1.35;
  background: var(--surface);
  color: var(--muted);
}

.pill.ok,
.badge.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.pill.warn,
.badge.warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.pill.danger,
.badge.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.pill.neutral,
.badge.neutral {
  border-color: var(--border);
}

.btn {
  min-height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 7px 13px;
  font-size: 13px;
}

.btn:hover {
  background: var(--surface-soft);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn.secondary {
  color: var(--accent);
}

.btn[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.icon-btn {
  min-width: 34px;
}

.signin-panel {
  display: grid;
  gap: 12px;
  margin: 0 0 14px;
  padding: 14px;
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn);
}

.signin-panel h1,
.signin-panel p {
  margin: 0;
}

.signin-panel h1 {
  font-size: 16px;
}

.signin-panel p {
  max-width: 760px;
  font-size: 13px;
  line-height: 1.45;
}

.signin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.signin-actions {
  display: flex;
  gap: 8px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 110, 86, 0.1);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
}

.card .label {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
}

.card .value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.card .value small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.card .value.ok {
  color: var(--ok);
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12.5px;
}

.stage-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.stage-node {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  padding: 2px 8px;
  color: var(--muted);
}

.stage-node.done,
.stage-node.current {
  color: var(--ink);
  font-weight: 650;
}

.stage-node.current {
  color: var(--accent);
}

.partial-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 430px;
  max-height: calc(100vh - 210px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sysmsg {
  text-align: center;
}

.sysmsg span {
  display: inline-flex;
  max-width: 100%;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  padding: 3px 12px;
  font-size: 12px;
  line-height: 1.45;
}

.msg-user {
  align-self: flex-end;
  max-width: min(75%, 620px);
  border-radius: var(--radius);
  background: var(--accent-bg);
  color: var(--accent-ink);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
}

.msg-bot {
  align-self: flex-start;
  max-width: min(86%, 700px);
}

.bubble {
  border-radius: var(--radius);
  background: var(--bg);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.55;
}

.bubble .big {
  display: block;
  margin-bottom: 3px;
  font-size: 19px;
  font-weight: 700;
}

.bubble .basis {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.bubble .intent {
  display: inline-flex;
  margin-top: 8px;
}

.chips,
.suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chips {
  margin-top: 6px;
}

.cite {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  padding: 2px 10px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
}

.cite:hover,
.cite.active {
  border-color: var(--accent);
  color: var(--accent);
}

.excerpt {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
}

.suggest .btn {
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
}

.review {
  align-self: flex-start;
  display: grid;
  gap: 8px;
  max-width: min(86%, 700px);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn);
  padding: 12px 14px;
  font-size: 14px;
}

.review textarea {
  min-height: 72px;
  border-color: rgba(133, 79, 11, 0.35);
}

.inputrow {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-top: 12px;
}

.inputrow input {
  flex: 1;
  font-size: 14px;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 29, 33, 0.22);
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(720px, 100%);
  overflow: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 18px;
  box-shadow: -10px 0 28px rgba(26, 29, 33, 0.12);
}

.system-panel {
  width: min(780px, 100%);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.drawer-head h2,
.drawer-head p,
.drawer-section h3,
.drawer-section p {
  margin: 0;
}

.drawer-head h2 {
  font-size: 18px;
}

.drawer-head p,
.drawer-section p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.drawer-section {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--border);
  padding: 16px 0;
}

.drawer-section:first-of-type {
  border-top: 0;
}

.form-stack {
  display: grid;
  gap: 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.check-row input {
  width: auto;
}

.summary,
.stack-list .item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.stack-list {
  display: grid;
  gap: 8px;
}

.item strong {
  display: block;
  color: var(--ink);
  margin-bottom: 4px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.kv {
  display: grid;
  gap: 8px;
  margin: 0;
}

.kv div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  max-width: 60%;
  text-align: right;
  overflow-wrap: anywhere;
}

.code-block {
  max-height: 340px;
  margin: 0;
  overflow: auto;
  border-radius: var(--radius-sm);
  background: #18212a;
  color: #e8eef4;
  padding: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.tab-row button.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px 10px 24px;
  }

  .app-header,
  .statusbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .signin-grid {
    grid-template-columns: 1fr;
  }

  .chat {
    max-height: none;
  }

  .msg-user,
  .msg-bot,
  .review {
    max-width: 100%;
  }
}
