:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #e9e9ec;
  --border: #d1d1d6;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #0071e3;
  --good: #1f9d4d;
  --attention: #c77700;
  --attention-bg: rgba(255, 159, 10, 0.14);
  --bad: #d92d20;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --surface: #2c2c2e;
    --surface-2: #3a3a3c;
    --border: #48484a;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --accent: #0a84ff;
    --good: #32d74b;
    --attention: #ff9f0a;
    --bad: #ff6961;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app { flex: 1; min-height: 0; }

.connection-banner {
  background: var(--attention-bg);
  border-bottom: 1px solid var(--attention);
  padding: 6px 16px;
  padding-top: max(6px, env(safe-area-inset-top));
  font-size: 13px;
  text-align: center;
}

a { color: inherit; text-decoration: none; }

button, input, select, textarea { font: inherit; color: inherit; }

button {
  background: var(--surface-2);
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}

button.primary { background: var(--accent); color: #fff; }
button.quiet { background: transparent; color: var(--muted); padding: 6px 8px; }
button:disabled { opacity: 0.5; cursor: default; }

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  width: 100%;
  min-width: 0;
}

textarea { resize: vertical; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

[hidden] { display: none !important; }

.muted { color: var(--muted); }
.right { margin-left: auto; }

.view { display: flex; flex-direction: column; height: 100%; }

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.top .worker-state { display: flex; align-items: center; margin-left: auto; }
.top .back { font-size: 22px; line-height: 1; padding: 0 6px 2px 0; }

.page {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px max(16px, calc((100% - 848px) / 2)) 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stack { display: flex; flex-direction: column; gap: 12px; }

.bottom-nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav .tab { flex: 1; text-align: center; padding: 11px 0; color: var(--muted); }
.bottom-nav .tab.on { color: var(--accent); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stat strong { font-size: 22px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12px; }
.stat.attention { border-color: var(--attention); background: var(--attention-bg); }
.stat.bad strong { color: var(--bad); }
.stat.active strong { color: var(--accent); }

.banner {
  background: var(--attention-bg);
  border: 1px solid var(--attention);
  border-radius: 10px;
  padding: 9px 12px;
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }

.card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.card-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.card-prompt {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; background: var(--muted); flex: none; }
.dot.good { background: var(--good); }
.dot.active { background: var(--accent); }
.dot.attention { background: var(--attention); }
.dot.bad { background: var(--bad); }

.pill { font-size: 12px; border-radius: 10px; padding: 1px 8px; background: var(--surface-2); white-space: nowrap; }
.pill.good { color: var(--good); }
.pill.active { color: var(--accent); }
.pill.attention { color: var(--attention); background: var(--attention-bg); }
.pill.bad { color: var(--bad); }

.approval {
  border: 1px solid var(--attention);
  background: var(--attention-bg);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.approval-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.actions { display: flex; gap: 8px; }

pre, code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface-2);
  border-radius: 6px;
  padding: 8px;
  max-height: 420px;
  overflow-y: auto;
}

.command {
  max-height: none;
  direction: ltr;
  unicode-bidi: bidi-override;
}

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 8px max(16px, calc((100% - 848px) / 2));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.composer select { flex: 0 1 180px; width: auto; }
.composer textarea { flex: 1 1 240px; width: auto; }

.tabs { display: flex; gap: 6px; }
.tabs .tab { background: transparent; color: var(--muted); padding: 6px 10px; }
.tabs .tab.on { color: var(--accent); font-weight: 600; background: var(--surface-2); }

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

.me {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  padding: 6px 12px;
  max-width: 85%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.text, .answer { white-space: pre-wrap; overflow-wrap: anywhere; }

.answer { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }

.tool { border-left: 2px solid var(--border); padding-left: 8px; color: var(--muted); overflow-wrap: anywhere; }
.tool summary { cursor: pointer; }
.tool pre { margin-top: 6px; color: var(--text); }

.note { font-size: 13px; overflow-wrap: anywhere; }
.error-line { color: var(--bad); overflow-wrap: anywhere; }

.run-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }

.settings { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.settings dt { color: var(--muted); }
.settings dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.plain { list-style: none; margin: 0; padding: 0; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }

.chip { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 3px 12px; white-space: nowrap; }
.chip.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.log-line { display: block; padding: 7px 0; border-bottom: 1px solid var(--surface-2); overflow-wrap: anywhere; }
.log-line summary { cursor: pointer; }
.log-line .muted, .log-line .who { margin-right: 8px; font-size: 13px; white-space: nowrap; }
.log-line .who { color: var(--accent); }
.log-line pre { margin-top: 6px; }

.start-failure p { margin: 0; }

.login, .start-failure {
  max-width: 340px;
  margin: 0 auto;
  padding: 72px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login h1 { margin: 0 0 8px; font-size: 24px; }
.login label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.form-error { margin: 0; min-height: 1.5em; color: var(--bad); }

.toast {
  position: fixed;
  left: 50%;
  top: calc(60px + env(safe-area-inset-top));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  border-radius: 10px;
  padding: 8px 14px;
  max-width: 90%;
}

@media (max-width: 420px) {
  .stat strong { font-size: 19px; }
  .stat { padding: 6px 8px; }
}
