:root {
  --p: #6d1232; --p-dark: #4a0d24; --p-light: #8c1d45; --gold: #d6a84f; --gold-soft: #f4e6c4;
  --ivory: #fffdf8; --cream: #fbf7f0; --ink: #1b1420; --muted: #6b6470; --line: rgba(109, 18, 50, 0.14);
  --shadow: 0 14px 40px rgba(74, 13, 36, 0.12); --radius: 14px; --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif; --display: 'Fraunces', Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--cream); font-size: 15px; line-height: 1.5; }
a { color: var(--p); }
button { font: inherit; cursor: pointer; }
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { height: 56px; display: flex; align-items: center; gap: 14px; padding: 0 16px; background: #fff; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--p-dark); font-weight: 700; }
.topbar-title { font-family: var(--display); font-weight: 600; font-size: 1.05rem; color: var(--p); display: flex; align-items: center; gap: 8px; flex: 1; }
.beta { font-family: var(--font); font-size: 11px; background: var(--gold-soft); color: #7a5a14; padding: 2px 8px; border-radius: 999px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.topbar-right { display: flex; gap: 6px; }
.icon-btn { background: none; border: 1px solid transparent; color: var(--muted); width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.only-mobile { display: none; }
.icon-btn:hover { background: var(--cream); color: var(--p); border-color: var(--line); }
.btn-primary { background: linear-gradient(135deg, var(--p), var(--p-light)); color: #fff; border: none; border-radius: 999px; padding: 10px 18px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: #fff; color: var(--p); border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.btn-secondary.small { padding: 6px 12px; font-size: 13px; }
.muted { color: var(--muted); } .small { font-size: 13px; }

[hidden] { display: none !important; }
.gate { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 36px; text-align: center; max-width: 420px; box-shadow: var(--shadow); }
.gate-icon { font-size: 34px; color: var(--p); margin-bottom: 10px; }
.gate-card h1 { font-family: var(--display); margin: 0 0 8px; }
.gate-card .btn-primary, .gate-card .btn-secondary { margin-top: 12px; }

.shell { flex: 1; display: grid; grid-template-columns: 250px 1fr 340px; min-height: 0; }
.shell[hidden] { display: none; }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; min-height: 0; }
.new-chat { width: 100%; justify-content: center; }
.sidebar-section { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 18px 0 8px; }
.conv-list { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-item { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px; border: none; background: none; text-align: left; width: 100%; color: var(--ink); }
.conv-item:hover { background: var(--cream); }
.conv-item.active { background: var(--gold-soft); color: var(--p-dark); font-weight: 600; }
.conv-item span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv-item .del { opacity: 0; color: var(--muted); }
.conv-item:hover .del { opacity: 1; }
.sidebar-foot { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; padding-top: 10px; border-top: 1px solid var(--line); }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.messages { flex: 1; overflow: auto; padding: 24px 24px 12px; }
.welcome { max-width: 860px; margin: 24px auto; }
.eyebrow { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.welcome h2 { font-family: var(--display); font-size: 2rem; margin: 6px 0 8px; color: var(--p-dark); line-height: 1.15; }
.welcome p { color: var(--muted); max-width: 640px; }
.starters { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin: 18px 0; }
.starter { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px; text-align: left; display: flex; gap: 12px; align-items: flex-start; transition: transform .12s, box-shadow .12s; }
.starter:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--gold); }
.starter i { color: var(--p); font-size: 18px; margin-top: 2px; width: 22px; text-align: center; }
.starter b { display: block; font-size: 14px; color: var(--p-dark); }
.starter span { font-size: 12.5px; color: var(--muted); }
.welcome-tip { background: var(--gold-soft); border-radius: 12px; padding: 12px 14px; font-size: 14px; color: #5a4312; display: flex; gap: 10px; }

.msg { max-width: 860px; margin: 0 auto 18px; display: flex; gap: 12px; }
.msg .avatar { width: 32px; height: 32px; border-radius: 50%; flex: 0 0 32px; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.msg.user .avatar { background: var(--gold-soft); color: #7a5a14; }
.msg.assistant .avatar { background: var(--p); color: #fff; }
.msg .bubble { flex: 1; min-width: 0; }
.msg.user .bubble { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; white-space: pre-wrap; }
.msg.assistant .bubble { padding: 4px 0; }
.md p { margin: 0 0 10px; } .md ul, .md ol { margin: 0 0 10px; padding-left: 22px; } .md li { margin-bottom: 4px; }
.md h1, .md h2, .md h3 { font-family: var(--display); color: var(--p-dark); margin: 14px 0 6px; } .md h1 { font-size: 1.35rem; } .md h2 { font-size: 1.2rem; } .md h3 { font-size: 1.05rem; }
.md code { background: var(--cream); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md pre { background: #fff; border: 1px solid var(--line); padding: 10px; border-radius: 10px; overflow: auto; }
.md table { border-collapse: collapse; margin: 6px 0 12px; font-size: 14px; } .md td, .md th { border: 1px solid var(--line); padding: 5px 9px; text-align: left; } .md th { background: var(--cream); }
.md blockquote { border-left: 3px solid var(--gold); margin: 8px 0; padding: 4px 12px; color: var(--muted); }
.attachments { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--cream); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; color: var(--p-dark); }
.chip img { width: 20px; height: 20px; object-fit: cover; border-radius: 4px; }
.chip .x { border: none; background: none; color: var(--muted); padding: 0 2px; }
.tool-card { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; margin: 4px 6px 4px 0; }
.tool-card i { color: var(--p); }
.tool-card.running i { animation: spin 1s linear infinite; }
.tool-card .ok { color: #2e7d32; } .tool-card .err { color: #c62828; }
.progress-note { font-size: 13px; color: var(--muted); font-style: italic; margin: 4px 0; padding-left: 4px; border-left: 2px solid var(--gold-soft); }
@keyframes spin { to { transform: rotate(360deg); } }
.typing { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--p); animation: blink 1s infinite; margin-left: 4px; }
@keyframes blink { 50% { opacity: .2; } }

.artifact { display: flex; gap: 14px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 10px 0; box-shadow: 0 6px 20px rgba(74,13,36,.06); max-width: 560px; }
.artifact .thumb { width: 110px; height: 142px; flex: 0 0 110px; border-radius: 8px; background: var(--cream); border: 1px solid var(--line); overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--p); font-size: 30px; }
.artifact .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.artifact .thumb.wide { height: 80px; }
.artifact .info { flex: 1; min-width: 0; }
.artifact .title { font-weight: 700; color: var(--p-dark); margin-bottom: 2px; }
.artifact .meta { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.artifact .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.artifact .actions a, .artifact .actions button { font-size: 13px; }

.composer-wrap { padding: 8px 24px 14px; background: linear-gradient(to top, var(--cream) 70%, rgba(251,247,240,0)); }
.allowance-line { display: block; margin-bottom: 4px; color: var(--p); font-weight: 600; }
.allowance-line a { color: var(--p); text-decoration: underline; }
.allowance-banner { max-width: 860px; margin: 0 auto 8px; background: var(--gold-soft); border: 1px solid #e6cf8a; color: #5a4210; border-radius: 12px; padding: 10px 14px; font-size: 13.5px; line-height: 1.45; }
.allowance-banner a { color: var(--p); font-weight: 700; }
.status-line { max-width: 860px; margin: 0 auto 6px; font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.status-line[hidden] { display: none; }
.attach-list { max-width: 860px; margin: 0 auto 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.composer { max-width: 860px; margin: 0 auto; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 8px 8px 8px 10px; display: flex; align-items: flex-end; gap: 6px; box-shadow: var(--shadow); }
.composer:focus-within { border-color: var(--p); }
.composer textarea { flex: 1; border: none; resize: none; outline: none; font: inherit; padding: 8px 4px; max-height: 220px; background: transparent; }
.mic-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--p); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: 0 0 auto; }
.mic-btn:hover { background: var(--cream); }
.mic-btn.on { background: #c62828; border-color: #c62828; color: #fff; animation: micpulse 1.2s ease-in-out infinite; }
.mic-btn.busy { color: var(--muted); }
.mic-btn-sm { width: 26px; height: 26px; font-size: 12px; vertical-align: middle; margin-left: 6px; }
@keyframes micpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(198,40,40,.45); } 50% { box-shadow: 0 0 0 8px rgba(198,40,40,0); } }
.send-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--p); color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.send-btn:disabled { opacity: .5; cursor: default; }
.send-btn.stop { background: #c62828; }
.composer-note { max-width: 860px; margin: 8px auto 0; font-size: 12px; color: var(--muted); text-align: center; }

.workspace { background: #fff; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.workspace.collapsed { display: none; }
.ws-tabs { display: flex; border-bottom: 1px solid var(--line); }
.ws-tab { flex: 1; border: none; background: none; padding: 12px 6px; color: var(--muted); font-weight: 600; font-size: 13px; border-bottom: 2px solid transparent; }
.ws-tab.active { color: var(--p); border-bottom-color: var(--p); }
.ws-pane { display: none; overflow: auto; padding: 14px; flex: 1; }
.ws-pane.active { display: block; }
.ws-actions { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.empty { color: var(--muted); font-size: 13.5px; }
.doc-list, .file-list { display: flex; flex-direction: column; gap: 10px; }
.doc-item { display: flex; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.doc-item .thumb { width: 54px; height: 70px; flex: 0 0 54px; background: var(--cream); border-radius: 6px; overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--p); }
.doc-item .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.doc-item .t { font-size: 13.5px; font-weight: 600; color: var(--p-dark); line-height: 1.25; }
.doc-item .m { font-size: 12px; color: var(--muted); }
.doc-item .a { display: flex; gap: 10px; margin-top: 4px; font-size: 12.5px; }
.file-item { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.file-item .thumb { width: 48px; height: 48px; flex: 0 0 48px; border-radius: 8px; background: var(--cream); overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--p); }
.file-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-item .n { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .m { font-size: 12px; color: var(--muted); }
.file-item .del { margin-left: auto; }
.profile-form label { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.profile-form input, .profile-form textarea, .profile-form select { display: block; width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 14px; color: var(--ink); background: #fff; }
.profile-form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.profile-form .btn-primary { width: 100%; justify-content: center; margin-top: 4px; }
.memories { margin-top: 18px; }
.memory { font-size: 13px; background: var(--cream); border-radius: 8px; padding: 7px 10px; margin-bottom: 6px; display: flex; gap: 8px; }
.memory button { border: none; background: none; color: var(--muted); margin-left: auto; }

.modal { position: fixed; inset: 0; background: rgba(27,20,32,.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 18px; padding: 20px; max-width: 980px; width: 100%; max-height: 90vh; overflow: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-family: var(--display); margin: 0; color: var(--p-dark); }
.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-top: 12px; }
.style-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; text-align: left; padding: 0; display: flex; flex-direction: column; }
.style-card:hover { border-color: var(--p); box-shadow: var(--shadow); }
.style-card .sw { height: 120px; display: flex; align-items: flex-end; padding: 10px; background: #eee; }
.style-card .sw img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.style-card .sw.fallback { background: linear-gradient(160deg, var(--sw1), var(--sw2)); }
.style-card .sw .lab { font-family: var(--display); color: #fff; font-weight: 700; text-shadow: 0 1px 3px rgba(0,0,0,.4); }
.style-card .nm { font-weight: 700; font-size: 13.5px; padding: 8px 10px 2px; color: var(--p-dark); }
.style-card .lk { font-size: 12px; color: var(--muted); padding: 0 10px 10px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 60; box-shadow: var(--shadow); }
.toast[hidden] { display: none; }

@media (max-width: 1100px) { .shell { grid-template-columns: 220px 1fr; } .workspace { display: none; position: fixed; right: 0; top: 56px; bottom: 0; width: 340px; z-index: 40; box-shadow: var(--shadow); } .workspace.open { display: flex; } }
@media (max-width: 760px) { html, body { overflow-x: hidden; } .topbar { gap: 8px; } .brand span, .beta { display: none; } .topbar-title { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; } .topbar-right { flex-shrink: 0; } .only-mobile { display: inline-flex; } .shell { grid-template-columns: 1fr; } .sidebar { display: none; } .sidebar.open { display: flex; position: fixed; left: 0; top: 56px; bottom: 0; width: 260px; z-index: 40; } .messages { padding: 14px; } .composer-wrap { padding: 6px 10px 10px; } .starters { grid-template-columns: 1fr; } .workspace { width: 100%; } .topbar-title { font-size: .95rem; } .artifact .thumb { width: 80px; height: 104px; flex-basis: 80px; } }
