:root {
  --bg: #f6f6f4; --panel: #fff; --text: #1d1d1b; --muted: #6b6b66; --line: #e3e3de;
  --accent: #1f6f5c; --accent-text: #fff; --user: #eaf3f0; --danger: #b3261e;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: inherit; }

.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 20px 14px;
  background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px; }
.brand { text-decoration: none; display: flex; flex-direction: column; }
.brand span { color: var(--muted); font-size: 13px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.conv { display: block; padding: 7px 9px; border-radius: 6px; text-decoration: none; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv:hover { background: var(--bg); }
.conv.active { background: var(--user); font-weight: 600; }

.main { max-width: 860px; width: 100%; margin: 0 auto; padding: 28px 24px 0; display: flex; flex-direction: column; min-height: 100vh; }
.intro p { color: var(--muted); line-height: 1.5; }

.button { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); text-decoration: none; text-align: center; cursor: pointer; font: inherit; font-size: 14px; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.subtle { color: var(--muted); }
.button:disabled { opacity: .6; cursor: progress; }

textarea { width: 100%; font: inherit; font-size: 15px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); resize: vertical; }
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.brief-form .row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.brief-form small { color: var(--muted); }

.conv-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.conv-header h2 { margin: 0; font-size: 18px; }
.thread { flex: 1; padding: 16px 0; }
.message { padding: 14px 16px; border-radius: 12px; margin-bottom: 14px; background: var(--panel); border: 1px solid var(--line); }
.message.user { background: var(--user); border-color: transparent; }
.message.failed { border-color: var(--danger); }
.message .who { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
.message .body { line-height: 1.55; overflow-wrap: anywhere; }
.message .body > :first-child { margin-top: 0; }
.message .body > :last-child { margin-bottom: 0; }
.message .body h2 { font-size: 17px; margin: 20px 0 6px; }
.message .body h3 { font-size: 15px; margin: 16px 0 4px; }
.message .body table { border-collapse: collapse; margin: 10px 0; display: block; overflow-x: auto; }
.message .body th, .message .body td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.thinking { color: var(--muted); animation: pulse 1.4s ease-in-out infinite; }
.cursor { animation: pulse 1s steps(2) infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.composer { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0 20px; }
.reply-form { display: flex; gap: 10px; align-items: flex-end; }
.reply-form .button { flex-shrink: 0; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--user); }
.flash.alert { background: #fbe9e7; color: var(--danger); }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { max-height: 160px; overflow-y: auto; }
  .main { padding: 16px 16px 0; }
}
.message .retry { margin-top: 10px; }

/* Brief dropdowns */
.selects { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.selects .field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.selects label { font-size: 13px; font-weight: 500; color: var(--muted); }
.selects select { font: inherit; font-size: 15px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); width: 100%; }
.message .body h1 { font-size: 19px; margin: 0 0 8px; }
@media (max-width: 720px) { .selects { grid-template-columns: 1fr; } }

/* Draft → full strategy */
.message.draft { border-left: 4px solid var(--accent); }
.message.full { border-left: 4px solid #8a5a00; }
.message.full .who { color: #8a5a00; }
.strategy-actions { display: flex; justify-content: flex-end; }
.strategy-actions > * { margin-bottom: 8px; }
.working { margin: 0; flex: 1; color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.working .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.req { color: var(--danger); }
.field_with_errors { display: contents; }
.brief-form .field_with_errors textarea, .brief-form .field_with_errors select { border-color: var(--danger); }
