:root {
  color: #18212b;
  background: #f4f6f8;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --background: #f4f6f8;
  --surface: #ffffff;
  --surface-subtle: #f8fafb;
  --text: #18212b;
  --muted: #647180;
  --border: #dce2e8;
  --border-strong: #c7d0d9;
  --accent: #315fbd;
  --accent-hover: #264e9d;
  --success: #207a4b;
  --success-bg: #e9f6ef;
  --warning: #8a5a0a;
  --warning-bg: #fff4d8;
  --danger: #a63b37;
  --danger-bg: #fff0ef;
  --focus: #6b9cff;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--background);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--background);
  color: var(--text);
  line-height: 1.5;
}

button,
a,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
  font: inherit;
}

code {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 8px 12px;
  border-radius: 4px;
  background: var(--text);
  color: #fff;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.shell {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid rgba(220, 226, 232, 0.92);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.header-inner,
.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-weight: 750;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 15px;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.header-actions,
.live-status {
  display: flex;
  align-items: center;
}

.header-actions {
  gap: 12px;
}

.header-actions form {
  margin: 0;
}

.live-status {
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #96a1ac;
}

.live-status[data-tone="success"] {
  color: var(--success);
}

.live-status[data-tone="success"] .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px var(--success-bg);
}

.live-status[data-tone="warning"] {
  color: var(--warning);
}

.live-status[data-tone="warning"] .status-dot {
  background: var(--warning);
  box-shadow: 0 0 0 4px var(--warning-bg);
}

.live-status[data-tone="danger"] {
  color: var(--danger);
}

.live-status[data-tone="danger"] .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px var(--danger-bg);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 650;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

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

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

.button.quiet {
  background: transparent;
  color: var(--muted);
}

.button.quiet:hover {
  color: var(--text);
}

.full-width {
  width: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ai-body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.ai-page {
  display: flex;
  width: min(1040px, calc(100% - 48px));
  min-height: calc(100vh - 65px);
  padding: 32px 0;
  flex: 1;
  flex-direction: column;
  gap: 20px;
}

.ai-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.ai-toolbar h1 {
  margin: 2px 0 4px;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.1;
  letter-spacing: -0.025em;
}

.ai-context {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.ai-offline {
  margin: 0;
}

.ai-offline p {
  margin: 4px 0 0;
}

.ai-console {
  display: grid;
  min-height: 560px;
  flex: 1;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(24, 33, 43, 0.06);
  grid-template-rows: minmax(0, 1fr) auto;
}

.ai-feed {
  display: flex;
  min-height: 0;
  padding: 28px;
  overflow-y: auto;
  flex-direction: column;
  gap: 18px;
  overscroll-behavior: contain;
}

.ai-empty {
  max-width: 520px;
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.ai-empty-mark {
  display: grid;
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  place-items: center;
  border-radius: 14px;
  background: #edf2ff;
  color: var(--accent);
  font-size: 15px;
  font-weight: 800;
}

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

.ai-empty p {
  margin: 0;
}

.ai-message {
  display: flex;
  width: min(82%, 760px);
  flex-direction: column;
  gap: 5px;
}

.ai-message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.ai-message.assistant,
.ai-message.system,
.ai-approval {
  align-self: flex-start;
}

.ai-message-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ai-message-content {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-subtle);
  color: var(--text);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.ai-message.user .ai-message-content {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.ai-message.system {
  width: min(90%, 780px);
}

.ai-message.system .ai-message-content {
  padding: 9px 12px;
  border-style: dashed;
  color: var(--muted);
  font-size: 13px;
}

.ai-message.system.error .ai-message-content {
  border-color: #e6b7b5;
  background: var(--danger-bg);
  color: var(--danger);
}

.ai-cursor::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-left: 3px;
  background: var(--accent);
  vertical-align: -2px;
  animation: ai-blink 900ms steps(2, start) infinite;
}

@keyframes ai-blink {
  50% { opacity: 0; }
}

.ai-approval {
  width: min(92%, 780px);
  padding: 16px;
  border: 1px solid #e8c880;
  border-radius: 10px;
  background: var(--warning-bg);
}

.ai-approval h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.ai-approval p,
.ai-approval pre {
  margin: 0 0 12px;
}

.ai-approval pre {
  max-height: 180px;
  padding: 10px;
  overflow: auto;
  border: 1px solid rgba(138, 90, 10, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.65);
  font: 12px/1.45 "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap;
}

.ai-approval-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ai-question-card fieldset {
  padding: 0;
  margin: 14px 0;
  border: 0;
}

.ai-question-card legend {
  margin-bottom: 8px;
  font-weight: 700;
}

.ai-choice {
  display: flex;
  align-items: flex-start;
  padding: 7px 0;
  gap: 9px;
  cursor: pointer;
}

.ai-choice input {
  margin-top: 5px;
}

.ai-answer-input {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
}

.ai-composer {
  padding: 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-subtle);
}

.ai-composer textarea {
  display: block;
  width: 100%;
  min-height: 68px;
  max-height: 220px;
  padding: 12px 14px;
  resize: vertical;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  line-height: 1.45;
}

.ai-composer textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(107, 156, 255, 0.22);
}

.ai-composer textarea:disabled {
  cursor: not-allowed;
  background: #eef1f4;
  color: var(--muted);
}

.ai-composer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-top: 10px;
  gap: 10px;
}

