:root {
  --bg: #f6f3ee;
  --side: #efebe4;
  --card: #ffffff;
  --ink: #23201c;
  --muted: #77706a;
  --line: #e2ddd5;
  --accent: #1f5f5b;
  --accent-soft: #e3eeec;
  --user: #e9e4dc;
  --radius: 14px;
  --serif: 'Source Serif 4', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, Segoe UI, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 15px; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(360px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 32px; text-align: center; box-shadow: 0 10px 30px rgba(60, 40, 20, .06); }
.login-card h1 { font-family: var(--serif); font-weight: 600; margin: 12px 0 4px; font-size: 28px; }
.login-card p { color: var(--muted); margin: 0 0 20px; }
.login-card input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--bg); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card button { width: 100%; margin-top: 12px; padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; }
.login-err { color: #b3261e; min-height: 20px; margin-top: 10px; font-size: 14px; }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: #fff; display: inline-grid; place-items: center; font-family: var(--serif); font-weight: 600; font-size: 24px; }
.brand-mark.sm { width: 26px; height: 26px; font-size: 15px; border-radius: 7px; }

/* Layout */
.app { display: flex; height: 100dvh; overflow: hidden; }
.sidebar { width: 268px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 12px; gap: 6px; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 8px; }
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--serif); font-weight: 600; font-size: 19px; }
.new-chat { text-align: left; padding: 10px 12px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; font-weight: 500; }
.new-chat:hover { border-color: #cfc8bd; }
.side-label { font-size: 12px; color: var(--muted); padding: 14px 8px 4px; text-transform: uppercase; letter-spacing: .04em; }
.convo-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; min-height: 0; }
.convo { display: flex; align-items: center; gap: 4px; border-radius: 8px; }
.convo a { flex: 1; min-width: 0; padding: 8px 10px; color: inherit; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.convo:hover, .convo.active { background: #e4dfd6; }
.convo .del { opacity: 0; border: 0; background: none; color: var(--muted); padding: 4px 8px; }
.convo:hover .del { opacity: 1; }
.courses { font-size: 13px; color: var(--muted); padding: 6px 8px; }
.courses summary { cursor: pointer; padding: 4px 0; }
.courses ul { margin: 6px 0 0; padding-left: 16px; max-height: 180px; overflow-y: auto; }
.courses li { margin: 3px 0; }
.logout { border: 0; background: none; color: var(--muted); text-align: left; padding: 8px; font-size: 13px; }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid transparent; }
.convo-title { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
#model, #effort { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 5px 8px; font: inherit; font-size: 13px; color: var(--ink); }
.icon-btn { border: 0; background: none; width: 32px; height: 32px; border-radius: 8px; display: inline-grid; place-items: center; font-size: 16px; color: var(--muted); }
.icon-btn:hover { background: rgba(0, 0, 0, .05); color: var(--ink); }
.only-mobile { display: none; }

.scroller { flex: 1; overflow-y: auto; }
.messages { max-width: 760px; margin: 0 auto; padding: 18px 22px 30px; }
.msg { margin: 18px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--user); padding: 10px 15px; border-radius: 16px 16px 4px 16px; max-width: 82%; white-space: pre-wrap; word-wrap: break-word; line-height: 1.5; }
.msg.assistant .body { font-family: var(--serif); font-size: 17px; line-height: 1.65; }
.body > :first-child { margin-top: 0; }
.body h1, .body h2, .body h3 { font-weight: 600; line-height: 1.3; margin: 1.2em 0 .4em; }
.body h1 { font-size: 1.35em; } .body h2 { font-size: 1.2em; } .body h3 { font-size: 1.05em; }
.body p { margin: .6em 0; }
.body ul, .body ol { padding-left: 1.4em; margin: .5em 0; }
.body li { margin: .25em 0; }
.body code { font-family: ui-monospace, Consolas, monospace; font-size: .85em; background: #ece7df; padding: .1em .35em; border-radius: 5px; }
.body pre { background: #2a2622; color: #f1ece4; padding: 14px; border-radius: 10px; overflow-x: auto; font-size: 13px; }
.body pre code { background: none; padding: 0; color: inherit; }
.body table { border-collapse: collapse; width: 100%; margin: .8em 0; font-family: var(--sans); font-size: 14px; display: block; overflow-x: auto; }
.body th, .body td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.body th { background: #efeae2; }
.body blockquote { border-left: 3px solid var(--accent); margin: .8em 0; padding: .1em 1em; color: #4a4540; }
.body a { color: var(--accent); }
.tools { display: flex; flex-direction: column; gap: 4px; margin: 0 0 10px; }
.tool { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.tool::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #c2bbb0; }
.err { color: #b3261e; font-family: var(--sans); font-size: 14px; background: #fbeceb; padding: 10px 12px; border-radius: 10px; margin-top: 8px; }
.stopped { color: var(--muted); font-size: 13px; font-family: var(--sans); margin-top: 6px; }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #b9b1a5; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

.art-card { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 420px; margin: 12px 0; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; text-align: left; font-family: var(--sans); }
.art-card:hover { border-color: var(--accent); }
.art-card .ico { width: 38px; height: 38px; flex: none; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 18px; }
.art-card .t { font-weight: 600; font-size: 14px; }
.art-card .s { font-size: 12.5px; color: var(--muted); }

.empty { max-width: 680px; margin: 14vh auto 0; padding: 0 22px; text-align: center; }
.empty h2 { font-family: var(--serif); font-weight: 400; font-size: 34px; margin: 0 0 24px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.suggestions button { text-align: left; padding: 12px 14px; border: 1px solid var(--line); background: var(--card); border-radius: 12px; font-size: 14px; color: #4a4540; }
.suggestions button:hover { border-color: #cfc8bd; color: var(--ink); }

.composer { padding: 0 18px 14px; }
.composer-box { max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 10px 10px 10px 16px; box-shadow: 0 4px 18px rgba(60, 40, 20, .05); }
.composer-box:focus-within { border-color: #cbc3b7; }
.composer-box { flex-wrap: wrap; padding-left: 8px; }
.attach-row { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 2px 6px; }
.attach-btn { width: 36px; height: 36px; flex: none; border: 0; background: none; border-radius: 10px; color: var(--muted); display: grid; place-items: center; }
.attach-btn:hover { background: rgba(0, 0, 0, .05); color: var(--ink); }
.chip { position: relative; display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 30px 0 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 13px; max-width: 240px; }
.chip img { width: 44px; height: 44px; object-fit: cover; border-radius: 7px; display: block; }
.chip .pdf-ico { width: 44px; height: 44px; border-radius: 7px; background: #f3dcd8; color: #a33a2c; display: grid; place-items: center; font-weight: 700; font-size: 11px; }
.chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .x { position: absolute; top: 4px; right: 4px; border: 0; background: none; color: var(--muted); width: 22px; height: 22px; border-radius: 6px; }
.chip .x:hover { background: rgba(0, 0, 0, .06); }
.chip.uploading { opacity: .6; }
.chip.uploading::after { content: ''; position: absolute; left: 20px; top: 20px; width: 14px; height: 14px; border: 2px solid rgba(0, 0, 0, .2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.chip.failed { border-color: #e3a49d; background: #fbeceb; }
.msg.user { flex-direction: column; align-items: flex-end; gap: 6px; }
.user-atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 82%; }
.user-atts img { max-width: 220px; max-height: 220px; border-radius: 12px; display: block; cursor: zoom-in; border: 1px solid var(--line); }
.user-atts .pdf { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; font-size: 13px; }
.drop-zone { position: absolute; inset: 10px; z-index: 40; border: 2px dashed var(--accent); border-radius: 18px; background: rgba(246, 243, 238, .92); display: grid; place-items: center; font-size: 18px; color: var(--accent); font-weight: 500; pointer-events: none; }
.main { position: relative; }
textarea { flex: 1; border: 0; outline: none; resize: none; font: inherit; font-size: 15.5px; line-height: 1.5; max-height: 220px; background: none; padding: 5px 0; color: var(--ink); }
.send { width: 36px; height: 36px; flex: none; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-size: 18px; font-weight: 600; }
.send:disabled { opacity: .35; cursor: default; }
.send.stop { background: var(--ink); font-size: 12px; }
.hint { max-width: 760px; margin: 6px auto 0; text-align: center; font-size: 12px; color: var(--muted); }

/* Artifact panel */
.panel { width: min(52vw, 900px); flex: none; display: flex; flex-direction: column; background: var(--card); border-left: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--line); }
.panel-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-tabs { display: flex; background: var(--bg); border-radius: 9px; padding: 3px; }
.tab { border: 0; background: none; padding: 5px 10px; border-radius: 7px; font-size: 13px; color: var(--muted); }
.tab.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.panel-actions { display: flex; align-items: center; gap: 2px; }
#versionSel { border: 1px solid var(--line); border-radius: 7px; padding: 3px 4px; font: inherit; font-size: 12px; background: var(--card); }
.panel-body { flex: 1; position: relative; min-height: 0; }
#frame { width: 100%; height: 100%; border: 0; background: #fff; }
.code { position: absolute; inset: 0; margin: 0; overflow: auto; padding: 16px; background: #2a2622; color: #f1ece4; font: 12.5px/1.55 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.building { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 99px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.spinner { width: 12px; height: 12px; border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .panel { position: fixed; inset: 0; width: auto; z-index: 30; border: 0; }
}
@media (max-width: 760px) {
  .only-mobile { display: inline-grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; width: 84vw; max-width: 300px; }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .25); z-index: 15; }
  .topbar { padding: 8px 10px; }
  .messages { padding: 10px 14px 24px; }
  .msg.assistant .body { font-size: 16.5px; }
  .suggestions { grid-template-columns: 1fr; }
  .empty { margin-top: 8vh; }
  .empty h2 { font-size: 28px; }
  .composer { padding: 0 10px calc(10px + env(safe-area-inset-bottom)); }
  .tab { padding: 5px 8px; }
}
