:root {
  --bg: #0b1020;
  --panel: #11182b;
  --panel-2: #151f35;
  --panel-3: #1b2740;
  --text: #eef2ff;
  --muted: #9aa8c2;
  --border: rgba(148, 163, 184, 0.16);
  --accent: #7c9cff;
  --accent-strong: #5e7ff2;
  --accent-soft: rgba(124, 156, 255, 0.14);
  --danger: #ff6b78;
  --success: #4ade80;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
  --sidebar-width: 292px;
  --radius: 16px;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f7f9fd;
  --panel-3: #eef2f8;
  --text: #182033;
  --muted: #68738a;
  --border: rgba(30, 41, 59, 0.12);
  --accent: #506fe5;
  --accent-strong: #3f5ed2;
  --accent-soft: rgba(80, 111, 229, 0.11);
  --danger: #d94152;
  --success: #168a49;
  --shadow: 0 24px 80px rgba(38, 50, 79, 0.14);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.mobile-only { display: none; }

.app-shell { height: 100dvh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.sidebar {
  min-width: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  padding: max(16px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  z-index: 30;
}
.sidebar-top { min-width: 0; min-height: 0; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 18px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand > div:last-child { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-size: 15px; letter-spacing: .1px; }
.brand span { color: var(--muted); font-size: 11px; margin-top: 4px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center;
  font-weight: 800; color: white; background: linear-gradient(145deg, #8ea7ff, #576fe0);
  box-shadow: 0 8px 24px rgba(87, 111, 224, .35);
}
.brand-mark.large { width: 54px; height: 54px; border-radius: 17px; font-size: 22px; }
.new-chat-btn {
  height: 46px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; font-weight: 650;
  transition: .18s ease;
}
.new-chat-btn:hover { border-color: rgba(124,156,255,.55); background: var(--accent-soft); transform: translateY(-1px); }
.search-box {
  margin: 12px 0 8px; height: 40px; display: flex; align-items: center; gap: 8px;
  padding: 0 11px; border-radius: 12px; background: var(--panel-2); border: 1px solid transparent;
}
.search-box:focus-within { border-color: rgba(124,156,255,.5); }
.search-box span { color: var(--muted); font-size: 20px; }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 13px; }
.conversation-list { min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 4px 0; scrollbar-width: thin; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.conversation-item {
  position: relative; width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer;
  padding: 11px 38px 10px 12px; border-radius: 12px; color: var(--text); margin: 2px 0;
}
.conversation-item:hover { background: var(--panel-2); }
.conversation-item.active { background: var(--accent-soft); }
.conversation-item .conv-title { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-item .conv-meta { display: block; margin-top: 5px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-menu-btn { position: absolute; right: 7px; top: 13px; width: 27px; height: 27px; opacity: .2; }
.conversation-item:hover .conversation-menu-btn, .conversation-item.active .conversation-menu-btn { opacity: 1; }
.sidebar-empty { padding: 28px 14px; color: var(--muted); text-align: center; font-size: 13px; line-height: 1.6; }
.sidebar-footer { position: relative; z-index: 4; flex: none; border-top: 1px solid var(--border); padding-top: 10px; display: grid; gap: 2px; background: var(--panel); }
.footer-btn { border: 0; background: transparent; color: var(--muted); text-align: left; border-radius: 10px; padding: 10px 11px; cursor: pointer; }
.footer-btn:hover { background: var(--panel-2); color: var(--text); }

.main-panel { min-width: 0; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: var(--bg); }
.topbar {
  height: 66px; padding: max(8px, env(safe-area-inset-top)) 18px 8px; display: flex; align-items: center;
  justify-content: space-between; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px); z-index: 10;
}
.topbar-left, .topbar-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.title-button { border: 0; background: transparent; text-align: left; cursor: pointer; min-width: 0; padding: 4px 8px; border-radius: 9px; }
.title-button:hover { background: var(--panel-2); }
.title-button span { display: block; max-width: 300px; font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-button small { color: var(--muted); display: block; margin-top: 3px; font-size: 10px; }
.model-select { max-width: 190px; height: 38px; border: 1px solid var(--border); border-radius: 11px; padding: 0 30px 0 10px; background: var(--panel-2); color: var(--text); outline: none; }
.icon-btn {
  width: 38px; height: 38px; flex: 0 0 auto; border-radius: 11px; border: 1px solid transparent;
  background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--muted); font-size: 17px;
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--border); color: var(--text); }

.messages-viewport { min-height: 0; overflow-y: auto; scroll-behavior: smooth; overscroll-behavior: contain; }
.message-list { width: min(850px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 42px; }
.empty-state { min-height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 44px 20px; }
.empty-state h2 { margin: 18px 0 8px; font-size: clamp(24px, 4vw, 34px); }
.empty-state > p { color: var(--muted); margin: 0 0 26px; }
.suggestion-grid { width: min(650px, 100%); display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.suggestion-grid button { min-height: 68px; text-align: left; padding: 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; }
.suggestion-grid button:hover { border-color: rgba(124,156,255,.5); background: var(--accent-soft); }

.message { display: grid; grid-template-columns: 38px minmax(0,1fr); gap: 12px; padding: 18px 4px; border-bottom: 1px solid var(--border); }
.message:last-child { border-bottom: 0; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; font-size: 12px; font-weight: 800; }
.message.user .avatar { background: var(--panel-3); color: var(--text); }
.message.assistant .avatar { color: white; background: linear-gradient(145deg, #8ea7ff, #576fe0); }
.message-main { min-width: 0; }
.message-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.message-author { font-size: 12px; font-weight: 700; }
.message-time { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 10px; }
.message-actions { display: flex; opacity: 0; transition: opacity .15s; }
.message:hover .message-actions { opacity: 1; }
.message-actions button { width: 29px; height: 29px; font-size: 13px; }
.message-content { line-height: 1.72; font-size: 15px; overflow-wrap: anywhere; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message-content p { margin: .65em 0; }
.message-content h1, .message-content h2, .message-content h3 { line-height: 1.35; margin: 1.2em 0 .55em; }
.message-content h1 { font-size: 1.45em; } .message-content h2 { font-size: 1.25em; } .message-content h3 { font-size: 1.1em; }
.message-content ul, .message-content ol { padding-left: 1.55em; margin: .7em 0; }
.message-content blockquote { margin: .8em 0; padding: .2em 1em; border-left: 3px solid var(--accent); color: var(--muted); }
.message-content a { color: var(--accent); }
.message-content code:not(pre code) { padding: .15em .38em; border-radius: 5px; background: var(--panel-3); font-size: .9em; }
.code-block { position: relative; margin: 1em 0; border-radius: 13px; overflow: hidden; border: 1px solid var(--border); background: #080d18; }
.code-head { height: 34px; display: flex; align-items: center; justify-content: space-between; padding: 0 9px 0 12px; color: #94a3b8; background: #111827; font-size: 11px; }
.code-head button { border: 0; background: transparent; color: #aeb9ce; cursor: pointer; font-size: 11px; }
.code-block pre { margin: 0; padding: 15px; overflow-x: auto; color: #dbe7ff; font: 13px/1.55 "SFMono-Regular", Consolas, monospace; }
.typing-cursor::after { content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 3px; background: var(--accent); vertical-align: -.15em; animation: blink .8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer-wrap { padding: 8px 16px max(10px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, transparent, var(--bg) 22%); }
.composer { width: min(850px, 100%); margin: 0 auto; border: 1px solid var(--border); border-radius: 18px; background: var(--panel); box-shadow: 0 10px 35px rgba(0,0,0,.12); overflow: hidden; }
.composer:focus-within { border-color: rgba(124,156,255,.55); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea { width: 100%; max-height: 210px; resize: none; border: 0; outline: 0; color: var(--text); background: transparent; padding: 15px 16px 8px; line-height: 1.5; }
.composer-bottom { min-height: 45px; display: flex; align-items: center; justify-content: space-between; padding: 5px 8px 7px 12px; }
.composer-tools { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; }
.small-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 5px; }
.small-btn:hover { color: var(--text); }
.send-btn, .stop-btn { width: 36px; height: 36px; border: 0; border-radius: 11px; display: grid; place-items: center; cursor: pointer; color: white; font-size: 19px; }
.send-btn { background: var(--accent-strong); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; }
.stop-btn { background: var(--danger); font-size: 11px; }
.composer-note { text-align: center; color: var(--muted); font-size: 10px; margin: 7px 0 0; }
.usage-bar { width: min(850px,100%); margin: 0 auto 5px; color: var(--muted); text-align: right; font-size: 10px; }

.login-view { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 50% 0%, rgba(124,156,255,.16), transparent 42%), var(--bg); }
.login-card { width: min(400px,100%); padding: 32px; border-radius: 22px; border: 1px solid var(--border); background: var(--panel); box-shadow: var(--shadow); }
.login-card .brand-mark { margin: 0 auto; }
.login-card h1 { text-align: center; margin: 18px 0 6px; }
.login-card > p { text-align: center; color: var(--muted); margin: 0 0 25px; }
.field-label, label > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.password-row { display: flex; border: 1px solid var(--border); border-radius: 12px; background: var(--panel-2); }
.password-row:focus-within { border-color: rgba(124,156,255,.55); }
.password-row input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); padding: 12px; }
.form-hint { min-height: 18px; margin: 12px 0 0 !important; color: var(--danger) !important; font-size: 12px; }

.primary-btn, .secondary-btn, .danger-btn { min-height: 39px; border-radius: 11px; padding: 0 16px; cursor: pointer; font-weight: 650; }
.primary-btn { background: var(--accent-strong); color: white; border: 0; }
.secondary-btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.danger-btn { background: rgba(255,107,120,.12); color: var(--danger); border: 1px solid rgba(255,107,120,.3); }
.wide { width: 100%; margin-top: 15px; }

.modal { width: 100%; max-width: none; height: 100%; max-height: none; padding: 0; border: 0; background: transparent; color: var(--text); }
.modal::backdrop { background: rgba(3,7,18,.68); backdrop-filter: blur(5px); }
.modal[open] { display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(680px,100%); max-height: min(820px, calc(100dvh - 32px)); overflow: auto; border: 1px solid var(--border); border-radius: 20px; background: var(--panel); box-shadow: var(--shadow); }
.wide-modal .modal-card { width: min(960px,100%); }
.modal-header { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 19px 21px; border-bottom: 1px solid var(--border); background: var(--panel); }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-header p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.modal-body { padding: 20px; }
.modal-footer { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 9px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--panel); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.settings-grid label, .preset-editor label { min-width: 0; }
.settings-grid input:not([type="checkbox"]), .settings-grid select, .settings-grid textarea,
.preset-editor input:not([type="checkbox"]), .preset-editor select, .preset-editor textarea,
.modal-body textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 11px; outline: 0; color: var(--text); background: var(--panel-2); padding: 10px 11px;
}
.settings-grid textarea, .preset-editor textarea, .modal-body textarea { resize: vertical; line-height: 1.55; }
.settings-grid input:focus, .settings-grid select:focus, .settings-grid textarea:focus,
.preset-editor input:focus, .preset-editor select:focus, .preset-editor textarea:focus { border-color: rgba(124,156,255,.6); }
.full-width { grid-column: 1 / -1; }
label small { display: block; color: var(--muted); margin-top: 6px; font-size: 10px; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; }
.toggle-row > span { margin: 0; }
.toggle-row b { display: block; color: var(--text); font-size: 13px; }
.toggle-row input[type="checkbox"] { width: 42px; height: 23px; accent-color: var(--accent-strong); }
.check-row { display: flex; gap: 8px; color: var(--muted); font-size: 12px; margin-top: 12px; }
.preset-layout { display: grid; grid-template-columns: 270px minmax(0,1fr); min-height: 510px; }
.preset-list { border-right: 1px solid var(--border); padding: 12px; overflow-y: auto; }
.preset-list-item { width: 100%; text-align: left; padding: 11px; border: 0; border-radius: 11px; background: transparent; cursor: pointer; }
.preset-list-item:hover, .preset-list-item.active { background: var(--accent-soft); }
.preset-list-item b { display: block; font-size: 13px; }
.preset-list-item span { display: block; color: var(--muted); font-size: 10px; margin-top: 5px; line-height: 1.4; }
.preset-editor { display: grid; align-content: start; gap: 14px; padding: 20px; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.toggle-row.compact { padding: 20px 0 0; }
.preset-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.toast-host { position: fixed; top: max(14px, env(safe-area-inset-top)); right: 16px; z-index: 1000; display: grid; gap: 8px; pointer-events: none; }
.toast { max-width: min(360px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); padding: 11px 14px; box-shadow: var(--shadow); font-size: 12px; animation: toastIn .2s ease; }
.toast.error { border-color: rgba(255,107,120,.45); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } }
.sidebar-backdrop { display: none; }

@media (max-width: 760px) {
  .mobile-only { display: grid; }
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(3,7,18,.55); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  .main-panel { height: 100dvh; }
  .topbar { height: 60px; padding-left: 8px; padding-right: 8px; }
  .title-button span { max-width: 150px; }
  .model-select { display: none; }
  .topbar-actions { gap: 1px; }
  .message-list { width: calc(100% - 20px); padding-top: 15px; }
  .message { grid-template-columns: 31px minmax(0,1fr); gap: 9px; padding: 15px 2px; }
  .avatar { width: 29px; height: 29px; border-radius: 9px; font-size: 10px; }
  .message-content { font-size: 14px; }
  .message-actions { opacity: .55; }
  .composer-wrap { padding-left: 9px; padding-right: 9px; }
  .composer-note { display: none; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .empty-state { justify-content: flex-start; padding-top: 18vh; }
  .settings-grid { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
  .modal[open] { padding: 0; align-items: end; }
  .modal-card { width: 100%; max-height: 92dvh; border-radius: 20px 20px 0 0; border-bottom: 0; }
  .preset-layout { grid-template-columns: 1fr; }
  .preset-list { max-height: 190px; border-right: 0; border-bottom: 1px solid var(--border); }
  .two-cols { grid-template-columns: 1fr; }
}

/* v2 additions */
button:disabled, select:disabled, input:disabled, textarea:disabled { opacity: .55; cursor: not-allowed; }
.conversation-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.conversation-item-main { min-width: 0; flex: 1; }
.conversation-item-main strong, .conversation-item-main span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item-main span { margin-top: 5px; color: var(--muted); font-size: 10px; }
.conversation-item > small { flex: none; color: var(--muted); font-size: 9px; }
.conversation-empty { padding: 18px 10px; text-align: center; color: var(--muted); font-size: 12px; }
.message-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.message-head span { color: var(--text); font-weight: 700; }
.message-head time { opacity: .72; }
.message-foot { min-height: 14px; margin-top: 9px; }
.message-usage { color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; }
.reasoning-slot:empty { display: none; }
.reasoning-box { margin: 0 0 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel-2); overflow: hidden; }
.reasoning-box summary { cursor: pointer; padding: 9px 11px; color: var(--muted); font-size: 11px; user-select: none; }
.reasoning-box pre { max-height: 260px; overflow: auto; margin: 0; padding: 0 11px 11px; white-space: pre-wrap; color: var(--muted); font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.memory-box { border: 1px solid var(--border); border-radius: 13px; background: var(--panel-2); padding: 12px; }
.memory-box > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.memory-box pre { max-height: 220px; overflow: auto; white-space: pre-wrap; margin: 10px 0 0; color: var(--muted); font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.danger-text { color: var(--danger) !important; }
.preset-toolbar { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.context-preview { margin: 0; min-height: 360px; max-height: 68dvh; overflow: auto; border: 1px solid var(--border); border-radius: 13px; background: var(--panel-2); padding: 14px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.typing-dot { display: inline-block; animation: pulseDot 1s infinite ease-in-out; color: var(--accent-strong); }
@keyframes pulseDot { 50% { opacity: .25; transform: scale(.8); } }
#globalUsage { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions .icon-btn { font-size: 13px; font-weight: 700; }
.usage-bar { font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .topbar-actions #contextBtn, .topbar-actions #exportBtn { display: none; }
  .preset-toolbar { position: sticky; top: 67px; z-index: 3; }
  .message-usage { display: block; line-height: 1.5; }
}
.conversation-item { padding: 11px 12px 10px; }
.message-body { min-width: 0; }
.message-actions { gap: 3px; margin-top: 7px; }
.message-actions button { width: auto; min-width: 34px; height: 27px; padding: 0 7px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-size: 10px; }
.message-actions button:hover { background: var(--panel-2); color: var(--text); }

/* v2.1: wallet balance and per-conversation actions */
.balance-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 8px;
  margin: 0 0 11px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--panel-2);
}
.balance-main { min-width: 0; }
.balance-main span { display: block; color: var(--muted); font-size: 10px; }
.balance-main strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.balance-card small {
  grid-column: 1 / -1;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.balance-card.unavailable strong { color: var(--danger); }
.balance-refresh {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
}
.balance-refresh:hover { background: var(--accent-soft); color: var(--text); }
.balance-refresh.loading { animation: balanceSpin .75s linear infinite; }
@keyframes balanceSpin { to { transform: rotate(360deg); } }

.conversation-item {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  overflow: visible;
  border-radius: 12px;
  background: transparent;
}
.conversation-item:hover { background: var(--panel-2); }
.conversation-item.active { background: var(--accent-soft); }
.conversation-open {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 42px 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.conversation-open > small { flex: none; color: var(--muted); font-size: 9px; }
.conversation-menu-btn {
  position: absolute;
  top: 9px;
  right: 7px;
  z-index: 2;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  opacity: .38;
}
.conversation-item:hover .conversation-menu-btn,
.conversation-item.active .conversation-menu-btn,
.conversation-menu-btn[aria-expanded="true"] { opacity: 1; }
.conversation-menu-btn:hover { background: var(--panel-3); color: var(--text); }
.conversation-action-menu {
  position: absolute;
  top: 38px;
  right: 7px;
  z-index: 80;
  width: 118px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.conversation-action-menu button {
  width: 100%;
  height: 34px;
  padding: 0 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 12px;
}
.conversation-action-menu button:hover { background: var(--panel-2); }

@media (max-width: 760px) {
  .conversation-menu-btn { opacity: .8; }
  .conversation-action-menu { width: 132px; }
}


/* v2.2: fixed sidebar regions and reliable touch controls */
.sidebar-control, .footer-btn, .new-chat-btn, .conversation-menu-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-control { position: relative; z-index: 6; pointer-events: auto; }
body.sidebar-open { overscroll-behavior: none; }
@media (max-width: 760px) {
  .sidebar { height: 100dvh; max-height: 100dvh; overflow: hidden; }
  .sidebar-footer { padding-bottom: max(0px, env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) and (max-height: 680px) {
  .sidebar { padding-top: max(9px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .sidebar-header { padding-bottom: 9px; }
  .balance-card { margin-bottom: 7px; padding-top: 8px; padding-bottom: 8px; }
  .new-chat-btn { height: 40px; }
  .search-box { height: 36px; margin-top: 8px; margin-bottom: 5px; }
  .sidebar-footer { padding-top: 6px; gap: 0; }
  .footer-btn { padding-top: 8px; padding-bottom: 8px; }
}