.ai-hint {
  margin-right: auto;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 760px) {
  .ai-page {
    width: min(100% - 24px, 1040px);
    min-height: calc(100vh - 65px);
    padding: 20px 0 12px;
  }

  .ai-toolbar {
    align-items: flex-start;
  }

  .ai-console {
    min-height: 65vh;
    border-radius: 10px;
  }

  .ai-feed {
    padding: 18px 14px;
  }

  .ai-message,
  .ai-message.system,
  .ai-approval {
    width: 94%;
  }

  .ai-hint {
    display: none;
  }
}

@media (max-width: 560px) {
  .ai-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .ai-toolbar .button {
    align-self: flex-start;
  }

  .ai-composer-actions {
    flex-wrap: wrap;
  }

  .ai-composer-actions .button.primary {
    min-width: 112px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-cursor::after {
    animation: none;
  }
}

.button.secondary {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.button.secondary:hover {
  border-color: #aab6c2;
  background: var(--surface-subtle);
}

.button:disabled {
  cursor: wait;
  opacity: 0.62;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.page {
  padding-top: 40px;
  padding-bottom: 48px;
}

.auth-body {
  display: grid;
  min-height: 100vh;
  padding: 32px 16px;
  place-items: center;
}

.auth-shell {
  width: min(100%, 520px);
}

.auth-brand {
  margin: 0 0 20px;
}

.auth-card,
.settings-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.auth-card {
  padding: 32px;
}

.lead.compact {
  margin-bottom: 20px;
}

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

.field {
  display: grid;
  gap: 8px;
  font-weight: 650;
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.field input:focus {
  border-color: var(--accent);
}

.field small,
.support-copy {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.field small a,
.text-link {
  color: var(--accent);
}

.form-message {
  padding: 12px 14px;
  border-left: 3px solid var(--danger);
  border-radius: 4px;
  background: var(--danger-bg);
  color: var(--danger);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.form-message[data-tone="success"] {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
}

.notice.info-state {
  margin-bottom: 20px;
  border-left-color: var(--accent);
}

.notice.warning-state {
  margin-bottom: 24px;
  border-left-color: var(--warning);
  background: var(--warning-bg);
  color: var(--warning);
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.7fr);
  gap: 24px;
  align-items: start;
}

.settings-card {
  padding: 24px;
}

.compact-heading {
  margin-bottom: 0;
}

.field-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.profile-state {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.profile-state[data-tone="success"],
.capability-list strong[data-tone="success"] {
  color: var(--success);
}

.capability-list strong[data-tone="warning"],
.warning-text {
  color: var(--warning);
}

.capability-list {
  display: grid;
  margin: 20px 0;
  padding: 0;
  list-style: none;
}

.capability-list li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.capability-list li:last-child {
  border-bottom: 0;
}

.capability-list strong {
  text-align: right;
}

.overview {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow,
.metric-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 8px;
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1.12;
  letter-spacing: -0.025em;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.lead {
  max-width: 700px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 16px;
}

.overview-meta {
  min-width: 180px;
  text-align: right;
}

.overview-meta span,
.overview-meta strong {
  display: block;
}

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

.overview-meta strong {
  margin-top: 4px;
  font-size: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  margin-bottom: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric {
  min-width: 0;
  padding: 20px;
  border-right: 1px solid var(--border);
}

.metric:last-child {
  border-right: 0;
}

.metric strong,
.metric small {
  display: block;
}

.metric strong {
  overflow-wrap: anywhere;
  font-size: 20px;
  line-height: 1.25;
}

.metric small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.section {
  margin-top: 32px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.section-heading > p {
  max-width: 520px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.section-heading.compact {
  margin-bottom: 16px;
}

.flow {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.flow-step {
  position: relative;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.flow-step:not(:last-child)::after {
  position: absolute;
  z-index: 2;
  top: 28px;
  right: -9px;
  width: 9px;
  height: 1px;
  background: var(--border-strong);
  content: "";
}

.step-index {
  display: grid;
  width: 24px;
  height: 24px;
  margin-bottom: 16px;
  place-items: center;
  border-radius: 50%;
  background: #edf1f5;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.flow-step strong,
.flow-step div > span {
  display: block;
}

.flow-step strong {
  font-size: 14px;
}

.flow-step div > span {
  min-height: 54px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.state-label {
  display: inline-flex;
  margin-top: 12px;
  padding: 3px 7px;
  border-radius: 4px;
  background: #edf1f5;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.state-label.success,
.tool-state.success {
  background: var(--success-bg);
  color: var(--success);
}

.state-label.warning,
.tool-state.warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.state-label.neutral {
  background: #edf1f5;
  color: var(--muted);
}

.tool-list {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.tool-row {
  display: grid;
  grid-template-columns: minmax(210px, 0.9fr) minmax(260px, 1.35fr) minmax(220px, 1fr);
  align-items: start;
  gap: 20px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.tool-row:last-child {
  border-bottom: 0;
}

.tool-name {
  min-width: 0;
}

.tool-name code,
.tool-name strong,
.tool-copy,
.tool-reason {
  display: block;
}

.tool-name code {
  overflow-wrap: anywhere;
  color: var(--accent);
  font-size: 12px;
}

.tool-name strong {
  margin-top: 4px;
  font-size: 14px;
}

.tool-copy,
.tool-reason {
  color: var(--muted);
  font-size: 13px;
}

.tool-status-cell {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.tool-state {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 750;
}

.tool-prompt-button {
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.tool-prompt-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tool-prompt-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.loading-row,
.error-row {
  padding: 24px 20px;
  color: var(--muted);
}

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

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.8fr);
  gap: 40px;
}

.instruction-list {
  margin: 0;
  padding-left: 24px;
}

.instruction-list li {
  padding: 4px 0 8px 8px;
}

.endpoint-panel {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.endpoint-panel code {
  display: block;
  overflow-wrap: anywhere;
  margin: 8px 0 16px;
  color: var(--accent);
  font-size: 13px;
}

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

.notice {
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.notice p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.privacy-note {
  border-left: 4px solid var(--success);
}

.error-state {
  border-color: #e6b8b5;
  background: var(--danger-bg);
  color: var(--danger);
}

.app-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 24px;
  bottom: 24px;
  max-width: min(360px, calc(100% - 48px));
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--text);
  color: #fff;
  font-size: 13px;
}

.clipboard-fallback {
  position: fixed;
  left: -10000px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

@media (max-width: 980px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n + 2) {
    border-bottom: 1px solid var(--border);
  }

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

  .flow-step {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
  }

  .flow-step:not(:last-child)::after {
    top: auto;
    right: auto;
    bottom: -9px;
    left: 32px;
    width: 1px;
    height: 9px;
  }

  .step-index,
  .state-label {
    margin: 0;
  }

  .flow-step div > span {
    min-height: 0;
  }

  .tool-row {
    grid-template-columns: minmax(190px, 0.8fr) minmax(250px, 1.2fr);
  }

  .tool-status-cell {
    grid-column: 1 / -1;
    padding-top: 4px;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 32px, 1180px);
  }

  .header-inner {
    min-height: 60px;
  }

  .header-actions {
    gap: 8px;
  }

  .header-actions .button {
    padding-inline: 10px;
  }

  .live-status span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .button {
    min-height: 44px;
  }

  .page {
    padding-top: 28px;
  }

  .overview,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .overview-meta {
    min-width: 0;
    text-align: left;
  }

  .section-heading > p {
    max-width: none;
    text-align: left;
  }

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

  .metric,
  .metric:nth-child(2) {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .metric:last-child {
    border-bottom: 0;
  }

  .flow-step {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .state-label {
    grid-column: 2;
    justify-self: start;
  }

  .tool-row,
  .two-column {
    grid-template-columns: 1fr;
  }

  .tool-status-cell {
    grid-column: auto;
    flex-direction: column;
  }

  .tool-prompt-button {
    width: 100%;
    min-height: 44px;
  }

  .auth-card {
    padding: 24px 20px;
  }

  .settings-layout {
    grid-template-columns: 1fr;
  }

  .settings-card {
    padding: 20px 16px;
  }

  .field-heading,
  .capability-list li {
    align-items: flex-start;
    flex-direction: column;
  }

  .capability-list strong {
    text-align: left;
  }

  .footer-inner {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding: 16px 0;
  }
}

@media (max-width: 520px) {
  .header-inner {
    flex-wrap: wrap;
    padding: 8px 0;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .live-status {
    margin-right: auto;
  }

  #ai-status {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
