:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --ink: #24272a;
  --muted: #65706b;
  --line: #d9d4c6;
  --panel: #fffdf8;
  --accent: #1e6f68;
  --accent-strong: #15534e;
  --danger: #a23b3b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: 24px;
  width: min(1180px, calc(100vw - 32px));
  margin: 32px auto;
}

.topbar,
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
}

.panel,
.result {
  margin-top: 20px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.result {
  margin-top: 0;
}

label {
  display: grid;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 500;
}

textarea {
  resize: vertical;
  line-height: 1.5;
  padding: 14px;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.ghost:hover {
  border-color: var(--accent);
  background: #edf7f5;
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--accent-strong);
  background: #edf7f5;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

#replyOutput {
  margin-top: 16px;
  min-height: 430px;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.source-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #f4efe4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status {
  min-height: 24px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 700;
}

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

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    margin: 18px auto;
  }

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

  .topbar,
  .result-header {
    align-items: flex-start;
  }
}
