/* Local Agent: colors and type scale are inlined from the shared design tokens;
   values are inlined so the kit runs outside the repo. Light theme only. */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --raised: #faf9f6;
  --ink: #232322;
  --muted: #6e6c66;
  --line: #e2e0db;
  --accent: #0c7ac4;
  --accent-deep: #0a6baa;
  --accent-tint: #e8f2fa;
  --positive: #157f43;
  --warning: #9a6400;
  --warning-tint: #fdf6e7;
  --warning-line: #f1dfb8;
  --negative: #c5303f;
  --negative-tint: #fcecee;
  --negative-line: #efc2c7;
  --negative-ink: #8f1d2a;
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 50px rgba(0, 0, 0, 0.18);
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;
  --side-w: 248px;
  --content-w: 760px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 "PingFang TC", "Hiragino Sans", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
:lang(zh-Hant) { font-family: "PingFang TC", "Hiragino Sans", -apple-system, BlinkMacSystemFont, system-ui, sans-serif; }
:lang(ja) { font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "PingFang TC", -apple-system, BlinkMacSystemFont, system-ui, sans-serif; }
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }

/* ── Header ─────────────────────────────────────── */
.top {
  flex: none;
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; grid-column: 2; }
.top .drawer-btn { display: none; grid-column: 1; }
.seg {
  grid-column: 3;
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
}
.seg button {
  border: 0;
  background: transparent;
  padding: 5px 16px;
  border-radius: var(--r-pill);
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.top-right { grid-column: 4; justify-self: end; display: flex; align-items: center; gap: 6px; }
.status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--positive); }
.status.warn .dot { background: var(--warning); }
.status.down .dot { background: var(--negative); }
html[data-deploy="hosted"] .status.boot .dot { background: var(--warning); animation: boot-pulse 1.7s ease-in-out infinite; }
@keyframes boot-pulse { 50% { opacity: .3; transform: scale(.7); } }
.icon-btn {
  width: 36px; height: 36px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: var(--r-sm);
  background: transparent;
}
.icon-btn:hover { background: var(--bg); }
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.8; fill: currentColor; stroke-linecap: round; }
.drawer-btn svg, .lang-btn svg { fill: none; }

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  z-index: 30;
  min-width: 140px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.more-menu, .lang-menu { right: 0; top: 40px; }
.chat-menu { position: fixed; z-index: 45; }   /* above the drawer (40) and its scrim (35) */
.menu button {
  display: block; width: 100%;
  text-align: left;
  border: 0; background: transparent;
  padding: 8px 12px; border-radius: var(--r-sm);
}
.menu button:hover { background: var(--bg); }
.lang-menu { min-width: 170px; }
.lang-menu button { display: flex; align-items: center; gap: 16px; }
.lang-menu button[aria-checked="true"] { color: var(--accent-deep); font-weight: 600; }
.lang-check { margin-left: auto; visibility: hidden; color: var(--accent); }
.lang-menu button[aria-checked="true"] .lang-check { visibility: visible; }
.danger-text { color: var(--negative); }

/* ── Layout ─────────────────────────────────────── */
.layout { flex: 1; display: flex; min-height: 0; }
.side {
  flex: none;
  width: var(--side-w);
  display: flex; flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--raised);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
body[data-mode="image"] .side { display: none; }
.new-chat {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
}
.new-chat:hover { border-color: var(--accent); color: var(--accent); }
.chat-list { display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex; align-items: center; gap: 4px;
  border-radius: var(--r-sm);
}
.chat-item > .open {
  flex: 1; min-width: 0;
  border: 0; background: transparent;
  text-align: left;
  padding: 8px 10px; border-radius: var(--r-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item .item-more { visibility: hidden; width: 28px; height: 28px; }
.chat-item:hover .item-more, .chat-item.current .item-more, .chat-item:focus-within .item-more { visibility: visible; }
@media (hover: none) { .chat-item .item-more { visibility: visible; } }
.chat-item:hover { background: var(--bg); }
.chat-item.current { background: var(--accent-tint); }
.chat-item.current > .open { color: var(--accent-deep); font-weight: 600; }
.chat-item input { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid var(--accent); border-radius: var(--r-sm); }
.side-empty { color: var(--muted); font-size: 13px; padding: 4px 10px; margin: 0; }
.scrim { display: none; }

main { flex: 1; min-width: 0; display: flex; }
.view { flex: 1; min-width: 0; display: none; flex-direction: column; }
body[data-mode="chat"] .chat-view, body[data-mode="image"] .image-view { display: flex; }
.scroll { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.thread { max-width: var(--content-w); margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

/* ── Composer ───────────────────────────────────── */
.composer { flex: none; padding: 8px 16px 16px; }
.composer > * { max-width: var(--content-w); margin-left: auto; margin-right: auto; }
.box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 10px 10px 10px 14px;
  box-shadow: var(--shadow-sm);
}
.box:focus-within { border-color: var(--accent); }
.box textarea {
  width: 100%;
  border: 0; outline: 0; resize: none;
  background: transparent;
  max-height: 200px;
  padding: 2px 0;
}
.box-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.primary {
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: var(--r-pill);
}
.primary:hover:not(:disabled) { background: var(--accent-deep); }
.primary.stop { background: var(--ink); }
.ghost { border: 1px solid var(--line); background: var(--surface); padding: 6px 14px; border-radius: var(--r-pill); color: var(--muted); }
.ghost:hover { color: var(--ink); border-color: var(--muted); }

.think, .aspects { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.think-label { font-size: 13px; color: var(--muted); margin-right: 2px; }
.think button, .aspects button, .chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-pill);
  padding: 3px 12px;
  font-size: 13px;
  color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
}
.think button[aria-checked="true"], .aspects button[aria-checked="true"] {
  border-color: var(--accent); color: var(--accent-deep); background: var(--accent-tint); font-weight: 600;
}
.shape { display: inline-block; border: 1.5px solid currentColor; border-radius: 2px; }
.shape.sq { width: 12px; height: 12px; }
.shape.ls { width: 14px; height: 10px; }
.shape.pt { width: 10px; height: 14px; }
.notice, .warn-note {
  font-size: 13px;
  color: var(--warning);
  background: var(--warning-tint);
  border: 1px solid var(--warning-line);
  border-radius: var(--r-md);
  padding: 6px 10px;
}
.notice { padding: 6px 12px; margin-bottom: 8px; }
.hint {
  display: block;
  margin-top: 6px;
  border: 0; background: transparent;
  color: var(--accent);
  font-size: 13px;
  padding: 2px 4px;
}

/* ── Messages ───────────────────────────────────── */
.msg { display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-items: flex-end; }
.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--r-lg);
  overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--accent-tint); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.agent .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; max-width: 100%; }
