:root {
  --sidebar-bg: #fbfbf9;
  --main-bg: #fcfcfb;
  --ink: #20201e;
  --ink-soft: #6b6861;
  --ink-faint: #93908a;
  --line: #eceae4;
  --line-soft: #f2f0eb;
  --soft: #f5f4f1;
  --soft-2: #ecebe4;
  --accent: #ce5c34;
  --accent-soft: #f1d9d1;
  --sidebar-w: 288px;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow: 0 10px 30px rgba(50,42,33,.07);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--main-bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
svg { display: block; flex: 0 0 auto; }
a { color: inherit; text-decoration: none; }
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100%; }

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  padding: 0 8px 12px;
}
.brand-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 17px; }
.brand { font-family: Georgia, "Times New Roman", serif; font-size: 23px; line-height: 26px; font-weight: 600; letter-spacing: -0.03em; }
.close-sidebar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; color: var(--ink-faint); transition: background .15s ease, color .15s ease; }
.close-sidebar:hover { color: var(--ink); background: var(--soft); }
.side-list { display: grid; gap: 0; margin-bottom: 24px; }
.new-chat {
  display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 10px; border-radius: 8px;
  background: var(--soft); color: var(--ink); font-size: 14px; font-weight: 580; transition: background .15s ease, color .15s ease;
}
.new-chat:hover { background: var(--soft-2); color: var(--ink); }
.new-chat span { display: inline-flex; align-items: center; }
.new-chat .shortcut { margin-left: auto; color: var(--ink-faint); font-size: 11.5px; font-weight: 450; }
.nav-item {
  display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 10px; border-radius: 8px;
  color: #4b4944; font-size: 14px; transition: background .15s ease, color .15s ease;
}
.nav-item:hover { background: var(--soft); color: var(--ink); }
.nav-item span { display: inline-flex; align-items: center; }
.nav-item .nav-tag { margin-left: auto; color: #3c7a84; background: #eef4f5; border-radius: 99px; padding: 2px 7px; font-size: 10.5px; }
.section-title { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 8px; color: #6c6a62; font-size: 12px; font-weight: 520; }
.section-plus { color: #8b8880; width: 24px; height: 24px; border-radius: 8px; display: grid; place-items: center; font-size: 16px; }
.section-plus:hover { background: var(--soft); color: var(--ink); }
.pin-row { display: flex; align-items: center; gap: 10px; padding: 10px 6px 22px; border-radius: 10px; color: #7f7d75; font-size: 12.5px; }
.pin-row span { display: grid; place-items: center; color: #9d9a93; }
.conversation-list { min-height: 0; overflow: auto; margin-top: 0; padding: 0 6px 10px; scrollbar-width: thin; scrollbar-color: #dddad3 transparent; }
.conversation-list::-webkit-scrollbar { width: 6px; }
.conversation-list::-webkit-scrollbar-thumb { background: #dddad3; border-radius: 99px; }
.empty-history { padding: 14px 10px; color: #8b8881; font-size: 12.5px; line-height: 1.5; }
.conversation-row { position: relative; }
.conversation-item {
  width: 100%; min-height: 34px; display: flex; align-items: center; gap: 8px; padding: 8px 9px; margin-bottom: 2px;
  border-radius: 9px; background: transparent; color: #3f3d38; text-align: left; font-size: 13.5px; line-height: 1.35;
}
.conversation-item > span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding-right: 34px; }
.conversation-row:hover .conversation-item, .conversation-row:focus-within .conversation-item { background: var(--soft); color: var(--ink); }
.conversation-item.active { background: var(--soft-2); font-weight: 520; }
.conversation-actions { position: absolute; right: 5px; top: 5px; display: flex; gap: 1px; opacity: 0; pointer-events: none; transition: opacity .15s ease; }
.conversation-row:hover .conversation-actions, .conversation-row:focus-within .conversation-actions, .conversation-row.active .conversation-actions { opacity: 1; pointer-events: auto; }
.conversation-actions button { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 7px; color: #89867f; }
.conversation-actions button:hover { background: #e7e4dd; color: var(--ink); }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 10px; }
.utility-row { display: flex; align-items: center; gap: 6px; padding: 0 4px; }
.utility-btn { min-width: 0; flex: 1; display: flex; align-items: center; gap: 9px; height: 36px; padding: 0 9px; border-radius: 9px; color: #4a4843; font-size: 13px; transition: background .15s ease, color .15s ease; }
.utility-btn:hover { background: var(--soft); color: var(--ink); }
.mini-btn { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: #7d7b73; }
.mini-btn:hover { background: var(--soft); color: var(--ink); }

/* Main */
.main { display: flex; flex-direction: column; min-width: 0; background: var(--main-bg); position: relative; }
.topbar { position: relative; height: 46px; flex: 0 0 46px; padding: 0 14px; display: flex; align-items: center; justify-content: flex-start; }
.menu-btn { display: none; width: 34px; height: 34px; border-radius: 10px; color: #787570; transition: background .15s ease, color .15s ease; }
.app.sidebar-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.app.sidebar-collapsed .sidebar { overflow: hidden; opacity: 0; pointer-events: none; transition: opacity .18s ease; }
.app.sidebar-collapsed .topbar .menu-btn { display: grid; }
.menu-btn:hover { background: var(--soft); color: var(--ink); }

.workspace { min-height: 0; flex: 1; display: flex; flex-direction: column; }
.messages { flex: 1; overflow: auto; padding: 24px 22px 170px; scrollbar-width: thin; scrollbar-color: #dedbd4 transparent; }
.messages::-webkit-scrollbar { width: 7px; }
.messages::-webkit-scrollbar-thumb { background: #dedbd4; border-radius: 99px; }
.message-column { width: min(100%, 720px); margin: 0 auto; }
.app.home .messages { display: none; }
.app.home .workspace { display: none; }
.app.home .composer-wrap { position: absolute; inset: 46px 0 0; margin: 0; background: none; display: block; padding: 252px 20px 22px; }
.app.home .composer { width: min(100%, 640px); margin: 0 auto; }
.home-copy { width: min(100%, 640px); margin: 0 auto 35px; display: none; }
.app.home .home-copy { display: block; animation: homeIn .42s cubic-bezier(.2,.75,.25,1) both; }
.greeting { display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 0; font-family: Georgia, "Times New Roman", serif; font-size: 38px; line-height: 47.5px; letter-spacing: 0; color: #0b0b0b; font-weight: 400; }
.greeting-text { min-width: 0; }
.greeting .star { width: 40px; height: 40px; margin-right: -2px; color: #d97757; display: grid; place-items: center; }
.setup-hint { display: none; margin-top: 14px; color: #8a8781; font-size: 14px; line-height: 1.6; text-align: center; }
.setup-hint.show { display: block; animation: homeIn .42s cubic-bezier(.2,.75,.25,1) both; }
.message { display: flex; gap: 12px; margin: 26px 0; animation: messageIn .34s ease both; animation-delay: calc(var(--message-index, 0) * 14ms); }
.message.user { justify-content: flex-end; }
.message-avatar { width: 26px; height: 26px; border-radius: 9px; display: grid; place-items: center; color: #d2603b; background: #f0ded5; margin-top: 2px; }
.message-body { width: min(100%, 680px); min-width: 0; }
.message.user .message-body { display: flex; flex-direction: column; align-items: flex-end; }
.message-content { font-size: 15.5px; line-height: 1.72; }
.message.user .message-content { padding: 12px 15px; border-radius: 15px 15px 5px 15px; background: #f2f0eb; line-height: 1.6; max-width: min(86%, 580px); box-shadow: 0 2px 8px rgba(60,51,40,.04); }
.message-content p { margin: 0 0 11px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content pre { margin: 12px 0; padding: 13px 14px; background: #f7f5f1; color: #2d2b28; border-radius: 12px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; line-height: 1.6; }
.copy-code { position: absolute; top: 6px; right: 6px; padding: 3px 6px; border-radius: 6px; background: #fff; color: #78766f; font-size: 10px; }
.copy-code:hover { color: var(--ink); }
.message-content code { background: #f3f0eb; padding: 2px 4px; border-radius: 4px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .88em; }
pre code { background: transparent; padding: 0; }
.message-actions { display: flex; opacity: 0; gap: 2px; margin-top: 6px; transition: opacity .16s ease; }
.main.view-transition { animation: viewIn .3s cubic-bezier(.2,.75,.25,1) both; }
.main.view-transition .message { animation: none; opacity: 1; transform: none; }
.message:hover .message-actions, .message-actions:focus-within { opacity: 1; }
.ghost-action { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 8px; color: #8f8c84; }
.ghost-action:hover { background: var(--soft); color: var(--ink); }
.typing { display: inline-flex; gap: 4px; align-items: center; padding: 5px 0; }
.typing i { width: 5px; height: 5px; background: #bdbab2; border-radius: 99px; animation: pulse 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

/* Attachments */
.attachment-tray { display: flex; gap: 8px; margin-bottom: 10px; overflow-x: auto; }
.attachment-tray:empty { display: none; }
.attachment-tray.message { justify-content: flex-end; margin-bottom: 8px; }
.attachment-chip { position: relative; flex: 0 0 auto; display: flex; align-items: center; gap: 8px; height: 44px; padding: 6px 10px 6px 6px; border: 1px solid #eeece6; border-radius: 12px; background: #fff; box-shadow: 0 3px 10px rgba(60,50,35,.05); }
.attachment-chip img, .file-icon { width: 30px; height: 30px; border-radius: 8px; }
.attachment-chip img { object-fit: cover; background: #f3f1ec; }
.file-icon { display: grid; place-items: center; color: #904c2d; background: #f3ded4; }
.attachment-name { max-width: 170px; color: #6c6a62; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment-chip button { width: 22px; height: 22px; margin-right: -4px; border-radius: 7px; color: #8b8881; font-size: 12px; display: grid; place-items: center; }
.attachment-chip button:hover { background: var(--soft); color: var(--ink); }

/* Composer */
.composer-wrap { position: absolute; bottom: 0; left: 0; right: 0; z-index: 2; padding: 18px 22px 18px; background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,.9) 28%, #fff 60%); display: flex; flex-direction: column; }
.composer { width: min(100%, 760px); margin: 0 auto; }
.composer-box { height: 114px; background: #fff; border: 0; border-radius: 14px; padding: 10px; box-shadow: 0 4px 20px rgba(0,0,0,.075), 0 0 0 1px rgba(31,31,30,.3); transition: box-shadow .2s ease; }
.composer-box:focus-within, .composer-box.dragging { box-shadow: 0 4px 20px rgba(0,0,0,.1), 0 0 0 1px rgba(31,31,30,.42); }
.composer-input { width: 100%; height: 54px; min-height: 54px; max-height: 180px; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 16px; line-height: 22px; padding: 5px 0 5px 10px; }
.composer-input::placeholder { color: #898781; }
.composer-bottom { height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tools { display: flex; align-items: center; gap: 5px; }
.tool-btn { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 10px; color: #7c7a73; }
.tool-btn:hover { background: var(--soft); color: var(--ink); }
.composer-right { display: flex; align-items: center; gap: 4px; }
.model-picker { position: relative; }
.model-picker .model-picker-btn { width: 100%; }
.model-picker-btn { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; height: 36px; min-width: 180px; max-width: 240px; padding: 0 12px; border-radius: 10px; border: 1px solid #e7e4de; background: #fff; color: #0b0b0b; font-size: 13px; transition: border-color .15s ease, background .15s ease; }
.model-picker-btn:hover { border-color: #c9c2b6; background: #faf9f6; }
.model-picker-panel { position: absolute; right: 0; bottom: 48px; width: 320px; padding: 4px 0; border: 1px solid #e7e4de; border-radius: 14px; background: #fff; box-shadow: 0 18px 50px rgba(60,50,40,.18); z-index: 20; }
.model-picker-panel.in-modal { top: 44px; bottom: auto; left: 0; right: 0; width: 100%; }
.model-picker-search { padding: 10px 12px; border-bottom: 1px solid #eceae4; }
.model-picker-search input { width: 100%; height: 34px; padding: 0 10px; border: 1px solid #e7e4de; border-radius: 10px; outline: none; font-size: 13px; }
.model-picker-search input:focus { border-color: #c9c2b6; box-shadow: 0 0 0 3px rgba(180,170,150,.09); }
.model-list { max-height: 260px; overflow: auto; padding: 4px 0; }
.model-settings-list { margin-top: 8px; border: 1px solid #e7e4de; border-radius: 12px; background: #fff; overflow: hidden; }
.model-settings-list .model-list { max-height: 220px; overflow: auto; }

.model-list-empty { padding: 12px 12px; color: #8a8781; font-size: 12.5px; line-height: 1.5; }
.model-option { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; color: #0b0b0b; font-size: 13px; text-align: left; transition: background .14s ease; }
.model-option:hover { background: #f5f4f1; }
.model-option.active { background: #e8f4ff; font-weight: 600; }
.model-check { color: #2f6f83; }
.model-select { appearance: none; height: 32px; width: 126px; min-width: 126px; max-width: 126px; padding: 0 18px 0 4px; border: 0; background: transparent; color: #77756f; font-size: 14px; }
.model-select:focus { outline: none; }
.send-btn { width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; transition: background .15s ease, transform .15s ease, opacity .15s ease; }
.send-btn.empty { background: transparent; color: #0b0b0b; opacity: .35; }
.send-btn:disabled { cursor: default; }
.send-btn:hover { background: #b64f2c; transform: translateY(-1px); }
.send-btn.empty:hover { background: transparent; transform: none; }
.send-btn.stop { background: #262623; }
.clear-input-btn { visibility: hidden; opacity: 0; transition: opacity .15s ease, visibility .15s ease; }
.clear-input-btn.visible { visibility: visible; opacity: 1; }
.quick-chips { width: min(100%, 640px); margin: 39px auto 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.suggestions-panel { display: none; width: min(100%, 640px); margin: 39px auto 0; overflow: hidden; border: 1px solid #e7e4de; border-radius: 15px; background: #fff; box-shadow: 0 3px 12px rgba(55,48,39,.08); animation: suggestionIn .2s ease both; }
.composer.suggestions-open .suggestions-panel { display: block; }
.composer.suggestions-open .quick-chips { display: none; }
.suggestions-head { height: 40px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px 0 17px; color: #7b7870; font-size: 13px; }
.suggestions-close { width: 28px; height: 28px; border-radius: 8px; color: #77746d; font-size: 20px; line-height: 1; }
.suggestions-close:hover { background: var(--soft); color: var(--ink); }
.suggestion-item { width: 100%; height: 41px; padding: 0 17px; border-top: 1px solid #efede8; color: #595650; text-align: left; font-size: 13.5px; transition: background .14s ease, color .14s ease; }
.suggestion-item:hover { background: #faf9f6; color: var(--ink); }
.app:not(.home) .quick-chips, .app:not(.home) .home-copy { display: none; }
.app:not(.home) .suggestions-panel { display: none !important; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid #e8e6df; background: #fff; color: #0b0b0b; font-size: 14px; transition: background .16s ease, color .16s ease, transform .16s ease, border-color .16s ease; }
.chip:hover { background: #fff; color: var(--ink); border-color: #ddd8cf; transform: translateY(-1px); }
.chip span { display: grid; place-items: center; color: #89867e; }
/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(31,30,27,.38); opacity: 0; pointer-events: none; transition: opacity .18s ease; }
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal { width: min(560px, 100%); max-height: min(720px, 94vh); overflow: auto; background: #fff; border-radius: 20px; box-shadow: var(--shadow); transform: translateY(10px) scale(.98); opacity: 0; transition: transform .2s ease, opacity .16s ease; }
.modal-backdrop.open .modal { transform: none; opacity: 1; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 14px; }
.modal-title { font-size: 17px; font-weight: 620; }
.close-btn { width: 30px; height: 30px; border-radius: 9px; color: #7f7d76; font-size: 18px; }
.close-btn:hover { background: var(--soft); color: var(--ink); }
.settings-form { display: flex; flex-direction: column; min-height: 0; }
.modal-body { overflow: auto; padding: 2px 22px 18px; display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field-label { display: flex; justify-content: space-between; font-size: 12px; font-weight: 580; }
.field-help { color: #918f87; font-size: 10.5px; font-weight: 400; }
.field input, .field textarea { width: 100%; border: 1px solid #ddd9d1; border-radius: 11px; padding: 10px 11px; background: #fff; font-size: 13px; outline: none; }
.field textarea { min-height: 74px; resize: vertical; line-height: 1.5; }
.field input:focus, .field textarea:focus { border-color: #c9c2b6; box-shadow: 0 0 0 3px rgba(180,170,150,.09); }
.input-with-button { display: flex; gap: 7px; }
.input-with-button input { min-width: 0; flex: 1; }
.small-btn { height: 35px; padding: 0 11px; border-radius: 10px; background: var(--soft); color: #6d6b64; font-size: 12px; }
.small-btn:hover { background: #eae8e2; color: var(--ink); }
.check-row { display: flex; align-items: center; gap: 8px; color: #6f6d66; font-size: 12.5px; }
.modal-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 22px 18px; border-top: 1px solid var(--line-soft); }
.danger-btn { color: #a45a42; font-size: 12px; }
.danger-btn:hover { text-decoration: underline; }
.primary-btn { height: 36px; padding: 0 16px; border-radius: 11px; background: #20201e; color: #fff; font-size: 12.5px; }
.primary-btn:hover { background: #333330; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 18px); background: #262523; color: #fff; padding: 10px 14px; border-radius: 11px; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes messageIn { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: .3; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-2px); } }
@keyframes homeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes suggestionIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

@media (max-width: 900px) {
  :root { --sidebar-w: 260px; }
  .conversation-item > span { padding-right: 0; }
}
@media (max-width: 760px) {
  body { overflow-x: hidden; }
  .app { grid-template-columns: minmax(0,1fr); }
  .sidebar { position: fixed; z-index: 45; top: 0; bottom: 0; left: 0; width: min(84vw, 300px); transform: translateX(-102%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .close-sidebar { display: grid; }
  .topbar { height: 38px; padding: 0 10px; }
  .menu-btn { display: grid; }
  .messages { padding: 18px 14px 168px; }
  .composer-wrap { padding: 14px 11px 16px; }
  .greeting { font-size: clamp(26px, 7vw, 38px); white-space: normal; flex-wrap: wrap; line-height: 1.15; text-align: center; }
  .message-body { width: min(100%, calc(100vw - 66px)); }
  .quick-chips { margin-top: 35px; }
}
@media (max-width: 560px) {
  .topbar { height: 34px; }
  .messages { padding-bottom: 165px; }
  .quick-chips { gap: 7px; }
  .chip { height: 36px; font-size: 12px; }
  .attachment-name { max-width: 120px; }
  .composer-box { padding-left: 8px; padding-right: 8px; }
  .composer-bottom { gap: 4px; }
  .composer-bottom, .composer-right, .tools { min-width: 0; }
  .model-select { flex: 1 1 78px; width: 78px; min-width: 78px; max-width: 78px; padding-right: 2px; font-size: 11px; }
  .composer-right { gap: 1px; flex-shrink: 1; }
}
