:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1b1e24;
  --muted: #646b78;
  --line: #e2e5ea;
  --accent: #2f6fe4;
  --accent-text: #ffffff;
  --user: #2f6fe4;
  --user-text: #ffffff;
  --warn-bg: #fff6e0;
  --warn-line: #e9c46a;
  --error-bg: #fdecec;
  --error-text: #a12a2a;
  --ready: #2fa45a;
  --busy: #e0a100;
  --off: #9aa1ad;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1d2026;
    --text: #e6e8ec;
    --muted: #9399a5;
    --line: #2c3038;
    --accent: #4f8cff;
    --accent-text: #0d1220;
    --user: #3a6fd8;
    --user-text: #ffffff;
    --warn-bg: #2d2615;
    --warn-line: #7a6326;
    --error-bg: #3a1d1f;
    --error-text: #f2a7a7;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

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

button:disabled { opacity: 0.45; cursor: default; }

a { color: var(--accent); overflow-wrap: anywhere; }

/* ------------------------------------------------------------- header */

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.name { font-weight: 650; font-size: 18px; }
.status { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.actions { display: flex; gap: 6px; }
.actions form { margin: 0; }
.actions button { padding: 6px 10px; font-size: 14px; }
.actions button.icon { display: flex; align-items: center; height: 100%; }

.light {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--off);
  display: inline-block;
  flex: none;
}
.light.ready { background: var(--ready); }
.light.busy, .light.starting { background: var(--busy); animation: pulse 1.2s infinite; }
.light.broken { background: var(--error-text); }

@keyframes pulse { 50% { opacity: 0.35; } }

/* ------------------------------------------------------------- log */

.log {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 120px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty { color: var(--muted); text-align: center; margin-top: 18vh; padding: 0 12px; }

.msg {
  padding: 10px 14px;
  border-radius: 16px;
  max-width: 92%;
  overflow-wrap: anywhere;
}

.msg p { margin: 0 0 8px; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 4px 0 8px; padding-left: 22px; }
.msg h3 { font-size: 16px; margin: 8px 0 4px; }
.msg code { font-size: 14px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }

.msg.user {
  align-self: flex-end;
  background: var(--user);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}
.msg.user a { color: inherit; }

.msg.dot {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.msg.job {
  align-self: stretch;
  max-width: none;
  font-size: 14px;
  color: var(--muted);
  border: 1px dashed var(--line);
}
.msg.job .label { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }

.msg.error {
  align-self: flex-start;
  background: var(--error-bg);
  color: var(--error-text);
}

.msg.confirm {
  align-self: stretch;
  max-width: none;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
}
.msg.confirm .label { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.msg.confirm .choices { display: flex; gap: 8px; margin-top: 10px; }
.msg.confirm.done { opacity: 0.7; }
.msg.confirm.done .choices span { color: var(--muted); font-size: 14px; }

.steps {
  align-self: flex-start;
  max-width: 100%;
  font-size: 13px;
  color: var(--muted);
}
.steps summary { cursor: pointer; padding: 2px 0; }
.steps[open] summary { color: var(--text); }
.steps ol {
  list-style: none;
  margin: 4px 0 0;
  padding: 8px 10px;
  border-left: 2px solid var(--line);
  max-height: 260px;
  overflow-y: auto;
}
.steps li { overflow-wrap: anywhere; padding: 1px 0; }
.steps .tag {
  display: inline-block;
  min-width: 58px;
  margin-right: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--accent);
}

/* ------------------------------------------------------------- composer */

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  max-width: 712px;
  margin-left: auto;
  resize: none;
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming in */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 9px 12px;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }

.composer button {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  margin-right: auto;
}

/* ------------------------------------------------------------- login */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.card h1 { margin: 0 0 8px; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.card label { font-size: 14px; color: var(--muted); }
.card input {
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
.card .error { color: var(--error-text); margin: 0; font-size: 14px; }
