:root {
  color-scheme: light dark;
  --surface: #fff; --sidebar: #f7f7f8; --text: #202123; --muted: #666870;
  --line: #e3e4e8; --soft: #f0f1f4; --accent: #275e53; --on-accent: #fff;
  font: 15px/1.6 system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface: #212121; --sidebar: #191919; --text: #ececec; --muted: #aaa;
    --line: #3d3d3d; --soft: #303030; --accent: #a0ded0; --on-accent: #132925;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100dvh; display: flex; overflow: hidden; background: var(--surface); color: var(--text); }
button, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button { border: 0; background: none; border-radius: 10px; }
button:hover, select:hover { background: var(--soft); }
button:disabled { opacity: .5; cursor: default; }
a { color: var(--accent); }
#sidebar { width: 246px; flex-shrink: 0; display: flex; flex-direction: column; padding: 20px 14px 12px; background: var(--sidebar); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; padding: 0 6px; }
.mark { display: inline-grid; place-items: center; background: var(--accent); color: var(--on-accent); width: 29px; height: 29px; border-radius: 9px; flex: none; }
.new-chat { text-align: left; padding: 9px 11px; border: 1px solid var(--line); margin-top: 24px; }
.history-label, footer { color: var(--muted); font-size: .82rem; padding: 0 9px; }
.history-label { margin: 24px 0 7px; }
#history { overflow-y: auto; flex: 1; }
#history button { display: block; text-align: left; width: 100%; padding: 7px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#history [aria-current] { background: var(--soft); font-weight: 600; }
footer { margin-top: 12px; }
.online { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--accent); }
main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 7px; padding: 10px 17px; min-height: 56px; }
.topbar select { max-width: min(54vw, 350px); font-weight: 650; }
select { background: var(--surface); border: 0; border-radius: 8px; padding: 5px 8px; }
#toggle-sidebar { padding: 4px 9px; font-size: 1.2rem; }
.local-badge { margin-left: auto; font-size: .77rem; color: var(--muted); }
.conversation-viewport { position: relative; display: flex; flex: 1; min-height: 0; }
#jump-bottom { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); font-size: 1.2rem; box-shadow: 0 2px 8px #0002; }
#scroll { flex: 1; overflow-anchor: none; min-height: 0; overflow-y: auto; padding: 0 20px; }
.thread { max-width: 760px; margin: auto; min-height: 100%; display: flex; flex-direction: column; }
#welcome { margin: auto 0; text-align: center; padding: 30px 0; }
.hero-mark { width: 46px; height: 46px; font-size: 1.5rem; border-radius: 14px; }
h1 { margin: 12px 0 2px; font-size: clamp(1.7rem, 5vw, 2.3rem); letter-spacing: -.04em; }
#welcome p { margin: 0 0 20px; color: var(--muted); }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.suggestions button, .artifacts a { border: 1px solid var(--line); padding: 5px 10px; border-radius: 10px; }
#messages { display: grid; gap: 22px; }
#messages:not(:empty) { padding: 22px 0; }
.turn { display: grid; gap: 14px; }
.user { justify-self: end; max-width: 85%; border-radius: 19px; background: var(--soft); padding: 9px 14px; }
.answer { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.answer-body { min-width: 0; flex: 1; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.meta { font-size: .82rem; color: var(--muted); margin: 0; }
.thinking { margin: 6px 0; padding-inline-start: 10px; border-inline-start: 2px solid var(--line); color: var(--muted); font-size: .9rem; }
.thinking summary { cursor: pointer; }
.artifacts { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.artifacts a { text-decoration: none; font-size: .86rem; overflow-wrap: anywhere; }
.answer img { display: block; max-width: min(100%, 512px); height: auto; border-radius: 12px; margin: 8px 0; }
.answer audio { max-width: 100%; margin-top: 8px; }
.archive { margin-top: 8px; border: 1px solid var(--line); padding: 4px 8px; }
.compose-area { padding: 8px 20px 9px; }
#task { max-width: 760px; margin: auto; border: 1px solid var(--line); border-radius: 24px; padding: 10px 11px; box-shadow: 0 3px 18px #0000000a; }
textarea { display: block; width: 100%; resize: none; border: 0; outline: 0; background: transparent; min-height: 38px; padding: 6px 8px; max-height: 175px; }
#task:focus-within { border-color: var(--muted); }
.tools { display: flex; align-items: center; gap: 6px; }
.chat-options { display: flex; flex-wrap: wrap; gap: 4px 10px; color: var(--muted); font-size: .85rem; }
.chat-options label { display: inline-flex; align-items: center; white-space: nowrap; cursor: pointer; }
.chat-options input { accent-color: var(--accent); }
#attach, #send { width: 35px; height: 35px; font-size: 1.25rem; border-radius: 50%; border: 1px solid var(--line); padding: 0; }
#send { margin-left: auto; background: var(--accent); color: var(--on-accent); border: 0; }
#attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachment-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 10px; }
.attachment-chip span { min-width: 0; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-thumbnail { width: 44px; height: 44px; flex: none; border-radius: 6px; background: var(--soft); }
#attachments .attachment-chip button { border: 0; }

#attachments button { border: 1px solid var(--line); padding: 3px 8px; overflow-wrap: anywhere; max-width: 100%; }
#notice { text-align: center; color: var(--muted); font-size: .75rem; margin: 7px 0 0; min-height: 1.2em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (min-width: 701px) { body.sidebar-hidden #sidebar { display: none; } }
@media (max-width: 700px) {
  #sidebar { display: none; position: fixed; inset: 56px auto 0 0; z-index: 1; box-shadow: 8px 0 24px #0002; }
  body.sidebar-open #sidebar { display: flex; }
  .topbar { padding: 9px 10px; }
  #scroll, .compose-area { padding-inline: 12px; }
}

.access { position:fixed; inset:0; z-index:5; display:grid; place-items:center; background:var(--surface); padding:20px; }
.access-card { width:min(100%,420px); border:1px solid var(--line); border-radius:18px; padding:24px; }
.access input { display:block; width:100%; margin:5px 0 14px; padding:8px; font:inherit; border:1px solid var(--line); border-radius:8px; }
.access button { padding:6px 12px; background:var(--accent); color:var(--on-accent); }
@media (max-width:700px) {
  .topbar { padding-top:max(8px, env(safe-area-inset-top)); }
  .topbar select { max-width:100%; font-size:16px; text-overflow:ellipsis; }
  .topbar label { min-width:0; flex:1; }
  .topbar a,.topbar button { flex-shrink:0; }
  #toggle-sidebar,#logout,#portal-home { min-height:44px; display:inline-grid; align-items:center; padding-inline:7px; }
  #sidebar { inset:calc(56px + env(safe-area-inset-top)) auto env(safe-area-inset-bottom) 0; }
  #new-chat,#history button { min-height:44px; }
  .compose-area { padding-bottom:max(9px, env(safe-area-inset-bottom)); }
  #task { border-radius:18px; padding:7px; }
  textarea, select,.access input { font-size:16px; }
  #attach,#send { width:44px; height:44px; flex-shrink:0; }
  .tools { flex-wrap:wrap; gap:4px; }
  .tools select { max-width:34vw; padding-inline:3px; }
  #notice { margin-top:4px; }
  .suggestions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); max-width:320px; margin:auto; }
  .suggestions button { min-height:44px; }
  .access { overflow:auto; padding-bottom:max(20px,env(safe-area-inset-bottom)); }
  .access button { min-height:44px; }
}

.access-link { display:inline-block; padding:9px 12px; border-radius:9px; background:var(--accent); color:var(--on-accent); text-decoration:none; }

#account-link { display:inline-block; max-width:min(24vw,180px); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

html.chat-keyboard { overflow: hidden; }
.chat-keyboard body {
  position: fixed;
  inset: 0 0 auto;
  height: var(--chat-viewport-height);
  transform: translateY(var(--chat-viewport-top));
}
.chat-keyboard .compose-area { flex: none; padding-bottom: 9px; }
.chat-keyboard #prompt { max-height: min(175px, calc(var(--chat-viewport-height) * .35)); }
.chat-keyboard #sidebar { bottom: 0; }
@media (max-width: 700px) {
  html, body { overscroll-behavior: none; }
  #scroll { overscroll-behavior: contain; }
}

#history-filter { width: 100%; margin-bottom: 6px; border: 1px solid var(--line); }
.conversation-row { --menu-toggle: 32px; display: grid; grid-template-columns: minmax(0, 1fr) var(--menu-toggle); align-items: start; }
.conversation-menu summary {
  display: grid;
  place-items: center;
  min-height: 36px;
  border-radius: 10px;
  list-style: none;
  cursor: pointer;
}
.conversation-menu summary::-webkit-details-marker { display: none; }
.conversation-menu summary:hover, .conversation-menu[open] summary { background: var(--soft); }
.conversation-actions {
  width: 150px;
  margin: 3px 0 6px calc(var(--menu-toggle) - 150px);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
#history .conversation-actions button { white-space: normal; }
@media (max-width: 700px) {
  .conversation-row { --menu-toggle: 44px; }
  .conversation-menu summary, #history-filter { min-height: 44px; }
}
.artifacts .artifact-action { border:1px solid var(--line); padding:5px 10px; font-size:.86rem; }

#edit-preview { display: block; max-width: 100%; max-height: 260px; touch-action: none; cursor: crosshair; }

.message video, video { max-width: 100%; }

.job-timer { font-variant-numeric: tabular-nums; white-space: nowrap; }

.project-folder { margin-left: .65rem; }
.project-folder > summary { cursor: pointer; padding: .35rem .4rem; }
.chat-status { display: inline-block; width: .7rem; height: .7rem; margin-right: .4rem; vertical-align: middle; border-radius: 50%; }
.chat-status.running { border: 2px solid currentColor; border-right-color: transparent; animation: chat-spin .8s linear infinite; }
.chat-status.unread { background: #438bf5; }
@keyframes chat-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .chat-status.running { animation: none; } }
#skill-dialog { width: min(36rem, 90vw); }
#skill-dialog textarea { display: block; width: 100%; margin: .5rem 0; }
.project-skill { margin: .25rem .4rem; }

#user-skills-dialog { width: min(42rem, 90vw); }
#user-skill-list { padding-left: 1.25rem; }
.user-skill-row { padding: .35rem 0; }
.user-skill-row button { margin-left: .35rem; }

.job-failure { margin: .45rem 0; padding: .5rem .65rem; border-left: 3px solid #d44; overflow-wrap: anywhere; }

#project-chat-list { display: flex; flex-wrap: wrap; gap: .4rem; max-height: 12rem; overflow: auto; margin-top: .5rem; }
#project-chat-list[hidden] { display: none; }

.storage-warning { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-shrink:0; margin:0 16px 8px; padding:12px 14px; border:1px solid #b58838; border-radius:10px; background:var(--soft); }
.storage-warning p { margin:4px 0; }
.storage-warning small { display:block; color:var(--muted); overflow-wrap:anywhere; }
.storage-warning button { flex-shrink:0; padding:8px 10px; border:1px solid var(--line); }
@media(max-width:600px) { .storage-warning { align-items:flex-start; flex-direction:column; font-size:.85rem; margin-inline:8px; } }
