:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-soft: #fafafa;
  --border: #e5e7eb;
  --text: #171717;
  --muted: #6b7280;
  --primary: #10a37f;
  --primary-hover: #0d8f6e;
  --user: #f7f7f8;
  --assistant: #ffffff;
  --error: #fff1f1;
  --mobile-text-scale: 1;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.board-layout {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
}

.board-header {
  position: sticky;
  top: 0;
  z-index: 24;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 46px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  overflow: visible;
}

.active-list-name {
  min-width: 0;
  flex: 1 1 auto;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-actions button {
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.header-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 10px;
  z-index: 40;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.16);
  padding: 8px;
}

#list-picker-panel {
  width: min(72vw, 240px);
  right: 86px;
}

#more-actions-panel {
  width: min(90vw, 300px);
}

.header-panel[hidden] {
  display: none !important;
}

.panel-title {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
}

.list-tabs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: min(52vh, 360px);
  overflow-y: auto;
}

.list-tab {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  background: #ffffff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}

.list-tab.active {
  border-color: var(--primary);
  background: #eaf9f4;
  color: #0d6e56;
  font-weight: 600;
}

.more-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.more-actions button,
.more-actions .link-btn {
  width: 100%;
  justify-content: flex-start;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 13px;
}

button {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 13px;
  cursor: pointer;
}

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

button.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

main {
  min-height: 0;
  overflow: hidden;
}

.session-board {
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px;
}

.session-column {
  flex: 0 0 380px;
  min-width: 320px;
  max-width: 460px;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

.column-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.column-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.column-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.column-head-btn {
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 12px;
}

.column-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.column-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.column-messages {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.column-composer {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  background: #ffffff;
}

.column-status {
  margin-bottom: 6px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #dbe3ed;
  border-radius: 8px;
  height: 24px;
  line-height: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.column-status[data-state="running"] {
  color: #0d6e56;
  background: #eaf9f4;
  border-color: #9bd7c8;
}

.column-status[data-state="idle"] {
  color: #475569;
  background: #f8fafc;
  border-color: #dbe3ed;
}

.column-status[data-state="error"] {
  color: #b42318;
  background: #fff1f1;
  border-color: #f1b7b7;
}

.column-input-wrap {
  position: relative;
}

.column-input {
  width: 100%;
  resize: none;
  min-height: 56px;
  max-height: 120px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 66px 8px 10px;
  color: var(--text);
  background: var(--panel);
  font: inherit;
}

.column-send-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 5px 9px;
  min-height: 28px;
}

.message {
  max-width: 95%;
  min-width: 0;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 11px;
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  overflow-x: hidden;
  overflow-y: visible;
}

.message .body {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: inherit;
}

.message.assistant .body.markdown-body {
  white-space: normal;
}

.message.assistant .body.markdown-body > * {
  margin: 0 0 0.68em;
}

.message.assistant .body.markdown-body > *:last-child {
  margin-bottom: 0;
}

.message.assistant .body.markdown-body h1,
.message.assistant .body.markdown-body h2,
.message.assistant .body.markdown-body h3,
.message.assistant .body.markdown-body h4,
.message.assistant .body.markdown-body h5,
.message.assistant .body.markdown-body h6 {
  line-height: 1.35;
  font-weight: 650;
}

.message.assistant .body.markdown-body h1 {
  font-size: 1.2em;
}

.message.assistant .body.markdown-body h2 {
  font-size: 1.12em;
}

.message.assistant .body.markdown-body h3 {
  font-size: 1.05em;
}

.message.assistant .body.markdown-body ul,
.message.assistant .body.markdown-body ol {
  margin: 0 0 0.68em 1.3em;
  padding: 0;
}

.message.assistant .body.markdown-body li + li {
  margin-top: 0.24em;
}

.message.assistant .body.markdown-body blockquote {
  margin: 0 0 0.68em;
  padding-left: 10px;
  color: #4b5563;
  border-left: 3px solid var(--border);
}

.message.assistant .body.markdown-body pre {
  margin: 0 0 0.74em;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
  overflow-x: auto;
  white-space: pre;
  font-size: 12px;
  line-height: 1.5;
}

.message.assistant .body.markdown-body pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  background: transparent;
  border: none;
  padding: 0;
}

.message.assistant .body.markdown-body .md-code-lang {
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.message.assistant .body.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
  padding: 1px 4px;
  border-radius: 5px;
  border: 1px solid #e5e7eb;
  background: #f3f4f6;
}

.message.assistant .body.markdown-body a {
  color: var(--primary);
}

.message.assistant .body.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.86em 0;
}

.message.user {
  align-self: flex-end;
  margin-left: auto;
  width: fit-content;
  max-width: 82%;
  background: var(--user);
}

.message.assistant,
.message.tool-group,
.message.tool {
  align-self: center;
  margin: 0 auto;
  width: 94%;
  max-width: 94%;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 3px 4px;
}

.message.system {
  background: var(--panel-soft);
}

.message.error {
  background: var(--error);
}

.message.tool-group {
  white-space: normal;
}

.message.tool[hidden] {
  display: none !important;
}

.message.tool.collapsed .tool-body {
  display: none;
}

.message.tool.expanded .tool-body {
  display: block;
}

.tool-group-summary {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 0;
  font: inherit;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.tool-group-summary:hover {
  color: var(--text);
}

.tool-summary {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 0;
  font: inherit;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.tool-summary:hover {
  color: var(--text);
}

.tool-body {
  margin-top: 6px;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}

.tool-body-content {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.tool-body-more {
  display: inline-block;
  margin-top: 6px;
  border: none;
  background: transparent;
  padding: 0;
  color: var(--primary);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
}

.tool-body-more:hover {
  color: var(--primary-hover);
}

.meta {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  flex-wrap: wrap;
}

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

.message-state {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 11px;
  line-height: 1.2;
  background: #f8fafc;
  color: var(--muted);
}

.message-state[data-state="pending"] {
  border-color: #f6d68d;
  background: #fff8e5;
  color: #9a6700;
}

.message-state[data-state="working"] {
  border-color: #9bd7c8;
  background: #eaf9f4;
  color: #0d6e56;
}

.message-state[data-state="done"] {
  border-color: #b9d8c7;
  background: #f0f8f3;
  color: #2f6b45;
}

.message-state[data-state="error"] {
  border-color: #f1b7b7;
  background: #fff1f1;
  color: #b42318;
}

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px;
}

@media (max-width: 900px), (hover: none) and (pointer: coarse) {
  .board-header {
    min-height: 42px;
    padding: 7px 8px;
    gap: 6px;
  }

  .active-list-name {
    font-size: 13px;
  }

  .header-actions {
    gap: 5px;
  }

  .header-actions button {
    padding: 5px 8px;
    font-size: 12px;
  }

  #list-picker-panel {
    right: 76px;
    width: min(74vw, 220px);
  }

  #more-actions-panel {
    right: 8px;
    width: min(90vw, 280px);
  }

  .session-column {
    flex-basis: 86vw;
    min-width: 86vw;
    max-width: 86vw;
  }

  .message {
    width: 100%;
    max-width: 100%;
    min-height: 44px;
    font-size: clamp(15px, max(calc(15px * var(--mobile-text-scale)), 3.8vw), 34px);
    line-height: 1.72;
    padding: 12px;
  }

  .message.user {
    width: fit-content;
    max-width: 96%;
  }

  .message.assistant,
  .message.tool-group,
  .message.tool {
    width: 94%;
    max-width: 94%;
    min-height: 0;
    padding: 3px 4px;
  }

  .meta {
    font-size: clamp(12px, max(calc(12px * var(--mobile-text-scale)), 2.8vw), 22px);
  }

  .tool-body {
    font-size: clamp(13px, max(calc(13px * var(--mobile-text-scale)), 3vw), 26px);
    line-height: 1.55;
  }
}
