:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #141a2b;
  --muted: #5d6680;
  --border: #dde2ee;
  --primary: var(--brand-primary, #2f5bea);
  --primary-text: #ffffff;
  --accent: var(--brand-accent, #14b8a6);
  --ok: #15803d;
  --warn: #b45309;
  --err: #b91c1c;
  --mine: var(--brand-primary, #2f5bea);
  --mine-text: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 26, 43, .06), 0 8px 24px rgba(20, 26, 43, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d111c;
    --surface: #151b2b;
    --surface-2: #1c2438;
    --text: #e6e9f2;
    --muted: #97a0b8;
    --border: #2a3350;
    --primary: var(--brand-primary-dark, #7d9bff);
    --primary-text: #0d111c;
    --ok: #4ade80;
    --warn: #fbbf24;
    --err: #f87171;
    --mine: #3b5fd9;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d111c;
  --surface: #151b2b;
  --surface-2: #1c2438;
  --text: #e6e9f2;
  --muted: #97a0b8;
  --border: #2a3350;
  --primary: var(--brand-primary-dark, #7d9bff);
  --primary-text: #0d111c;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --mine: #3b5fd9;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
button, input, textarea, select { font: inherit; color: inherit; }

header.top {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
header.top .brand { display: flex; align-items: center; gap: 10px; color: var(--primary); font-weight: 700; font-size: 18px; }
header.top .brand span { color: var(--text); }
header.top .product { color: var(--muted); font-weight: 500; border-left: 1px solid var(--border); padding-left: 12px; }
header.top .spacer { flex: 1; }
header.top .pill { font-size: 13px; white-space: nowrap; }
@media (max-width: 520px) { header.top .product { display: none; } .chat { height: 440px; } .code { font-size: 36px; } }

main { max-width: 1180px; margin: 0 auto; padding: 24px; display: grid; gap: 20px; }
.grid-2 { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); }
.grid-console { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 860px) { .grid-2, .grid-console { grid-template-columns: 1fr; } main { padding: 16px; } header.top { padding: 12px 16px; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  background: var(--primary); color: var(--primary-text); font-weight: 600;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn.danger { background: transparent; color: var(--err); border-color: var(--border); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.lg { padding: 14px 22px; font-size: 16px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill.err { color: var(--err); }

.steps { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 12px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.steps .n { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 13px; }
.steps li.done .n { background: var(--accent); color: #fff; }
.steps li.active .n { background: var(--primary); color: var(--primary-text); }

.code {
  font: 700 44px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .14em;
  text-align: center; padding: 18px; border-radius: 12px; background: var(--surface-2); margin: 12px 0 6px;
  overflow-wrap: anywhere;
}
.device { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px; border: 1px solid var(--border); border-radius: 12px; margin-top: 10px; }
.device .icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--primary); flex: none; }
.device .icon svg { width: 18px; height: 18px; }
.device .name { font-weight: 600; overflow-wrap: anywhere; }
.device .grow { flex: 1; min-width: 160px; }

label.check { display: flex; gap: 10px; align-items: flex-start; margin: 14px 0; color: var(--muted); font-size: 14px; }
label.check input { margin-top: 4px; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 14px; }
.notice.err { color: var(--err); }

/* chat */
.chat { display: flex; flex-direction: column; height: 520px; }
.chat .messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 2px 12px; }
.msg { max-width: 82%; padding: 8px 12px; border-radius: 14px; background: var(--surface-2); overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 13px; text-align: center; }
.msg .who { display: block; font-size: 11px; font-weight: 700; opacity: .7; margin-bottom: 2px; }
.chat form { display: flex; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.chat input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8, 12, 22, .55); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 22px; max-width: 440px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* console */
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field input, .field select, .write-row input {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); min-width: 0;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.service { border: 1px solid var(--border); border-radius: 12px; margin-top: 10px; overflow: hidden; }
.service > .head { padding: 10px 12px; background: var(--surface-2); display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.service > .head b { font-size: 14px; }
.char { padding: 10px 12px; border-top: 1px solid var(--border); display: grid; gap: 6px; }
.char .line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.char .title { font-weight: 600; font-size: 14px; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.value { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--surface-2); border-radius: 8px; padding: 6px 10px; overflow-wrap: anywhere; }
.value .t { color: var(--muted); }
#writeWhat { white-space: pre-wrap; }
.write-row { display: flex; gap: 6px; flex-wrap: wrap; }
.write-row input { flex: 1; min-width: 140px; }
.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.summary div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.summary .k { font-size: 12px; color: var(--muted); }
.summary .v { font-weight: 600; overflow-wrap: anywhere; }
.log { height: 220px; overflow-y: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.log div { white-space: pre-wrap; overflow-wrap: anywhere; }
.log .err { color: var(--err); }
.log .in { color: var(--ok); }
