:root {
  color-scheme: dark light;
  --bg: #0f1115;
  --panel: #161a22;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #9aa4b2;
  --accent: #5b8def;
  --accent-contrast: #fff;
  --ok: #3fbf6f;
  --denied: #e0555a;
  --error: #e0a94a;
  --badge: #7a5bd8;
  --code-bg: #0b0d12;
  --code-text: #c8e0ff;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --panel: #fff;
    --border: #d7dce3;
    --text: #1b2430;
    --muted: #5f6b7a;
    --accent: #3267c8;
    --accent-contrast: #fff;
    --ok: #167a3f;
    --denied: #b4232a;
    --error: #8a5a00;
    --badge: #6546b8;
    --code-bg: #eef1f5;
    --code-text: #174f8a;
  }
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

header {
  padding: 1.25rem 1.5rem;
  padding-top: max(1.25rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

main#chat {
  flex: 1;
  padding: 1.5rem;
  max-width: 720px;
  min-width: 0;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
}

.bubble {
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  max-width: 90%;
  min-width: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.bubble.bot {
  background: var(--panel);
  border: 1px solid var(--border);
}

.bubble.user {
  background: var(--accent);
  color: var(--accent-contrast);
  margin-left: auto;
}

.bubble .title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.bubble.step-ok { border-left: 3px solid var(--ok); }
.bubble.step-denied { border-left: 3px solid var(--denied); }
.bubble.step-error { border-left: 3px solid var(--error); }
.bubble.step-info { border-left: 3px solid var(--accent); }

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--badge);
  color: #fff;
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  margin-left: 0.5rem;
  vertical-align: middle;
}

details {
  margin-top: 0.5rem;
  min-width: 0;
  font-size: 0.85rem;
}

details summary {
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}

details pre,
pre.cli {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-width: 100%;
  padding: 0.6rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}

.cli-label {
  margin-top: 0.65rem;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

details.cli-details {
  margin-top: 0.65rem;
}

details.cli-details summary {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
}

details.cli-details pre.cli {
  margin-top: 0.4rem;
}

pre.cli {
  margin: 0 0 0.5rem;
  color: var(--code-text);
  font-size: 0.8rem;
}

.bubble code {
  font-size: 0.85em;
  color: var(--code-text);
}

.spinner {
  color: var(--muted);
  font-style: italic;
}

#options {
  padding: 1rem 1.5rem max(1.5rem, env(safe-area-inset-bottom));
  max-width: 720px;
  min-width: 0;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

#options button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  min-height: 44px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.25;
  cursor: pointer;
  touch-action: manipulation;
  overflow-wrap: anywhere;
}

#options button:hover {
  border-color: var(--accent);
}

#options button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#options .section-label {
  width: 100%;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0.5rem 0 0.1rem;
}

@media (max-width: 520px) {
  header {
    padding-right: 1rem;
    padding-bottom: 0.9rem;
    padding-left: 1rem;
  }

  header h1 {
    font-size: 1.1rem;
  }

  header p {
    font-size: 0.85rem;
    line-height: 1.4;
  }

  main#chat {
    padding: 1rem;
  }

  .bubble {
    max-width: 100%;
    padding: 0.7rem 0.8rem;
    border-radius: 8px;
  }

  .bubble.user {
    max-width: 92%;
  }

  .badge {
    margin-top: 0.3rem;
    margin-left: 0;
  }

  details summary {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  details pre,
  pre.cli {
    margin-right: -0.25rem;
    margin-left: -0.25rem;
    padding: 0.55rem;
    font-size: 0.75rem;
  }

  #options {
    padding: 0.75rem 1rem max(1rem, env(safe-area-inset-bottom));
    gap: 0.6rem;
  }

  #options button {
    width: 100%;
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    text-align: left;
  }

  #options .section-label {
    margin-top: 0.65rem;
  }
}

@media (hover: none) {
  #options button:hover {
    border-color: var(--border);
  }

  #options button:active {
    border-color: var(--accent);
  }
}
