:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1c1b19;
  --muted: #6b6862;
  --line: #e2ded6;
  --accent: #8a1e3c;
  --accent-soft: #f3e6ea;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(28, 27, 25, 0.06), 0 8px 24px rgba(28, 27, 25, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --panel: #1f1f24;
    --ink: #ecebe8;
    --muted: #a3a09a;
    --line: #32323a;
    --accent: #e2899f;
    --accent-soft: #2c2026;
    --on-accent: #20151a;
    --danger: #ffaaa4;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

/* `hidden` must win over the layout display values used below, or the drawer
   and the inline forms stay visible after being hidden. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.source {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar__right {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

input,
select,
textarea,
button {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 10px;
}

button {
  cursor: pointer;
}

button.primary,
.chatform button,
#gateForm button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

button.ghost {
  background: transparent;
}

.toggle {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

main {
  padding: 20px 22px 60px;
}

.status-line {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 14px;
}

.board {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  align-items: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card__head {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
}

.card h3 {
  margin: 0;
  font-size: 15px;
}

.chip {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.chip--active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.chip--done {
  opacity: 0.7;
}

.chip--dropped {
  text-decoration: line-through;
  opacity: 0.6;
}

.details {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
}

.details li {
  margin: 2px 0;
}

.latest {
  font-size: 13px;
  border-left: 2px solid var(--accent);
  padding-left: 9px;
}

.latest time {
  color: var(--muted);
  margin-right: 6px;
}

.card__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.card__actions button {
  font-size: 13px;
  padding: 5px 9px;
}

.card form {
  display: flex;
  gap: 8px;
}

.card form input {
  flex: 1;
}

.error {
  color: var(--danger);
  font-size: 13px;
}

.gate {
  max-width: 420px;
  margin: 60px auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
}

.gate h2 {
  margin-top: 0;
}

.gate form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  z-index: 10;
}

.drawer__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.drawer__label {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.drawer h2 {
  margin: 2px 0 0;
  font-size: 16px;
}

.chatlog {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 14px;
  white-space: pre-wrap;
}

.msg--user {
  background: var(--accent-soft);
}

.msg__actions {
  margin-top: 8px;
}

.actions {
  margin: 8px 0 0;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}

.action {
  color: var(--muted);
}

.action code {
  color: var(--ink);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 4px;
  margin-right: 4px;
}

.action--fail {
  color: var(--danger);
}

.newbar {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 22px;
}

.newbar form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.newbar input:first-child {
  flex: 1;
  min-width: 220px;
}

.newbar input:nth-child(2) {
  flex: 2;
  min-width: 220px;
}

.chatform {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chatform textarea {
  flex: 1;
  resize: vertical;
}

@media (max-width: 640px) {
  .board {
    grid-template-columns: 1fr;
  }
  .topbar {
    align-items: flex-start;
  }
}

/* --- Kitchen page ---------------------------------------------------------- */

.topbar a {
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
}

.kitchen {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 18px;
  padding: 20px 22px 60px;
  align-items: start;
}

.intake {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  position: sticky;
  top: 86px;
  box-shadow: var(--shadow);
}

.intake h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.intake form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.intake label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.intake--sent {
  opacity: 0.8;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 70vh;
}

.transcript .chatlog {
  max-height: 62vh;
  min-height: 40vh;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--panel);
}

.chatlog--busy {
  opacity: 0.85;
}

.mermaid {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  overflow-x: auto;
  margin: 8px 0;
}

.mermaid--failed {
  border-color: #b3261e;
}

.msg table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}

.msg th,
.msg td {
  border: 1px solid var(--line);
  padding: 4px 6px;
  text-align: left;
}

.msg h2,
.msg h3,
.msg h4 {
  margin: 12px 0 4px;
  font-size: 15px;
}

.msg code {
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 4px;
}

.msg blockquote {
  margin: 6px 0;
  padding-left: 8px;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 900px) {
  .kitchen {
    grid-template-columns: 1fr;
  }
  .intake {
    position: static;
  }
  .transcript .chatlog {
    max-height: none;
  }
}
