:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f7f8fa);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1d2733);
  --muted: var(--tg-theme-hint-color, #687384);
  --border: rgba(105, 116, 134, 0.2);
  --accent: var(--tg-theme-button-color, #2a8cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d94141);
  font-family:
    Inter,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 860px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom));
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.08;
}

h2 {
  margin-bottom: 8px;
  font-size: 24px;
  line-height: 1.15;
}

h3 {
  margin-bottom: 0;
  font-size: 16px;
  line-height: 1.2;
}

.status-pill {
  min-width: 68px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-align: center;
  text-transform: uppercase;
}

.status-pill[data-status="ready"] {
  border-color: rgba(29, 153, 92, 0.28);
  color: #168353;
}

.status-pill[data-status="offline"] {
  border-color: rgba(217, 65, 65, 0.28);
  color: var(--danger);
}

.agent-strip {
  display: grid;
  grid-auto-columns: minmax(144px, 1fr);
  grid-auto-flow: column;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.agent-strip::-webkit-scrollbar {
  display: none;
}

.agent-chip,
.template-button,
.ghost-button,
.task-form button {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.agent-chip {
  min-height: 44px;
  padding: 10px 12px;
  font-weight: 700;
  white-space: nowrap;
}

.agent-chip-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  color: var(--accent);
}

.workspace {
  display: grid;
  gap: 14px;
}

.agent-panel,
.answer-panel,
.history-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.agent-description {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

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

.template-button {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 58px;
  padding: 10px 12px;
  text-align: left;
}

.template-button-active {
  border-color: var(--accent);
}

.template-title {
  font-weight: 750;
}

.template-description {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.task-form {
  display: grid;
  gap: 8px;
}

.task-form label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.task-form textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.45;
  padding: 12px;
}

.task-form textarea:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 20%, transparent);
}

.task-form button {
  min-height: 48px;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
}

.task-form button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.ghost-button {
  min-height: 34px;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.answer-panel pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  line-height: 1.45;
}

.answer-error pre {
  color: var(--danger);
}

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

.history-item {
  display: grid;
  gap: 6px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.history-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 750;
}

.history-heading time {
  flex: 0 0 auto;
  color: var(--muted);
  font-weight: 600;
}

.history-item p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.35;
}

.muted {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.4;
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 24px;
  }

  .agent-strip {
    grid-template-columns: repeat(3, 1fr);
    grid-auto-flow: initial;
    grid-auto-columns: initial;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.72fr);
    align-items: start;
  }

  .agent-panel,
  .task-form,
  .answer-panel {
    grid-column: 1;
  }

  .workspace > section:first-of-type,
  .history-panel {
    grid-column: 2;
  }
}
