:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #5d6877;
  --line: #dde2e8;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --user: #e8f0fe;
  --ai: #ffffff;
  --note: #f1f3f5;
  --good: #1a7f37;
  --bad: #c62828;
  --warn: #9a6700;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --panel: #171d24;
    --text: #e6eaef;
    --muted: #9aa6b4;
    --line: #2a333d;
    --accent: #4c8dff;
    --accent-text: #0b1220;
    --user: #1c2a40;
    --ai: #1b222a;
    --note: #1d242c;
    --good: #3fb950;
    --bad: #ff7b72;
    --warn: #d29922;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419;
  --panel: #171d24;
  --text: #e6eaef;
  --muted: #9aa6b4;
  --line: #2a333d;
  --accent: #4c8dff;
  --accent-text: #0b1220;
  --user: #1c2a40;
  --ai: #1b222a;
  --note: #1d242c;
  --good: #3fb950;
  --bad: #ff7b72;
  --warn: #d29922;
  color-scheme: dark;
}
.theme-pick { display: inline-flex; }
.theme-pick button { padding: 3px 8px; font-size: 12px; border-radius: 0; }
.theme-pick button:first-child { border-radius: 6px 0 0 6px; }
.theme-pick button:last-child { border-radius: 0 6px 6px 0; }
.theme-pick button + button { border-left: 0; }
.theme-pick button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, textarea, select {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 10px; width: 100%;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); min-height: 1.2em; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px 24px;
}
.card h1 { font-size: 22px; margin: 0 0 8px; display: flex; align-items: center; gap: 10px; }
.logo { width: 28px; height: 28px; }
.card form { display: grid; gap: 10px; margin-top: 16px; }
.card label { font-weight: 600; font-size: 14px; }
#code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .12em; text-transform: uppercase; }
.langs { display: flex; gap: 6px; margin-top: 16px; }
.langs button { padding: 3px 8px; font-size: 12px; }

/* app */
.app { height: 100%; display: flex; flex-direction: column; }
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.site { display: flex; flex-direction: column; min-width: 0; flex: 1 1 220px; }
.site select { font-weight: 600; border: 0; padding: 2px 0; background: none; width: auto; max-width: 100%; align-self: flex-start; }
.site a { color: var(--muted); }
.usage {
  font-size: 13px; padding: 5px 10px; border-radius: 999px; background: var(--note); white-space: nowrap;
}
.usage.low { color: var(--warn); }
.usage.out { color: var(--bad); font-weight: 600; }
.actions { display: flex; gap: 8px; align-items: center; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; }
.menu summary::-webkit-details-marker { display: none; }
.menu-body a { color: var(--accent); }
.menu-body {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 5; min-width: 220px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 10px;
}
.status { padding: 0 16px; font-size: 14px; min-height: 0; }
.status:not(:empty) { padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.status.good { color: var(--good); }
.status.bad { color: var(--bad); }

.tabs { display: none; }
.panes { flex: 1; display: grid; grid-template-columns: 3fr minmax(340px, 2fr); min-height: 0; }
.panes .preview { order: 1; }
.panes .chat { order: 2; }
.chat { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { border-radius: var(--radius); padding: 10px 12px; max-width: 92%; border: 1px solid var(--line); }
.msg.user { background: var(--user); align-self: flex-end; border-color: transparent; }
.msg.ai { background: var(--ai); align-self: flex-start; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg .ver { opacity: .8; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.note { align-self: center; font-size: 13px; color: var(--muted); background: var(--note); border-radius: 999px; padding: 4px 12px; text-align: center; max-width: 95%; }
.note.bad { color: var(--bad); }
.working { padding: 6px 16px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }
.composer { padding: 12px 16px 16px; border-top: 1px solid var(--line); background: var(--panel); display: grid; gap: 8px; }
.composer textarea { resize: vertical; min-height: 70px; }
.composer-row { display: flex; align-items: center; gap: 10px; }
.composer-row .muted { flex: 1; }
.photo-btn { border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.photo-btn:hover { border-color: var(--accent); }

.preview { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.preview-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.preview-bar select { width: auto; max-width: 220px; }
.preview-bar a { color: var(--accent); font-size: 14px; margin-left: auto; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; border-left: 0; }
.seg button.on, .tabs button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.frame-wrap { flex: 1; display: flex; justify-content: center; padding: 12px; min-height: 0; overflow: hidden; position: relative; }
/* desktop: the site is drawn at a real desktop width and scaled into the panel (app.js layoutFrame) */
.frame-wrap:not(.phone) iframe { position: absolute; top: 12px; left: 12px; transform-origin: 0 0; }
.frame-wrap iframe { width: 100%; height: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.frame-wrap.phone iframe { width: 390px; max-width: 100%; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); max-width: 480px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
#dlg-list { max-height: 200px; overflow: auto; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
#dlg-list:empty { display: none; }
.dlg-row { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 900px) {
  .tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--panel); }
  .tabs button { flex: 1; border: 0; border-radius: 0; padding: 10px; }
  .panes { grid-template-columns: 1fr; }
  .chat { border-left: 0; }
  .app:not([data-tab="preview"]) .preview { display: none; }
  .app[data-tab="preview"] .chat { display: none; }
  .actions button { padding: 6px 9px; }
  .top { padding: 8px 12px; }
  .usage { order: 3; }
}

#share-dlg h3 { margin: 0 0 6px; }
#share-dlg h4 { margin: 16px 0 6px; font-size: 14px; }
.share-row { display: flex; gap: 8px; }
.share-row input { flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.share-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; font-size: 13px; }
.share-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.share-list button { padding: 3px 8px; font-size: 12px; }
#zoom { width: auto; }
