:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --accent: #2b5ae0;
  --accent-strong: #1f47bf;
  --accent-soft: #e6edfd;
  --accent-text: #1f47bf;
  --bg: #f3f3f3;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --surface-3: #ebebeb;
  --hover: #e8e8e8;
  --pressed: #dcdcdc;
  --border: #d4d4d4;
  --border-soft: #e5e5e5;
  --text: #1f1f1f;
  --text-2: #5c5c5c;
  --text-3: #8a8a8a;
  --danger: #c42b1c;
  --danger-soft: #fde7e9;
  --warn-soft: #fff4ce;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.14), 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --radius-sm: 4px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --accent: #6b8cff;
  --accent-strong: #8aa5ff;
  --accent-soft: #1f2a4d;
  --accent-text: #9db4ff;
  --bg: #1f1f1f;
  --surface: #292929;
  --surface-2: #2f2f2f;
  --surface-3: #383838;
  --hover: #3a3a3a;
  --pressed: #454545;
  --border: #4a4a4a;
  --border-soft: #3a3a3a;
  --text: #f0f0f0;
  --text-2: #c2c2c2;
  --text-3: #9a9a9a;
  --danger: #ff7b72;
  --danger-soft: #4a2020;
  --warn-soft: #4a3f12;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #6b8cff;
    --accent-strong: #8aa5ff;
    --accent-soft: #1f2a4d;
    --accent-text: #9db4ff;
    --bg: #1f1f1f;
    --surface: #292929;
    --surface-2: #2f2f2f;
    --surface-3: #383838;
    --hover: #3a3a3a;
    --pressed: #454545;
    --border: #4a4a4a;
    --border-soft: #3a3a3a;
    --text: #f0f0f0;
    --text-2: #c2c2c2;
    --text-3: #9a9a9a;
    --danger: #ff7b72;
    --danger-soft: #4a2020;
    --warn-soft: #4a3f12;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.4 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }
svg.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--pressed); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn:disabled { opacity: 0.5; cursor: default; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; color: var(--text-2); font-weight: 500; }
.input, select.input, textarea.input {
  height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); min-width: 0;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); width: 440px; max-width: 100%;
  max-height: calc(100vh - 32px); display: flex; flex-direction: column; border: 1px solid var(--border-soft);
}
.modal.wide { width: 640px; }
.modal.xwide { width: 820px; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 6px; font-size: 16px; font-weight: 600; }
.modal .body { padding: 8px 18px; overflow: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; }
.icon-btn { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: none; background: transparent; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-2); }
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* menus */
.menu {
  position: fixed; z-index: 1100; min-width: 200px; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; max-height: 70vh; overflow: auto;
}
.menu .mi { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; border: none; background: none; width: 100%; text-align: left; }
.menu .mi:hover, .menu .mi.active { background: var(--hover); }
.menu .mi .kbd { margin-left: auto; color: var(--text-3); font-size: 12px; padding-left: 20px; }
.menu .mi.disabled { opacity: 0.45; pointer-events: none; }
.menu .sep { height: 1px; background: var(--border-soft); margin: 4px 2px; }
.menu .mh { font-size: 11px; font-weight: 600; color: var(--text-3); padding: 6px 10px 2px; text-transform: uppercase; letter-spacing: 0.03em; }
.menu .swatches { display: grid; grid-template-columns: repeat(10, 18px); gap: 3px; padding: 6px 8px; }
.menu .swatches button { width: 18px; height: 18px; border: 1px solid rgba(0, 0, 0, 0.15); border-radius: 2px; cursor: pointer; padding: 0; }
.menu .swatches button:hover { outline: 2px solid var(--accent); }

/* toasts */
.toasts { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); z-index: 1200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #2b2b2b; color: #fff; padding: 9px 16px; border-radius: 6px; box-shadow: var(--shadow); font-size: 13px; max-width: 520px; pointer-events: auto; }
.toast.error { background: #a4262c; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; text-decoration: none; color: inherit; }
.brand-mark { width: 26px; height: 26px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; color: #fff; flex: none; }
.brand-mark svg { width: 16px; height: 16px; stroke: #fff; fill: none; stroke-width: 1.8; }

.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-size: 12px; font-weight: 600; flex: none; }

/* Connect an AI assistant (tokens) */
.tokens h4 { margin: 18px 0 8px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.token-form { display: grid; grid-template-columns: 1.4fr 1fr 0.8fr auto; gap: 0 10px; align-items: end; }
.token-form .field { margin-bottom: 0; }
.token-form .btn { height: 32px; }
.code-wrap { position: relative; }
.code-wrap pre.code { margin: 0; padding: 10px 84px 10px 12px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); font: 12.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; max-height: 220px; overflow: auto; }
.code-wrap .sm-btn { position: absolute; top: 6px; right: 6px; height: 26px; padding: 0 8px; font-size: 12px; }
.code-wrap .sm-btn svg { width: 14px; height: 14px; }
.token-created { margin-top: 14px; display: grid; gap: 8px; }
.token-created h4 { margin: 8px 0 0; }
.token-created p { margin: 0; }
.notice { background: var(--warn-soft); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; }
.token-row { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.token-row.expired { opacity: .6; }
.token-row code { font: 12px var(--mono); }
.token-row .grow { flex: 1; min-width: 0; }
@media (max-width: 640px) { .token-form { grid-template-columns: 1fr 1fr; gap: 8px 10px; } }
