:root {
  --bg: #f4f1ea;
  --paper: #fff8f0;
  --ink: #1f1e1b;
  --muted: #6c665e;
  --accent: #b44b2a;
  --accent-soft: rgba(180, 75, 42, 0.15);
  --border: #e0d7cc;
  --shadow: 0 18px 35px rgba(31, 30, 27, 0.08);
  --radius: 16px;
  --mono: "IBM Plex Mono", "Courier New", monospace;
  --serif: "Spectral", "Georgia", serif;
  --sans: "Manrope", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: radial-gradient(circle at top, #fff2e2 0%, #f4f1ea 55%, #eee8df 100%);
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 6vw 12px;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  background: var(--accent);
  color: #fff8f0;
  font-weight: 700;
  padding: 12px 14px;
  border-radius: 12px;
  font-family: var(--mono);
}

h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
  font-family: var(--serif);
}

p {
  margin: 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  gap: 12px;
}

button {
  border: 1px solid var(--border);
  background: #fff8f0;
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
  padding: 12px 6vw 40px;
}

.panel {
  background: var(--paper);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 500px;
}

.panel-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--serif);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  font-weight: 600;
}

input,
textarea,
select {
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 10px;
  font-family: var(--sans);
  background: #fff;
  font-size: 0.95rem;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.field-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.preview {
  font-family: var(--serif);
  line-height: 1.6;
  background: #fff;
  border-radius: 12px;
  border: 1px dashed var(--border);
  padding: 18px;
  min-height: 420px;
}

.preview h3 {
  margin-top: 20px;
  margin-bottom: 8px;
  font-family: var(--sans);
}

.preview ul {
  padding-left: 20px;
}

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

.app-footer {
  padding: 16px 6vw 32px;
  font-family: var(--mono);
  color: var(--muted);
}

@media (max-width: 720px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }
}

/* ── Layout: AI config full-width row ──────────────────────── */
@media (min-width: 721px) {
  .layout--with-ai {
    grid-template-columns: 1fr 1fr;
  }

  .panel--ai-config {
    grid-column: 1 / -1;
  }
}

/* ── AI config tabs ────────────────────────────────────────── */
.ai-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.ai-tab {
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  box-shadow: none;
}

.ai-tab:hover {
  color: var(--ink);
  background: var(--accent-soft);
  transform: none;
  box-shadow: none;
  border-color: transparent;
}

.ai-tab--active {
  color: var(--accent);
  background: var(--accent-soft);
  border-bottom: 2px solid var(--accent);
}

.ai-tab-pane { display: none; }
.ai-tab-pane--active { display: block; }

.ai-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* ── Output controls ───────────────────────────────────────── */
.output-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.field--toggles {
  grid-column: 1 / -1;
}

.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  font-size: 0.9rem;
  cursor: pointer;
}

/* ── Generate button ───────────────────────────────────────── */
.btn--generate {
  width: 100%;
  background: var(--accent);
  color: #fff8f0;
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s;
}

.btn--generate:hover {
  opacity: 0.88;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: transparent;
}

.btn--generate:disabled,
.btn--generate.loading {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ── Input extensions ──────────────────────────────────────── */
.input-extensions {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.file-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.88rem;
  font-family: var(--mono);
}

.remove-file {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 1rem;
  line-height: 1;
}

.remove-file:hover {
  color: var(--accent);
  transform: none;
  box-shadow: none;
  border: none;
}

.repo-input-row {
  display: flex;
  gap: 8px;
}

.repo-input-row input { flex: 1; }

/* ── Disclosure banner ─────────────────────────────────────── */
.disclosure-banner {
  margin: 0 6vw 12px;
  padding: 10px 16px;
  background: var(--accent-soft);
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--ink);
  border: 1px solid rgba(180, 75, 42, 0.2);
}

.disclosure-banner a {
  color: var(--accent);
}

/* ── Error container ───────────────────────────────────────── */
.error-container {
  background: #fff0ee;
  border: 1px solid #f5c0b0;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.9rem;
  color: #8b2000;
  margin-bottom: 12px;
}

.error-container[hidden] { display: none; }

/* ── Citation footer ───────────────────────────────────────── */
.citation-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.citation-footer strong {
  font-family: var(--sans);
  color: var(--muted);
  margin-right: 4px;
}

/* ── Citation chips ────────────────────────────────────────── */
.citation {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-family: var(--mono);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 3px;
  vertical-align: middle;
  white-space: nowrap;
}

/* ── Repo status states ────────────────────────────────────── */
#repo-status.loading { color: var(--muted); font-style: italic; }
#repo-status.success { color: #2a7a2a; }
#repo-status.error   { color: #8b2000; }

/* ── fieldset reset for toggle group ──────────────────────── */
fieldset.field--toggles {
  border: none;
  margin: 0;
  padding: 0;
}

fieldset.field--toggles legend {
  font-weight: 600;
  margin-bottom: 4px;
  padding: 0;
  float: left;
  width: 100%;
}

/* ── Document type row ─────────────────────────────────────── */
.doc-type-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.doc-type-row .field {
  flex: 1 1 180px;
  min-width: 0;
}

/* ── Schema switch notice ──────────────────────────────────── */
.schema-notice {
  background: var(--accent-soft);
  border: 1px solid rgba(180, 75, 42, 0.25);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.82rem;
  color: #6b2c12;
  margin-bottom: 12px;
}

/* ── Template preview block ────────────────────────────────── */
.template-preview {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--paper);
  font-size: 0.85rem;
}

.template-preview > strong {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.76rem;
}

.template-heading {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-heading-marker {
  color: var(--muted);
  margin-right: 4px;
}

.template-placeholders {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  line-height: 1.9;
}

.placeholder-chip {
  display: inline-block;
  background: rgba(180, 75, 42, 0.1);
  color: #7a2a10;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: 0.78rem;
  margin: 2px 2px;
}

/* ── Validation warnings ───────────────────────────────────── */
.validation-warnings {
  background: #fffbe6;
  border: 1px solid #d4a017;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: #5a4000;
}

.validation-warnings strong {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
}

.validation-warnings ul {
  margin: 0;
  padding-left: 18px;
}

.validation-warnings li {
  margin: 2px 0;
}
