:root {
  --color-bg: #f6f7f9;
  --color-surface: #ffffff;
  --color-surface-alt: #f0f2f5;
  --color-border: #d8dde3;
  --color-text: #1f2933;
  --color-text-muted: #5b6570;
  --color-primary: #1b6a5a;
  --color-primary-hover: #155447;
  --color-primary-soft: #e4f0ec;
  --color-danger: #b3261e;
  --color-danger-soft: #fdecea;
  --color-focus: #2f7d6c;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.06);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.container {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-primary);
  color: #fff;
  padding: 8px 14px;
  border-radius: 0 0 var(--radius) 0;
  z-index: 100;
}
.skip-link:focus {
  left: 0;
}

/* Header */
.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
}
.brand {
  margin: 0;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-weight: 400;
  color: var(--color-text-muted);
}
.brand-version {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-left: 2px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.session-hint {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Main layout */
.main {
  flex: 1;
  padding-top: 32px;
  padding-bottom: 48px;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 28px;
}

.login-card {
  max-width: 440px;
  margin: 0 auto;
}

.heading-1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
}
.heading-2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}
.lede {
  margin: 0 0 24px;
  color: var(--color-text-muted);
}

/* Fields */
.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
}
.field input,
.field textarea {
  width: 100%;
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.field textarea {
  resize: vertical;
  min-height: 220px;
  line-height: 1.5;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}
.field input:focus,
.field textarea:focus {
  outline: 2px solid var(--color-focus);
  outline-offset: 1px;
  border-color: var(--color-focus);
}
.field-hint {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

/* Segmented control */
.segmented {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--color-surface-alt);
}
.segmented button {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 20px;
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}
.segmented button[aria-checked="true"] {
  background: var(--color-primary);
  color: #fff;
}
.segmented button:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: -2px;
}

/* Buttons */
.button {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.12s ease;
}
.button-block { width: 100%; }
.button-primary {
  background: var(--color-primary);
  color: #fff;
}
.button-primary:hover { background: var(--color-primary-hover); }
.button-primary:disabled {
  background: var(--color-border);
  color: var(--color-text-muted);
  cursor: not-allowed;
}
.button-ghost {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-border);
}
.button-ghost:hover { background: var(--color-primary-soft); }
.button:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

/* Form errors */
.form-errors {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--color-danger-soft);
  border: 1px solid #f3c9c6;
  border-radius: var(--radius);
  color: var(--color-danger);
  font-size: 0.9rem;
  white-space: pre-wrap;
}

/* App view */
.app-view .grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}
.app-view .card { padding: 24px; }

/* Status region */
.status-region { margin-top: 20px; }
.status-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 0.95rem;
}
.status-inner[data-tone="info"] { border-color: var(--color-border); }
.status-inner[data-tone="error"] {
  border-color: #f3c9c6;
  background: var(--color-danger-soft);
  color: var(--color-danger);
}
.status-inner[data-tone="success"] {
  border-color: #bfe0d6;
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
.spinner {
  width: 18px;
  height: 18px;
  flex: none;
  border: 2px solid rgba(27, 106, 90, 0.25);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Report */
.report-section { margin-top: 28px; }
.report-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}
.report {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 28px;
}
.report:focus {
  outline: none;
}

/* Markdown rendering */
.markdown h1 {
  font-size: 1.4rem;
  margin: 0 0 16px;
  letter-spacing: -0.02em;
}
.markdown h2 {
  font-size: 1.15rem;
  margin: 28px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--color-border);
  letter-spacing: -0.01em;
}
.markdown h3 { font-size: 1rem; margin: 20px 0 8px; }
.markdown p { margin: 0 0 14px; }
.markdown ul, .markdown ol { margin: 0 0 14px; padding-left: 24px; }
.markdown li { margin-bottom: 4px; }
.markdown strong { font-weight: 700; }
.markdown blockquote {
  margin: 0 0 14px;
  padding: 4px 16px;
  border-left: 3px solid var(--color-border);
  color: var(--color-text-muted);
}
.markdown code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--color-surface-alt);
  border-radius: 4px;
  padding: 2px 5px;
}
.markdown pre {
  background: #1e2833;
  color: #e8edf2;
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  margin: 0 0 14px;
}
.markdown pre code { background: transparent; padding: 0; color: inherit; }
.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 0.9rem;
  display: block;
  overflow-x: auto;
}
.markdown th, .markdown td {
  border: 1px solid var(--color-border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.markdown th {
  background: var(--color-surface-alt);
  font-weight: 600;
}
.markdown hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: 24px 0;
}
.markdown a { color: var(--color-primary); }

/* Footer */
.site-footer {
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 0.82rem;
}
.site-footer p { margin: 14px 0; }

/* Field header (label + inline action) */
.field-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.field-header label { margin-bottom: 0; }

.button-sm {
  padding: 5px 12px;
  font-size: 0.85rem;
}
.button-sm:disabled {
  color: var(--color-text-muted);
  border-color: var(--color-border);
  cursor: not-allowed;
}
.button-sm:disabled:hover { background: transparent; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 24, 40, 0.45);
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 24px;
  width: 100%;
  max-width: 440px;
}
.modal .heading-2 { margin-bottom: 12px; }
.modal-selected {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 16px;
  font-size: 0.88rem;
  min-width: 0;
}
.modal-selected-label {
  flex: none;
  font-weight: 600;
}
.modal-selected-text {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--color-surface-alt);
  border-radius: var(--radius);
  padding: 2px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.modal .field { margin-bottom: 18px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 4px;
}

/* Responsive */
@media (max-width: 600px) {
  .card { padding: 20px; }
  .report { padding: 20px; }
  .modal { padding: 20px; }
  .container { padding: 0 16px; }
}
