:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #131820;
  --panel-2: #181f29;
  --line: #263140;
  --text: #eef3f8;
  --muted: #94a3b8;
  --soft: #c7d2df;
  --accent: #38bdf8;
  --accent-2: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 18px 60px rgba(0, 0, 0, .32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
textarea {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100vh;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #0f141b;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid #31566a;
  border-radius: 8px;
  color: #081016;
  background: var(--accent);
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.1;
}

.brand p,
.chat-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.side-actions {
  display: grid;
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel h2 {
  margin-bottom: 12px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.meta {
  display: grid;
  gap: 10px;
  margin: 0;
}

.meta div {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.meta dt {
  color: var(--muted);
  font-size: 12px;
}

.meta dd {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strategy-panel {
  flex: 0 0 auto;
}

.strategy-panel p {
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.strategy-history-wrap {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.strategy-history-wrap h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.strategy-history {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
}

.strategy-item {
  border-left: 2px solid #475569;
  padding-left: 9px;
}

.strategy-item strong {
  display: block;
  margin-bottom: 2px;
  color: var(--soft);
  font-size: 11px;
}

.strategy-item p {
  color: var(--muted);
  font-size: 12px;
}

.event-panel {
  flex: 1;
  min-height: 160px;
  overflow: hidden;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-height: 140px;
  overflow: auto;
  padding-right: 2px;
}

.event {
  border-left: 2px solid var(--line);
  padding: 2px 0 2px 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.event strong {
  display: block;
  margin-bottom: 2px;
  color: var(--soft);
  font-size: 12px;
}

.event.action {
  border-left-color: var(--accent);
}

.event.error {
  border-left-color: var(--danger);
}

.event.done {
  border-left-color: var(--accent-2);
}

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100vh;
  background: #0b0d10;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  min-height: 72px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 20, 27, .92);
}

.chat-header h2 {
  font-size: 18px;
}

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

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 18px 22px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 100%;
  color: var(--muted);
  text-align: center;
}

.empty h3 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 20px;
}

.msg {
  max-width: min(880px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

.msg.user {
  align-self: flex-end;
  width: fit-content;
  max-width: min(720px, 92%);
  background: #122131;
  border-color: #214056;
}

.msg.assistant,
.msg.system {
  align-self: flex-start;
  width: min(920px, 100%);
}

.msg.system {
  width: fit-content;
  max-width: min(760px, 100%);
  background: #151b22;
  border-color: #2f3b4a;
  box-shadow: none;
}

.msg.system .msg-body {
  color: var(--soft);
  font-size: 14px;
}

.msg.tool {
  align-self: flex-start;
  width: min(820px, 100%);
  background: #10151d;
}

.msg-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.msg-body {
  padding: 10px 12px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.48;
}

.msg-body p {
  margin: 0 0 8px;
}

.msg-body p:last-child {
  margin-bottom: 0;
}

.msg-body code,
.msg-body pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.code-block {
  position: relative;
  overflow: auto;
  margin: 8px 0;
  border: 1px solid #2c3848;
  border-radius: 8px;
  background: #080b0f;
  white-space: pre;
}

.code-block code {
  display: block;
  padding: 32px 12px 12px;
  color: #dbeafe;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
}

.code-block.command {
  border-color: #31566a;
}

.code-label {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 6px 10px;
  border-bottom: 1px solid #263140;
  color: var(--muted);
  background: #10151d;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 11px;
  text-transform: uppercase;
}

.inline-code {
  border: 1px solid #2c3848;
  border-radius: 5px;
  padding: 1px 5px;
  background: #0a1118;
  color: #bfdbfe;
  font-size: .92em;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 16px 22px 20px;
  border-top: 1px solid var(--line);
  background: rgba(15, 20, 27, .92);
}

.composer-actions {
  display: flex;
  gap: 8px;
  align-items: end;
}

textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  outline: none;
  color: var(--text);
  background: var(--panel-2);
  line-height: 1.4;
}

textarea:focus {
  border-color: var(--accent);
}

.button,
.icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  color: var(--text);
  cursor: pointer;
}

.button.primary {
  min-width: 92px;
  background: var(--accent);
  color: #061018;
  font-weight: 800;
}

.button.stop {
  min-width: 78px;
  border-color: #5b2630;
  background: #2a1318;
  color: #fecdd3;
  font-weight: 700;
}

.button.secondary,
.icon-button {
  background: var(--panel-2);
  border-color: var(--line);
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 99px;
  background: var(--muted);
}

.status-dot.ok {
  background: var(--accent-2);
}

.status-dot.busy {
  background: var(--warn);
}

.status-dot.err {
  background: var(--danger);
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    position: relative;
    height: auto;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .event-panel {
    display: none;
  }

  .chat {
    min-height: calc(100vh - 224px);
  }

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

  .composer-actions {
    justify-content: stretch;
  }

  .composer-actions .button {
    flex: 1;
  }

  .chat-header {
    align-items: flex-start;
  }
}
