:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --border: #dcdcd6;
  --accent: #c15f3c;
  --accent-text: #ffffff;
  --ok: #2f7d4f;
  --warn: #b7791f;
  --danger: #b42318;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a18;
    --surface: #242422;
    --text: #ecece8;
    --muted: #a3a39c;
    --border: #3a3a36;
    --accent: #d97757;
    --ok: #4caf7a;
    --warn: #e0a640;
    --danger: #f97066;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.bar h1 { font-size: 18px; margin: 0; }
.bar h1 .version { font-size: 12px; font-weight: normal; margin-left: 6px; }
.bar.slim { justify-content: flex-start; padding: 6px 12px; }
.bar a { color: var(--accent); text-decoration: none; }

main { max-width: 900px; margin: 0 auto; padding: 16px; }

.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

button {
  font: inherit;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.5; cursor: default; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  gap: 4px;
}
.card-main { display: flex; align-items: center; gap: 10px; }
.meta { color: var(--muted); font-size: 13px; }
.message { font-size: 13px; }

.badge {
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  color: var(--muted);
}
.status-working { border-left-color: var(--ok); }
.status-working .badge, .badge[data-state="ok"] { color: var(--ok); }
.status-waiting { border-left-color: var(--warn); }
.status-waiting .badge, .badge[data-state="pending"] { color: var(--warn); }
.badge[data-state="error"] { color: var(--danger); }
.status-exited { opacity: 0.7; }

dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  width: min(440px, calc(100vw - 32px));
}
dialog h2 { margin-top: 0; font-size: 17px; }
form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; }
input, select {
  width: 100%;
  min-width: 0;
  font: inherit;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.error { color: var(--danger); margin: 0; }
textarea {
  font: inherit;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 100%;
  resize: vertical;
}
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 12px; }
.section-head h2 { font-size: 16px; margin: 0; }
.prompt-preview { color: var(--muted); white-space: pre-wrap; max-height: 3.2em; overflow: hidden; }

.login { max-width: 320px; margin: 15vh auto; padding: 0 16px; }

.term-page { height: 100vh; display: flex; flex-direction: column; background: #000; }
.term-page .bar { gap: 14px; position: relative; }
.term-page .bar button { padding: 2px 10px; }
.hint { margin-left: auto; }
.links-panel {
  position: absolute;
  top: 100%;
  right: 12px;
  z-index: 10;
  width: min(720px, calc(100vw - 24px));
  max-height: 50vh;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.links-panel[hidden] { display: none; }
.links-panel div { display: flex; gap: 8px; align-items: flex-start; }
.links-panel a { color: var(--accent); word-break: break-all; flex: 1; }
.links-panel p { margin: 0; }
.files-panel { max-height: 70vh; }
.files-header { display: flex; align-items: center; gap: 8px; }
.files-header strong { flex: 1; word-break: break-all; }
.links-panel .file-row { display: grid; grid-template-columns: 64px 1fr auto auto; gap: 10px; align-items: center; }
.file-row img { max-width: 64px; max-height: 48px; border-radius: 4px; background: #fff; }
.file-row a { color: var(--accent); word-break: break-all; }
#terminal { flex: 1; min-height: 0; padding: 4px; }
