:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1b1f24; --muted: #6b7280; --line: #e3e6ea;
  --accent: #1d4ed8; --accent-ink: #fff; --ok: #15803d; --warn: #b45309; --bad: #b91c1c;
  --chip: #eef2ff; --user: #e8f0fe; --assistant: #f1f3f5; --tool: #fbfbfc;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --panel: #191d23; --ink: #e6e8eb; --muted: #9aa3ad; --line: #2a3038;
    --accent: #3b82f6; --chip: #1e2a44; --user: #1d2a3f; --assistant: #20252c; --tool: #171b21;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
#app, .view { height: 100%; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: .4rem .7rem; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.ghost { background: transparent; }
button.small, .small { font-size: 12px; padding: .2rem .5rem; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
.spacer { flex: 1; }
code.url { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30ch; }

.brand { display: flex; align-items: center; gap: .5rem; font-size: 16px; margin: 0; }
.logo { width: 20px; height: 20px; border-radius: 5px; background: var(--accent); display: inline-block; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem; }

/* login */
#view-login { display: grid; place-items: center; }
.login { width: min(22rem, 92vw); display: grid; gap: .8rem; }
.login label { display: grid; gap: .25rem; font-size: 12px; color: var(--muted); }
.login input { padding: .55rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }

/* topbar */
.topbar { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.badge { font-size: 12px; padding: .15rem .5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.bad { color: var(--bad); border-color: var(--bad); }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.segmented button:last-child { border-right: 0; }
.segmented button.on { background: var(--chip); color: var(--accent); }

/* sites */
.sites { max-width: 60rem; margin: 0 auto; padding: 1.5rem; }
.site-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); }
.site-card { display: grid; gap: .5rem; }
.site-card h3 { margin: 0; }
.site-card .row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* editor */
.editor { display: flex; flex-direction: column; }
.editor-body { flex: 1; display: grid; grid-template-columns: 1fr minmax(20rem, 26rem); min-height: 0; }
.preview-pane { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); }
.preview-toolbar { display: flex; gap: .5rem; align-items: center; padding: .4rem .6rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.frame-wrap { flex: 1; position: relative; display: flex; justify-content: center; background: repeating-linear-gradient(45deg, transparent 0 10px, rgba(0,0,0,.02) 10px 20px); overflow: hidden; }
.frame-wrap iframe { border: 0; height: 100%; width: 100%; background: #fff; transition: width .2s; }
.frame-wrap[data-vp="tablet"] iframe { width: 820px; max-width: 100%; box-shadow: 0 0 0 1px var(--line); }
.frame-wrap[data-vp="mobile"] iframe { width: 390px; max-width: 100%; box-shadow: 0 0 0 1px var(--line); }
.preview-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.25); }
.preview-overlay .card { text-align: center; display: grid; gap: .6rem; }

/* chat */
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.chat.dropping { outline: 2px dashed var(--accent); outline-offset: -4px; }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: .5rem .75rem; border-bottom: 1px solid var(--line); }
.messages { list-style: none; margin: 0; padding: .75rem; flex: 1; overflow: auto; display: grid; gap: .5rem; align-content: start; }
.msg { padding: .5rem .7rem; border-radius: 8px; white-space: pre-wrap; word-break: break-word; }
.msg.user { background: var(--user); margin-left: 2rem; }
.msg.assistant { background: var(--assistant); margin-right: 2rem; }
.msg .time { display: block; font-size: 11px; color: var(--muted); margin-top: .25rem; }
.msg .tools { display: grid; gap: .2rem; margin-top: .4rem; }
.msg details { background: var(--tool); border: 1px solid var(--line); border-radius: 6px; padding: .2rem .5rem; font-size: 12px; }
.msg details pre { margin: .3rem 0 0; white-space: pre-wrap; max-height: 12rem; overflow: auto; }
.msg .status { font-size: 12px; color: var(--muted); font-style: italic; }
.msg .ctx { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .3rem; }
.msg .ctx img { max-height: 80px; border-radius: 4px; border: 1px solid var(--line); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; padding: 0 .75rem; }
.chip { display: inline-flex; gap: .4rem; align-items: center; background: var(--chip); border-radius: 999px; padding: .15rem .3rem .15rem .6rem; font-size: 12px; max-width: 100%; }
.chip img { height: 28px; border-radius: 4px; }
.chip code { font-size: 11px; max-width: 18ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: 0; background: transparent; padding: 0 .3rem; font-size: 14px; line-height: 1; }
.composer { display: grid; gap: .4rem; padding: .6rem .75rem; border-top: 1px solid var(--line); }
.composer textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 6px; padding: .5rem; background: var(--bg); }
.composer-row { display: flex; align-items: center; gap: .5rem; }
.file-btn { display: inline-block; border: 1px solid var(--line); border-radius: 6px; padding: .2rem .5rem; cursor: pointer; }

/* history drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(28rem, 92vw); background: var(--panel); border-left: 1px solid var(--line); padding: .75rem 1rem; overflow: auto; box-shadow: -8px 0 24px rgba(0,0,0,.15); z-index: 10; }
.drawer-head { display: flex; align-items: center; gap: .5rem; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.history-list li { display: grid; grid-template-columns: 1fr auto; gap: .3rem .6rem; align-items: center; padding: .5rem; border: 1px solid var(--line); border-radius: 6px; }
.history-list .meta { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }

/* toast */
.toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .5rem .9rem; border-radius: 8px; max-width: min(40rem, 92vw); z-index: 20; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 900px) {
  .editor-body { grid-template-columns: 1fr; grid-template-rows: 1fr minmax(14rem, 40vh); }
  .preview-pane { border-right: 0; border-bottom: 1px solid var(--line); }
}
