:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e3e3df;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --ok: #1a7f37;
  --err: #cf222e;
  --warn: #9a6700;
  --main-bg: #fff1e5;
  --main-text: #bc4c00;
  --code-bg: #fafaf8;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111213;
    --surface: #1a1b1d;
    --text: #e8e8e6;
    --muted: #9a9a96;
    --border: #2c2d30;
    --accent: #4c8dff;
    --accent-text: #0b0b0c;
    --ok: #3fb950;
    --err: #ff7b72;
    --warn: #d29922;
    --main-bg: #3a2414;
    --main-text: #ffa657;
    --code-bg: #141517;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.logo {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.muted { color: var(--muted); font-weight: 400; }

.pill {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}
.pill.on { color: var(--ok); border-color: currentColor; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}

.card h2 { margin: 0 0 16px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.card-head h2 { margin: 0; }

.step {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
}

form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.hint { font-size: 12px; min-height: 18px; }

button {
  font: inherit;
  font-size: 14px;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.secondary { border-color: var(--accent); color: var(--accent); }
button.ghost { background: transparent; }
button.ghost:hover:not(:disabled) { background: var(--bg); }
button.danger { color: var(--err); }

.connected { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  margin-left: 6px;
}
.badge.main { background: var(--main-bg); color: var(--main-text); border-color: transparent; margin-left: 0; }
.badge.warn { color: var(--warn); }
td .badge:only-child { margin-left: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 0 8px 8px; }
td { padding: 10px 8px; border-top: 1px solid var(--border); vertical-align: middle; }
tr.active td { background: var(--bg); }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { padding: 5px 10px; font-size: 13px; }

.notice {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--main-bg);
  color: var(--main-text);
  font-size: 14px;
}

.editor { display: grid; grid-template-columns: 280px 1fr; gap: 12px; min-height: 480px; }
.editor aside { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.editor ul {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  max-height: 520px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
button.file {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 0;
  padding: 6px 10px;
  font: 12.5px/1.4 var(--mono);
  background: transparent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
button.file:hover { background: var(--bg); }
button.file.active { background: var(--accent); color: var(--accent-text); }

.pane { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.pane-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.pane-head code { font: 13px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
textarea {
  flex: 1;
  min-height: 440px;
  resize: vertical;
  font: 12.5px/1.55 var(--mono);
  background: var(--code-bg);
  tab-size: 2;
}

#log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13.5px; }
#log li { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 8px 10px; border-radius: 8px; background: var(--bg); }
#log details { grid-column: 2; }
#log summary { cursor: pointer; color: var(--muted); font-size: 12px; }
#log pre { margin: 6px 0 0; font: 12px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word; }
.log-time { color: var(--muted); font: 12px var(--mono); padding-top: 2px; }
.log-ok .log-msg { color: var(--ok); }
.log-err .log-msg { color: var(--err); }

@media (max-width: 720px) {
  .topbar { padding: 12px 16px; }
  .editor { grid-template-columns: 1fr; }
  .editor ul { max-height: 220px; }
  textarea { min-height: 320px; }
}