.msg.agent .bubble:empty { display: none; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md pre { margin: 0 0 .6em; }
.md ul, .md ol { padding-left: 1.4em; }
.md pre { position: relative; background: var(--bg); border-radius: var(--r-sm); padding: 10px 12px; overflow-x: auto; font-size: 13px; }
.code-copy {
  position: absolute; top: 6px; right: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 6px; padding: 0 8px; font-size: 12px; line-height: 20px; opacity: .75;
}
.code-copy:hover, .code-copy:focus-visible { opacity: 1; color: var(--ink); }
.md code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .92em; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md a { color: var(--accent); }
.md .h { font-weight: 700; margin: .4em 0 .3em; }
.waiting { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.waiting .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.waiting-note { color: var(--muted); font-size: 12px; }
.tools { display: flex; flex-direction: column; gap: 2px; }
.tool { font-size: 12px; color: var(--muted); }
.warns { display: flex; flex-direction: column; gap: 4px; }
.warns:empty { display: none; }
.tool.failed { color: var(--negative); }
.msg-actions { display: flex; gap: 8px; }
.link-btn { border: 0; background: transparent; color: var(--accent); font-size: 13px; padding: 2px 0; }
.link-btn:hover { text-decoration: underline; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 12px 14px;
}
.approvals { display: flex; flex-direction: column; gap: 8px; }
.approvals:empty { display: none; }
.card.approval { border-color: var(--warning); background: #fffaf0; }
.card.approval h3 { margin: 0 0 4px; font-size: 14px; }
.card.approval .warn { color: var(--negative); font-weight: 600; font-size: 13px; margin-top: 6px; }
.card.approval details { margin: 6px 0; font-size: 13px; }
.card.approval pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px; margin: 6px 0 0; font-size: 12px; }
.card .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.card.error { border-color: var(--negative-line); background: var(--negative-tint); color: var(--negative-ink); }
.card.done-note { color: var(--muted); font-size: 13px; padding: 8px 12px; }
/* Only hosted uses the temporary boot card; the local app's empty thread stays unchanged. */
html[data-deploy="hosted"] .boot-card {
  align-self: center; width: min(100%, 460px); margin: min(14vh, 90px) auto 0;
  padding: 32px; text-align: center; box-shadow: var(--shadow-sm);
}
.boot-mark { display: block; width: 15px; height: 15px; margin: 0 auto 18px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 6px var(--warning-tint); animation: boot-pulse 1.7s ease-in-out infinite; }
.boot-card h2 { margin: 0; font-size: 20px; line-height: 1.4; }
.boot-description { color: var(--muted); font-size: 14px; line-height: 1.75; margin: 16px 0 0; }
.boot-elapsed { color: var(--warning); font-size: 12px; margin: 18px 0 0; font-variant-numeric: tabular-nums; }
.boot-progress { height: 4px; border-radius: var(--r-pill); background: var(--warning-tint); overflow: hidden; margin: 24px 0 0; }
.boot-progress i { display: block; width: 38%; height: 100%; border-radius: inherit; background: var(--warning); animation: boot-travel 1.8s ease-in-out infinite; }
@keyframes boot-travel { from { transform: translateX(-110%); } to { transform: translateX(270%); } }

/* ── Images ─────────────────────────────────────── */
.image-items { display: flex; flex-direction: column; gap: 16px; }
.older { align-self: center; }
.img-card { align-self: flex-start; width: min(100%, 380px); padding: 8px; }
.img-card.landscape { width: min(100%, 440px); }
.img-card.portrait { width: min(100%, 300px); }
.img-card .frame { position: relative; border-radius: var(--r-md); overflow: hidden; background: var(--bg); }
.img-card .frame img { display: block; width: 100%; height: auto; cursor: zoom-in; }
.img-card .frame img:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.skeleton .acts { padding-top: 6px; }
.img-card .meta { font-size: 12px; color: var(--muted); padding: 6px 4px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tag { border: 1px solid var(--line); border-radius: var(--r-pill); padding: 0 8px; }
.img-card .acts { display: flex; gap: 12px; padding: 4px 4px 2px; flex-wrap: wrap; }
.img-card .acts a, .img-card .acts button { font-size: 13px; color: var(--accent); background: none; border: 0; padding: 0; text-decoration: none; }
.img-card .acts a:hover, .img-card .acts button:hover { text-decoration: underline; }
.skeleton .frame {
  aspect-ratio: 1 / 1;
  background: linear-gradient(100deg, #eeece7 30%, #f8f7f4 50%, #eeece7 70%);
  background-size: 300% 100%;
  animation: shimmer 1.6s steps(24) infinite;
}
.skeleton.landscape .frame { aspect-ratio: 4 / 3; }
.skeleton.portrait .frame { aspect-ratio: 3 / 4; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.progress { height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; margin: 8px 4px 0; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .9s linear; }
.wait-bar { max-width: 320px; margin: 0 0 0 16px; }

/* ── Disk space ─────────────────────────────────── */
.disk-banner {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 12px;
  padding: 6px 16px; font-size: 13px;
  color: var(--warning); background: var(--warning-tint); border-bottom: 1px solid var(--warning-line);
}
.disk-banner.severe { color: var(--negative-ink); background: var(--negative-tint); border-bottom-color: var(--negative-line); }
.disk-banner .link-btn { font-weight: 600; }
.examples { text-align: center; color: var(--muted); padding: 32px 0; }
.examples .chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ── Hosted trial: markup is tagged local-only / hosted-only and <html data-deploy> chooses ── */
html[data-deploy="hosted"] .local-only,
html:not([data-deploy="hosted"]) .hosted-only { display: none !important; }
.trial-banner {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 12px;
  padding: 6px 16px; font-size: 13px;
  color: var(--accent-deep); background: var(--accent-tint); border-bottom: 1px solid #cfe3f3;
}
.trial-ends { font-weight: 600; }
.usage { font-size: 12px; color: var(--muted); margin-top: 6px; margin-bottom: 0; padding: 0 4px; }
.usage:empty { display: none; }

/* ── Dialogs ────────────────────────────────────── */
dialog { border: 0; border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 20px 22px; max-width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(35, 35, 34, .45); }
.help-dialog h2, .storage-dialog h2 { margin: 0 0 8px; font-size: 18px; }
.help-dialog form { text-align: right; margin-top: 12px; }
.storage-dialog { width: min(440px, calc(100vw - 32px)); }
.storage-dialog .progress { margin: 4px 0 12px; height: 6px; border-radius: 3px; }
.storage-cats { list-style: none; margin: 0 0 12px; padding: 0; }
.storage-cats li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.storage-dialog p { font-size: 13px; margin: 0 0 8px; }
.storage-result { color: var(--positive); }
.dialog-row { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 12px; }
.dialog-row form { margin: 0; }
.lightbox { padding: 0; background: transparent; box-shadow: none; max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); }
.lightbox img { display: block; max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); border-radius: var(--r-md); }
.lightbox .close { position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,.9); }

/* ── Narrow screens (<768px): icon-only tabs, drawer sidebar, wrapped controls ── */
@media (max-width: 767px) {
  .top { grid-template-columns: auto auto 1fr auto; gap: 8px; padding: 0 8px; }
  .brand span { display: none; }
  .seg { grid-column: 3; justify-self: center; }
  .seg button { padding: 5px 14px; }
  .seg-label { display: none; }
  .status-text { display: none; }
  body[data-mode="chat"] .top .drawer-btn { display: inline-grid; }
  .side {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0;
    width: min(84vw, 300px);
    transform: translateX(-105%);
    visibility: hidden;   /* keep closed drawer out of the tab order */
    transition: transform .2s ease, visibility 0s linear .2s;
    box-shadow: var(--shadow-lg);
  }
  body.drawer-open .side { transform: none; visibility: visible; transition: transform .2s ease; }
  body.drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(35, 35, 34, .35); }
  .scroll { padding: 16px 12px 8px; }
  .composer { padding: 6px 12px 12px; }
  .bubble { max-width: 92%; }
  .box-row { align-items: flex-start; }
  .box-row .primary { margin-left: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton .frame, .waiting .pulse, .status.boot .dot, .boot-mark, .boot-progress i { animation: none; }
  .side, .progress > i { transition: none; }
}
