/* ===== Base Reset ===== */
@font-face { font-family: 'SiteFont'; src: url('Prompt-Medium.otf'); font-display: swap; }
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --bg: #ffffff;
    --bg-s: #f8f8f9;
    --bg-t: #f1f1f3;
    --border: #eaeaea;
    --border-d: #d4d4d4;
    --text: #1a1a2e;
    --text-s: #555;
    --text-m: #999;
    --text-muted: #999;
    --accent: #D97757;
    --accent-h: #c4654a;
    --accent-l: #fef3ef;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --r: 10px;
    --rs: 6px;
    --term-bg: #fff;
    --term-text: #1a1a2e;
    --term-sel: #fef3ef;
    --term-cur: #D97757;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'SiteFont', -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, 'Helvetica Neue', Arial, sans-serif;
    height: 100vh; height: 100dvh;
    overflow: hidden;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body.dark {
    --bg: #1a1a2e;
    --bg-s: #22223a;
    --bg-t: #2a2a42;
    --border: #333355;
    --border-d: #444466;
    --text: #e0e0e8;
    --text-s: #b0b0c0;
    --text-m: #777790;
    --text-muted: #777790;
    --accent-l: #2d2235;
    --danger: #f87171;
    --term-bg: #1a1a2e;
    --term-text: #e0e0e8;
    --term-sel: #3a2a45;
}
body.dark .terminal-output::-webkit-scrollbar-thumb { background: #444; }
body.dark .terminal-output::-webkit-scrollbar-thumb:hover { background: #555; }
body.dark .tab:hover { background: rgba(255,255,255,0.05); }
body.dark .CodeMirror { background: #1a1a2e; color: #e0e0e8; }
body.dark .CodeMirror-gutters { background: #22223a; border-color: #333355; }
body.dark .CodeMirror-linenumber { color: #555570; }
body.dark .CodeMirror-cursor { border-color: #e0e0e8; }
body.dark .CodeMirror-selected { background: #3a2a45; }
body.dark .CodeMirror-activeline-background { background: rgba(255,255,255,0.03); }

/* ===== Session Loading Overlay ===== */
.session-loading-overlay {
    position: fixed; inset: 0; z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.55); backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: sl-fadein 0.3s ease;
}
.session-loading-overlay.hidden { display: none; }
.sl-wrap { display: flex; flex-direction: column; align-items: center; }
.sl-spinner-wrap { width: 80px; height: 80px; animation: sl-rotate 1.5s linear infinite; }
.sl-svg { width: 80px; height: 80px; display: block; }
.sl-arc { stroke-dasharray: 214; animation: sl-dash 1.5s ease-in-out infinite; }
.session-loading-text { margin: 22px 0 18px; color: rgba(255,255,255,0.88); font-size: 14px; font-weight: 500; letter-spacing: 0.03em; }
.sl-dots { display: flex; gap: 6px; }
.sl-dots span { width: 5px; height: 5px; border-radius: 50%; background: rgba(255,255,255,0.5); animation: sl-bounce 1.2s ease-in-out infinite; }
.sl-dots span:nth-child(2) { animation-delay: 0.18s; }
.sl-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes sl-rotate { 100% { transform: rotate(360deg); } }
@keyframes sl-dash {
    0%   { stroke-dashoffset: 200; }
    50%  { stroke-dashoffset: 55;  }
    100% { stroke-dashoffset: 200; }
}
@keyframes sl-bounce {
    0%, 70%, 100% { transform: scale(0.75); opacity: 0.4; }
    35% { transform: scale(1.25); opacity: 1; }
}
@keyframes sl-fadein { from { opacity: 0; } to { opacity: 1; } }

/* ===== Layout ===== */
#app { display: flex; height: 100vh; height: 100dvh; }
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); }
#content { flex: 1; display: flex; min-height: 0; overflow: hidden; }

/* ===== Sidebar ===== */
#sidebar {
    width: 240px;
    background: var(--bg-s);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.2s;
    overflow: hidden;
}
#sidebar.collapsed { width: 48px; }
#sidebar.collapsed .logo-text,
#sidebar.collapsed .logo-wrap { display: none; }
#sidebar.collapsed .sidebar-toggle-btn { transform: rotate(180deg); margin: 0 auto; }

.sidebar-header {
    padding: 14px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.logo-text { font-size: 15px; font-weight: 700; color: var(--accent); letter-spacing: -0.02em; white-space: nowrap; }
.logo-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; }
.logo-svg { flex-shrink: 0; display: block; }
.logo-label { display: flex; align-items: baseline; gap: 0; white-space: nowrap; overflow: hidden; min-width: 0; }
#logo-span1 { font-size: 15px; font-weight: 800; color: var(--accent); letter-spacing: -0.02em; }
#logo-span2 { font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: -0.02em; }

.sidebar-toggle-btn {
    background: none; border: none; cursor: pointer; color: var(--text-m);
    padding: 4px 6px; border-radius: 4px; transition: all 0.15s;
    flex-shrink: 0; line-height: 0; display: flex; align-items: center; justify-content: center;
}
.sidebar-toggle-btn:hover { background: var(--bg-t); color: var(--text); }

.sidebar-body { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; transition: opacity 0.15s; }
.sidebar-section { padding: 10px 12px; }
.sidebar-sessions { flex: 1; min-height: 80px; overflow-y: auto; }

.sidebar-bottom {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
}

#btn-new {
    width: 100%; padding: 11px 0;
    background: linear-gradient(135deg, #ff8c5a 0%, var(--accent) 45%, #e05fa3 100%);
    background-size: 200% 200%;
    color: #fff;
    border: 2px solid rgba(255,255,255,0.28);
    border-radius: 12px; cursor: pointer;
    font-size: 13px; font-weight: 700; letter-spacing: 0.04em;
    display: flex; align-items: center; justify-content: center; gap: 7px;
    position: relative; overflow: hidden;
    /* Cartoon 3D raised shadow */
    box-shadow: 0 4px 0 rgba(155,50,15,0.32), 0 6px 20px rgba(217,119,87,0.38);
    transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s ease;
    animation: btnColorShift 5s ease-in-out infinite;
}
/* Animated gradient shift */
@keyframes btnColorShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}
/* Shimmer sweep */
#btn-new::before {
    content: ''; position: absolute;
    top: -60%; left: -85%; width: 55%; height: 220%;
    background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,0.26) 50%, transparent 70%);
    animation: btnShimmer 3.5s ease-in-out infinite;
    pointer-events: none;
}
@keyframes btnShimmer {
    0% { left: -85%; }
    60%, 100% { left: 130%; }
}
/* Floating sparkle stars */
.btn-new-spark {
    position: absolute; color: rgba(255,255,255,0.8);
    pointer-events: none; line-height: 1; user-select: none;
    animation: btnSparkFloat 2.4s ease-in-out infinite;
}
.btn-new-spark.s1 { left: 9%;  top: 18%;    font-size: 9px;  animation-delay: 0s;   }
.btn-new-spark.s2 { right: 13%; top: 22%;   font-size: 7px;  animation-delay: 0.8s; }
.btn-new-spark.s3 { left: 58%;  bottom: 16%; font-size: 6px; animation-delay: 1.5s; }
@keyframes btnSparkFloat {
    0%, 100% { opacity: 0.35; transform: translateY(0)    scale(0.8)  rotate(0deg);  }
    40%       { opacity: 1;   transform: translateY(-5px) scale(1.35) rotate(20deg); }
    70%       { opacity: 0.6; transform: translateY(-2px) scale(0.9)  rotate(-10deg);}
}
/* SVG icon spring rotation */
#btn-new svg { transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1); position: relative; z-index: 1; }
#btn-new span:last-child { position: relative; z-index: 1; }
/* Hover: lift, deepen 3D shadow */
#btn-new:hover { transform: translateY(-3px); box-shadow: 0 7px 0 rgba(155,50,15,0.32), 0 12px 28px rgba(217,119,87,0.5); }
#btn-new:hover svg { transform: rotate(90deg) scale(1.15); }
/* Active: press down, shadow collapses */
#btn-new:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 rgba(155,50,15,0.32), 0 2px 8px rgba(217,119,87,0.22);
    transition: transform 0.08s, box-shadow 0.08s;
}

/* ============ RECOVERY BANNER ============ */
.recovery-banner {
    margin-top: 8px;
    background: var(--bg-s);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 10px;
    padding: 10px 11px 10px;
    animation: recoveryIn 0.3s cubic-bezier(0.16,1,0.3,1);
}
.recovery-banner.hidden { display: none; }
@keyframes recoveryIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.recovery-top {
    display: flex; align-items: flex-start; gap: 8px; margin-bottom: 9px;
}
.recovery-icon {
    width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;
    background: rgba(217,119,87,0.12); color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    margin-top: 1px;
}
.recovery-text { flex: 1; min-width: 0; }
.recovery-title {
    font-size: 12px; font-weight: 700; color: var(--text);
    margin-bottom: 2px; line-height: 1.3;
}
.recovery-desc {
    font-size: 11px; color: var(--text-s); line-height: 1.4;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recovery-dismiss {
    flex-shrink: 0; width: 18px; height: 18px; padding: 0;
    background: none; border: none; color: var(--text-m); cursor: pointer;
    border-radius: 4px; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.recovery-dismiss:hover { background: var(--bg-t); color: var(--text); }
.recovery-actions { display: flex; gap: 6px; }
.recovery-btn-restore {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px;
    padding: 6px 10px; border-radius: 7px; border: none; cursor: pointer;
    font-size: 12px; font-weight: 600;
    background: linear-gradient(135deg, var(--accent), var(--accent-h));
    color: #fff; box-shadow: 0 2px 8px rgba(217,119,87,0.25);
    transition: all 0.2s;
}
.recovery-btn-restore:hover {
    box-shadow: 0 3px 12px rgba(217,119,87,0.4); transform: translateY(-1px);
}
.recovery-btn-dismiss {
    padding: 6px 10px; border-radius: 7px;
    background: none; border: 1px solid var(--border);
    color: var(--text-s); cursor: pointer; font-size: 12px; font-weight: 500;
    transition: all 0.15s;
}
.recovery-btn-dismiss:hover { background: var(--bg-t); color: var(--text); }

.section-title {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    color: var(--text-m); letter-spacing: 0.05em; margin-bottom: 6px;
}

#session-list { display: flex; flex-direction: column; gap: 1px; }

.session-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px; border-radius: var(--rs); cursor: pointer;
    font-size: 13px; color: var(--text-s); transition: all 0.1s;
}
.session-item:hover { background: var(--bg-t); color: var(--text); }
.session-item.active { background: var(--accent-l); color: var(--accent); font-weight: 500; }
.session-item.active .session-close { color: var(--accent); opacity: 0.5; }

.admin-other-session { flex-direction: column; align-items: flex-start; gap: 2px; position: relative; }
.admin-other-session .session-close { position: absolute; right: 8px; top: 8px; }
.admin-session-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; width: 100%; }
.admin-session-name { font-size: 12px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-session-meta { font-size: 10px; color: var(--text-m); font-family: monospace; }

.session-close {
    font-size: 16px; line-height: 1; color: var(--text-m);
    cursor: pointer; padding: 0 2px; border-radius: 3px; transition: all 0.1s;
}
.session-close:hover { color: var(--danger); background: #fef2f2; }

/* ===== Tab Bar ===== */
#tab-bar {
    display: flex; align-items: center;
    background: var(--bg-s); border-bottom: 1px solid var(--border);
    padding: 0 12px; height: 42px; flex-shrink: 0;
}
#tabs { display: flex; gap: 1px; overflow-x: auto; flex: 1; height: 100%; align-items: flex-end; }

.tab {
    display: flex; align-items: center; gap: 6px;
    padding: 7px 16px; border-radius: var(--r) var(--r) 0 0;
    cursor: pointer; font-size: 12px; color: var(--text-m);
    background: transparent; border: 1px solid transparent; border-bottom: none;
    white-space: nowrap; transition: all 0.1s;
}
.tab:hover { color: var(--text-s); background: rgba(255,255,255,0.6); }
.tab.active { background: var(--bg); color: var(--text); border-color: var(--border); font-weight: 500; }

.tab-close {
    font-size: 14px; line-height: 1; color: var(--text-m);
    cursor: pointer; border-radius: 3px; padding: 0 1px; transition: all 0.1s;
}
.tab-close:hover { color: var(--danger); background: #fef2f2; }

#tab-actions { display: flex; gap: 6px; padding-left: 12px; border-left: 1px solid var(--border); margin-left: 8px; }

.tab-action-btn {
    background: none; border: 1px solid var(--border); border-radius: var(--rs);
    padding: 5px 7px; cursor: pointer; color: var(--text-s);
    transition: all 0.1s; display: flex; align-items: center; justify-content: center; line-height: 0;
}
.tab-action-btn:hover { background: var(--bg-t); border-color: var(--border-d); }
.tab-action-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== Terminal Area ===== */
#terminal-area { flex: 1; position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--term-bg); }

#placeholder {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, calc(-50% - 120px));
    text-align: center; color: var(--text-m); pointer-events: none;
}
#terminal-area:has(#cmd-bar.centered) #placeholder { display: block; }
#terminal-area:not(:has(#cmd-bar.centered)) #placeholder { display: none; }
#main:has(#cmd-bar.centered) #btn-toggle-files { display: none; }

.placeholder-greeting { display: flex; align-items: center; gap: 12px; justify-content: center; flex-wrap: wrap; }
.placeholder-sparkle { width: 40px; height: 40px; color: var(--accent); flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
#placeholder-title { font-size: 28px; font-weight: 600; color: var(--text); letter-spacing: -0.02em; }

.terminal { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: none; }
.terminal.active { display: block; }

.terminal-output {
    position: absolute; inset: 0;
    overflow-y: auto; overflow-x: hidden;
    overflow-anchor: none; /* disable browser scroll anchoring — terminal manages its own scroll */
    -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    padding: 4px 0 80px; font-size: 13px; line-height: 1.4;
    font-family: 'JetBrains Mono','Cascadia Code','Fira Code','SF Mono','Consolas','Courier New',monospace;
    outline: none; background: var(--term-bg); color: var(--term-text);
    caret-color: var(--term-cur);
}

.term-hidden-input {
    position: absolute; left: 0; top: 0; width: 1px; height: 1px;
    opacity: 0; border: none; padding: 0; margin: 0; resize: none;
    overflow: hidden; outline: none; z-index: -1; font-size: 1px;
    color: transparent; background: transparent; caret-color: transparent;
    pointer-events: none;
}

.term-scrollback, .term-buffer { width: 100%; }
.term-line { white-space: pre; min-height: 1em; padding: 0 8px; }

.term-scrollback-hint {
    text-align: center;
    color: #94a3b8;
    font-size: 0.78em;
    padding: 5px 8px;
    user-select: none;
    font-style: italic;
    border-bottom: 1px solid #e2e8f0;
}
body.dark .term-scrollback-hint { color: #475569; border-bottom-color: #1e293b; }


.terminal-output::selection { background: var(--term-sel); }

/* Hide native scrollbar */
.terminal-output::-webkit-scrollbar { width: 0; height: 0; }
.terminal-output { scrollbar-width: none; -ms-overflow-style: none; }

/* ===== Custom Scrollbar ===== */
.custom-scrollbar {
    position: absolute;
    top: 6px;
    right: 4px;
    bottom: 6px;
    width: 6px;
    z-index: 50;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.terminal:hover .custom-scrollbar,
.custom-scrollbar.visible {
    opacity: 1;
}
.custom-scrollbar-track {
    position: absolute;
    inset: 0;
    border-radius: 3px;
    background: rgba(0,0,0,0.06);
    pointer-events: auto;
    cursor: pointer;
}
body.dark .custom-scrollbar-track {
    background: rgba(255,255,255,0.06);
}
.custom-scrollbar-thumb {
    position: absolute;
    left: 0; right: 0;
    min-height: 28px;
    border-radius: 3px;
    background: #D97757;
    opacity: 0.55;
    cursor: grab;
    pointer-events: auto;
    transition: opacity 0.15s, background 0.15s;
}
.custom-scrollbar-thumb:hover {
    opacity: 0.85;
    background: #D97757;
}
.custom-scrollbar-thumb.dragging,
.custom-scrollbar-thumb:active {
    opacity: 1;
    cursor: grabbing;
    background: #c4654a;
}
body.dark .custom-scrollbar-thumb {
    background: rgba(217,119,87,0.7);
    opacity: 0.7;
}
body.dark .custom-scrollbar-thumb:hover {
    opacity: 1;
    background: #D97757;
}

/* ===== Announcement Modal ===== */
.ann-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 3000;
}
.ann-modal {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 90%; max-width: 460px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.18);
    overflow: hidden;
    animation: ann-in .18s ease;
}
@keyframes ann-in { from { transform: scale(.94); opacity:0; } to { transform: scale(1); opacity:1; } }
.ann-modal-header {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border);
}
.ann-modal-header[data-type="info"]    { border-left: 4px solid #2563eb; }
.ann-modal-header[data-type="success"] { border-left: 4px solid #16a34a; }
.ann-modal-header[data-type="warning"] { border-left: 4px solid #d97706; }
.ann-modal-header[data-type="error"]   { border-left: 4px solid #dc2626; }
.ann-modal-icon { display: flex; align-items: center; flex-shrink: 0; }
.ann-icon-info    { color: #2563eb; }
.ann-icon-success { color: #16a34a; }
.ann-icon-warning { color: #d97706; }
.ann-icon-error   { color: #dc2626; }
.ann-modal-title {
    font-weight: 600; font-size: 16px;
    color: var(--text); flex: 1;
}
.ann-modal-body {
    padding: 16px 20px;
    color: var(--text); font-size: 14px; line-height: 1.65;
    white-space: pre-wrap; max-height: 280px; overflow-y: auto;
}
.ann-modal-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-s);
}
.ann-no-show-label {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; color: var(--text-s); cursor: pointer; user-select: none;
}
.ann-no-show-label input { cursor: pointer; }
.ann-modal-btn {
    background: var(--accent); color: #fff;
    border: none; border-radius: 7px;
    padding: 7px 22px; font-size: 14px; font-weight: 500;
    cursor: pointer; transition: background .15s;
}
.ann-modal-btn:hover { background: var(--accent-h); }

/* ===== Command Bar ===== */
#cmd-bar {
    position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
    width: calc(100% - 48px); max-width: 720px; z-index: 10;
    pointer-events: none; transition: bottom 0.3s, transform 0.3s;
}
#cmd-bar.centered { bottom: 50%; transform: translate(-50%, 50%); }

/* Idle Countdown */
.idle-countdown {
    pointer-events: auto; display: flex; align-items: center; gap: 5px;
    justify-content: center; margin-bottom: 6px;
    font-size: 11px; color: var(--text-m); opacity: 0.6;
}
.idle-countdown.hidden { display: none; }
.idle-countdown svg { flex-shrink: 0; }
.idle-countdown.idle-warn { color: var(--danger, #ef4444); opacity: 1; }

#cmd-bar-inner {
    pointer-events: auto; display: flex; flex-wrap: wrap; align-items: center;
    background: var(--bg); border: 1.5px solid var(--border);
    border-radius: 20px; padding: 0 6px 6px 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
    transition: border-color 0.2s, box-shadow 0.2s;
    position: relative; overflow: visible;
}
#cmd-bar-inner:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-l), 0 8px 24px rgba(0,0,0,0.08);
}
#cmd-bar-inner.drag-over { border-color: var(--accent); background: var(--accent-l); box-shadow: 0 4px 20px rgba(217,119,87,0.1), 0 0 0 3px rgba(217,119,87,0.06); }

.cmd-input-wrap { width: 100%; order: -1; position: relative; min-width: 0; padding: 14px 14px 6px; }

#cmd-input {
    width: 100%; border: none; outline: none; background: transparent;
    font-size: 14px; font-family: inherit; color: var(--text);
    line-height: 1.5; resize: none; height: calc(2lh); overflow-y: auto; padding: 0;
}
#cmd-input::placeholder { color: var(--text-m); font-family: inherit; font-size: 14px; opacity: 0.6; }

#cmd-stop {
    width: 34px; height: 34px; border: 1.5px solid var(--border); border-radius: 10px;
    background: none; color: var(--text-m); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: all 0.15s; margin-left: auto; margin-right: 4px;
}
#cmd-stop:hover { background: #fef2f2; color: var(--danger); border-color: #fca5a5; }
body.dark #cmd-stop:hover { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.4); }

#cmd-send {
    width: 34px; height: 34px; border: none; border-radius: 10px;
    background: var(--text); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}
#cmd-send:hover { background: var(--accent); transform: scale(1.06); box-shadow: 0 4px 12px rgba(217,119,87,0.35); }
body.dark #cmd-send { background: rgba(255,255,255,0.9); color: #111; }
body.dark #cmd-send:hover { background: var(--accent); color: #fff; }
#cmd-send.loading { pointer-events: none; opacity: 0.6; position: relative; color: transparent; transform: none; box-shadow: none; }
#cmd-send.loading::after {
    content: ''; position: absolute; width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
    border-radius: 50%; animation: cmd-spin 0.6s linear infinite;
}
body.dark #cmd-send.loading::after { border-color: rgba(0,0,0,0.2); border-top-color: #333; }
@keyframes cmd-spin { to { transform: rotate(360deg); } }

/* Command Bar Extras */
.cmd-model-select { display: none !important; }

/* Model Picker */
/* Model Picker */
.model-picker { position: relative; }
.model-picker.disabled .model-picker-trigger { opacity: 0.45; cursor: not-allowed; }
.model-picker.hidden { display: none; }

.model-picker-trigger {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 12px; border: 1.5px solid var(--border); border-radius: 10px;
    background: var(--bg-s); color: var(--text-s); font-size: 12px;
    cursor: pointer; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap; font-weight: 500; height: 34px; box-sizing: border-box;
}
.model-picker-trigger:hover {
    border-color: var(--accent);
    background: var(--accent-l);
    color: var(--accent);
    box-shadow: 0 2px 8px rgba(217, 119, 87, 0.12);
}
.model-picker-trigger svg:first-child {
    opacity: 0.7;
}
.model-picker-trigger svg:last-child {
    opacity: 0.5;
    transition: transform 0.2s;
}
.model-picker-trigger:hover svg:last-child {
    transform: translateY(1px);
}

/* Opus model trigger styling */
.model-picker-trigger.opus-selected {
    color: #d97706;
}
.model-picker-trigger.opus-selected:hover {
    color: #b45309;
}

.model-picker-popup {
    position: absolute; bottom: calc(100% + 12px); left: 50%; transform: translateX(-50%);
    background: var(--bg); border: 1px solid var(--border); border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.08);
    padding: 10px; min-width: 260px; max-width: 360px;
    z-index: 20; animation: modelPopIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    backdrop-filter: blur(8px);
}
.model-picker-popup.hidden { display: none; }
@keyframes modelPopIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(12px) scale(0.94);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

.model-card {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border-radius: 10px; cursor: pointer;
    font-size: 13px; color: var(--text-s); transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative; overflow: hidden;
    margin-bottom: 4px;
}
.model-card:last-child {
    margin-bottom: 0;
}
.model-card::before {
    content: '';
    position: absolute;
    left: 0; top: 50%; transform: translateY(-50%);
    width: 4px; height: 0;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
    transition: height 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.model-card:hover {
    background: var(--bg-t);
    color: var(--text);
    transform: translateX(4px);
}
.model-card:hover::before {
    height: 60%;
}
.model-card.active {
    background: var(--accent-l);
    color: var(--accent);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(217, 119, 87, 0.12);
}
.model-card.active::before {
    height: 80%;
}
.model-card svg {
    flex-shrink: 0;
    opacity: 0.5;
    transition: all 0.2s;
    width: 18px;
    height: 18px;
}
.model-card:hover svg {
    opacity: 0.75;
    transform: scale(1.1);
}
.model-card.active svg {
    opacity: 1;
    color: var(--accent);
    transform: scale(1.15);
}
.model-card span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Opus model styling - Golden theme */
.model-card-opus {
    color: #b45309;
    background: linear-gradient(135deg, rgba(254, 243, 199, 0.4) 0%, rgba(254, 243, 199, 0.1) 100%);
}
.model-card-opus:hover {
    background: linear-gradient(135deg, #fef3c7 0%, #fef9e7 100%);
    color: #92400e;
    box-shadow: 0 4px 12px rgba(217, 119, 6, 0.2);
}
.model-card-opus.active {
    background: linear-gradient(135deg, #fef3c7 0%, #fef9e7 100%);
    color: #b45309;
    font-weight: 700;
    box-shadow: 0 6px 16px rgba(217, 119, 6, 0.25);
}
.model-card-opus::before {
    background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 50%, #d97706 100%);
}
.model-card-opus svg {
    opacity: 0.7;
    color: #d97706;
    filter: drop-shadow(0 1px 3px rgba(217, 119, 6, 0.25));
}
.model-card-opus:hover svg {
    opacity: 0.85;
    filter: drop-shadow(0 2px 4px rgba(217, 119, 6, 0.3));
}
.model-card-opus.active svg {
    opacity: 1;
    color: #d97706;
    filter: drop-shadow(0 2px 6px rgba(217, 119, 6, 0.4));
}

.cmd-drop-hint {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; color: var(--accent); font-weight: 500;
    background: var(--accent-l); border-radius: 20px; z-index: 5;
    animation: cmdHintIn 0.15s ease;
}
.cmd-drop-hint.hidden { display: none; }
@keyframes cmdHintIn { from { opacity: 0; } to { opacity: 1; } }

#cmd-attach-btn {
    width: 34px; height: 34px; border: none; border-radius: 10px;
    background: none; color: var(--text-m); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background 0.15s, color 0.15s;
}
#cmd-attach-btn:hover { background: var(--bg-t); color: var(--text); }

#cmd-attachments {
    display: flex; flex-wrap: wrap; gap: 6px; width: 100%;
    padding: 10px 12px 0; order: -1;
}
#cmd-attachments:empty { display: none; }

.cmd-attach-card {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 8px 4px 10px; background: var(--bg-s);
    border: 1px solid var(--border); border-radius: var(--rs);
    font-size: 12px; color: var(--text-s); animation: cmdCardIn 0.15s ease;
}
.cmd-attach-card.uploading { opacity: 0.6; }
@keyframes cmdCardIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.cmd-attach-card-spinner {
    width: 12px; height: 12px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: cmd-spin 0.6s linear infinite;
}
.cmd-attach-card-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-attach-card-remove {
    background: none; border: none; cursor: pointer; color: var(--text-m);
    font-size: 14px; line-height: 1; padding: 0 2px; border-radius: 3px;
    transition: color 0.1s;
}
.cmd-attach-card-remove:hover { color: var(--danger); }

/* ===== File Manager Panel ===== */
#file-panel {
    width: 320px; border-left: 1px solid var(--border); background: var(--bg);
    display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden;
}
#file-panel.hidden { display: none; }

/* ===== Mobile Editor Bottom Bar ===== */
.editor-mobile-bottombar {
    display: none;
}

.file-panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.file-panel-title { font-size: 13px; font-weight: 600; color: var(--text); }
.file-panel-close {
    background: none; border: none; font-size: 18px; color: var(--text-m);
    cursor: pointer; padding: 2px 6px; border-radius: 4px; line-height: 1;
}
.file-panel-close:hover { background: var(--bg-t); color: var(--text); }

.file-toolbar {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.file-toolbar input {
    flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--border);
    border-radius: var(--rs); font-size: 12px; outline: none; background: var(--bg);
    color: var(--text); transition: border-color 0.15s;
}
.file-toolbar input:focus { border-color: var(--border-d); }

.file-btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 5px 10px; border: 1px solid var(--border); border-radius: var(--rs);
    background: var(--bg); color: var(--text-s); font-size: 12px;
    cursor: pointer; white-space: nowrap; transition: all 0.1s;
}
.file-btn:hover { background: var(--bg-t); border-color: var(--border-d); }
.file-btn-upload { background: var(--accent); color: #fff; border-color: var(--accent); }
.file-btn-upload:hover { background: var(--accent-h); border-color: var(--accent-h); }

.file-upload-bar {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    padding: 8px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#upload-status { font-size: 11px; color: var(--text-m); }

.upload-progress-wrap {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.upload-progress-wrap.hidden { display: none; }
.upload-progress-bar {
    flex: 1; height: 4px; background: var(--bg-t); border-radius: 2px; overflow: hidden;
}
.upload-progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.2s; width: 0; }
.upload-progress-text { font-size: 11px; color: var(--text-m); min-width: 30px; text-align: right; }

.file-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.file-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px; cursor: pointer; font-size: 13px;
    color: var(--text-s); transition: background 0.1s;
}
.file-item:hover { background: var(--bg-t); }
.file-item.is-dir { font-weight: 500; color: var(--text); }
.file-item.file-changed { color: var(--warning); }
.file-icon { width: 16px; text-align: center; flex-shrink: 0; font-size: 14px; color: var(--text-s); }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 11px; color: var(--text-m); flex-shrink: 0; }
.file-actions { display: none; gap: 3px; flex-shrink: 0; }
.file-item:hover .file-actions { display: flex; }
.file-action-btn {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 1px 5px; border: 1px solid var(--border-d); border-radius: 3px;
    background: var(--bg); color: var(--text-m); cursor: pointer;
    font-size: 10px; transition: all 0.15s; line-height: 1.4; white-space: nowrap;
}
.file-action-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.file-action-btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.file-select-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.file-select-bar.hidden { display: none; }
.file-select-all-label {
    display: flex; align-items: center; gap: 5px; font-size: 12px;
    color: var(--text-s); cursor: pointer; user-select: none;
}
.file-select-count { font-size: 11px; color: var(--text-m); }
.file-btn-danger {
    background: var(--danger, #e94560); color: #fff; border-color: var(--danger, #e94560);
}
.file-btn-danger:hover { opacity: 0.85; }
.file-item-checkbox {
    width: 14px; height: 14px; flex-shrink: 0; cursor: pointer; accent-color: var(--accent);
}

/* ===== Modals ===== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center; z-index: 100;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}
.modal-overlay.hidden { display: none; }
.modal-box {
    background: var(--bg); border-radius: 16px; padding: 28px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.15); min-width: 380px; max-width: 90vw;
    animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-title {
    font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 24px;
    padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.modal-actions {
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes slideInFromRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}
@keyframes modalSlideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.settings-field { margin-bottom: 16px; }
.settings-field label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 8px; }
.settings-optional { color: var(--text-m); font-weight: 400; font-size: 12px; }
.settings-field input,
.settings-field select {
    width: 100%; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 13px; outline: none;
    background: var(--bg); color: var(--text); transition: border-color 0.2s, box-shadow 0.2s;
}
.settings-field input:focus,
.settings-field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(217, 119, 87, 0.1);
}
.settings-save-btn { background: var(--accent) !important; color: #fff !important; border-color: var(--accent) !important; }
.settings-save-btn:hover { background: var(--accent-h) !important; }

/* ===== Balance Tab ===== */
.bal-card {
    background: linear-gradient(140deg, var(--accent) 0%, var(--accent-h) 55%, #f59e0b 100%);
    border-radius: 14px;
    padding: 18px 18px 0;
    margin-bottom: 14px;
    color: #fff;
    position: relative;
    overflow: hidden;
    box-shadow: 0 6px 24px rgba(217, 119, 87, 0.32);
}
.bal-card::before {
    content: '';
    position: absolute;
    top: -40px; right: -40px;
    width: 120px; height: 120px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    pointer-events: none;
}
.bal-card::after {
    content: '';
    position: absolute;
    bottom: 30px; left: -25px;
    width: 90px; height: 90px;
    border-radius: 50%;
    background: rgba(255,255,255,0.07);
    pointer-events: none;
}
.bal-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    position: relative;
    z-index: 1;
}
.bal-card-label {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 5px;
}
.bal-refresh-btn {
    width: 26px; height: 26px;
    border-radius: 7px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}
.bal-refresh-btn:hover {
    background: rgba(255,255,255,0.35);
    transform: rotate(180deg);
}
.bal-amount-row {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 16px;
    position: relative;
    z-index: 1;
}
.bal-currency {
    font-size: 20px;
    font-weight: 700;
    opacity: 0.9;
    line-height: 1;
    margin-bottom: -2px;
}
.bal-value {
    font-size: 40px;
    font-weight: 800;
    letter-spacing: -1.5px;
    line-height: 1;
}
.bal-unit {
    font-size: 14px;
    font-weight: 600;
    opacity: 0.75;
    margin-bottom: 4px;
}
.bal-card-actions {
    display: flex;
    gap: 1px;
    background: rgba(0,0,0,0.15);
    border-radius: 0 0 14px 14px;
    margin: 0 -18px;
    overflow: hidden;
    position: relative;
    z-index: 1;
}
.bal-act-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 500;
    border: none;
    background: rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.92);
    cursor: pointer;
    transition: background 0.2s;
}
.bal-act-btn:hover { background: rgba(255,255,255,0.22); color: #fff; }
.bal-act-buy {
    background: rgba(255,255,255,0.18);
    font-weight: 600;
}
.bal-act-buy:hover { background: rgba(255,255,255,0.28); }

/* Redeem section */
.bal-redeem {
    background: var(--bg-s);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 0;
}
.bal-redeem-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}
.bal-redeem-row {
    display: flex;
    gap: 8px;
}
.bal-redeem-row input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.bal-redeem-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-l);
}
.bal-redeem-row input::placeholder { color: var(--text-m); opacity: 0.6; }
.bal-redeem-row button {
    flex-shrink: 0;
    padding: 9px 18px;
    border-radius: 8px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.bal-redeem-row button:hover { background: var(--accent-h); }
.bal-redeem-status {
    font-size: 12px;
    margin-top: 8px;
    display: block;
    color: var(--text-m);
}
.newapi-keys-list { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.newapi-key-item { display: flex; align-items: center; gap: 6px; padding: 4px 0; font-size: 12px; }
.newapi-key-name { color: var(--text-s); min-width: 70px; }
.newapi-key-val { flex: 1; font-family: monospace; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.newapi-key-copy { cursor: pointer; color: var(--accent); background: none; border: none; font-size: 11px; padding: 2px 6px; flex-shrink: 0; }
.newapi-key-copy:hover { text-decoration: underline; }

.newapi-logs-panel { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 16px; max-height: 300px; overflow-y: auto; }
.newapi-log-item {
    display: flex;
    align-items: center;
    padding: 9px 12px;
    font-size: 12px;
    border-radius: 8px;
    gap: 8px;
    margin-bottom: 5px;
    background: var(--bg);
    border: 1px solid var(--border);
    transition: all 0.2s;
}
.newapi-log-item:hover {
    border-color: var(--accent);
    background: var(--bg-s);
    transform: translateX(2px);
}
.newapi-log-model { color: var(--accent); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.newapi-log-tokens { color: var(--text-m, #999); font-size: 10px; flex-shrink: 0; font-family: monospace; background: var(--bg-t); padding: 2px 6px; border-radius: 4px; }
.newapi-log-cost { color: #e74c3c; flex-shrink: 0; font-weight: 700; font-family: monospace; }
.newapi-log-time { color: var(--text-m); flex-shrink: 0; font-size: 10px; opacity: 0.7; }
.newapi-log-type1 { color: #2ecc71; font-weight: 600; flex: 1; }
.newapi-logs-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 0 4px;
}
.newapi-logs-pager button {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-s);
    transition: all 0.3s;
    font-weight: 600;
}
.newapi-logs-pager button:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    transform: scale(1.08);
    box-shadow: 0 2px 6px rgba(217, 119, 87, 0.25);
}
.newapi-logs-pager button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}
.newapi-logs-pager button:disabled:hover {
    background: var(--bg);
    color: var(--text-s);
    border-color: var(--border);
    box-shadow: none;
}
.newapi-logs-pager span {
    font-size: 12px;
    color: var(--text);
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

/* ===== Settings Modal ===== */
.settings-modal-overlay {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(0,0,0,0.45); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    animation: fadeIn .15s ease;
}
.settings-modal-overlay.hidden { display: none; }
.settings-modal-box {
    width: 720px; max-width: calc(100vw - 32px);
    height: 520px; max-height: calc(100vh - 64px);
    background: var(--bg); border-radius: 16px;
    display: flex; flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2), 0 4px 16px rgba(0,0,0,0.08);
    overflow: hidden;
    animation: modalSlideIn .22s cubic-bezier(0.16,1,0.3,1);
    border: 1px solid var(--border);
}
.settings-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.settings-modal-title-wrap { display: flex; align-items: center; gap: 8px; color: var(--text); }
.settings-modal-title-wrap svg { color: var(--accent); flex-shrink: 0; }
.settings-modal-title { font-size: 15px; font-weight: 600; color: var(--text); }
.settings-modal-close {
    width: 28px; height: 28px; border: none; border-radius: 6px;
    background: none; color: var(--text-m); font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; line-height: 1;
    transition: all .15s;
}
.settings-modal-close:hover { background: var(--bg-t); color: var(--text); }
.settings-modal-body { flex: 1; display: flex; min-height: 0; overflow: hidden; }
/* Left nav */
.settings-nav {
    width: 160px; flex-shrink: 0; padding: 10px 8px;
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 2px;
    overflow-y: auto; background: var(--bg-s);
}
.settings-nav-item {
    display: flex; align-items: center; gap: 9px;
    padding: 9px 11px; border-radius: 8px; border: none;
    background: none; color: var(--text-s); font-size: 13px;
    cursor: pointer; text-align: left; width: 100%;
    transition: all .15s; font-family: inherit;
}
.settings-nav-item:hover { background: var(--bg-t); color: var(--text); }
.settings-nav-item.active { background: var(--accent-l); color: var(--accent); font-weight: 500; }
.settings-nav-item svg { flex-shrink: 0; opacity: 0.55; transition: opacity .15s; }
.settings-nav-item.active svg { opacity: 1; }
/* Right content */
.settings-content { flex: 1; overflow-y: auto; padding: 24px; min-width: 0; }
.settings-tab { display: none; }
.settings-tab.active { display: block; }
.settings-tab-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.settings-tab-desc { font-size: 12px; color: var(--text-s); margin-bottom: 20px; }
.settings-tab-footer { display: flex; align-items: center; gap: 12px; padding-top: 20px; border-top: 1px solid var(--border); margin-top: 20px; }

/* ===== Token Tab ===== */
.tokens-topbar {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px;
}
.tokens-add-btn {
    display: flex; align-items: center; gap: 5px; padding: 7px 14px;
    border-radius: 8px; border: 1px solid var(--accent); background: var(--accent-l);
    color: var(--accent); font-size: 12px; font-weight: 600; cursor: pointer;
    transition: all .15s; white-space: nowrap; flex-shrink: 0;
}
.tokens-add-btn:hover { background: var(--accent); color: #fff; }

/* Token card list */
.tc-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.tc-card {
    border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
    overflow: hidden; transition: border-color .2s, box-shadow .2s;
}
.tc-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.tc-card.tc-active { border-color: #22c55e; box-shadow: 0 0 0 1px rgba(34,197,94,0.15); }
.tc-body { padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; }

/* Status dot */
.tc-dot {
    width: 7px; height: 7px; border-radius: 50%; background: var(--border);
    flex-shrink: 0; margin-top: 6px;
}
.tc-dot.tc-dot-on { background: #22c55e; }
.tc-dot.tc-dot-active { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-l); }

/* Info column */
.tc-info { flex: 1; min-width: 0; }
.tc-name-row { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; }
.tc-name { font-size: 13px; font-weight: 600; color: var(--text); }
.tc-badge {
    font-size: 10px; padding: 1px 7px; border-radius: 8px; font-weight: 600; flex-shrink: 0;
}
.tc-badge-active { background: var(--accent); color: #fff; }
.tc-badge-on { background: #dcfce7; color: #16a34a; }
.tc-badge-off { background: var(--bg-t); color: var(--text-m); }
body.dark .tc-badge-on { background: #14532d; color: #4ade80; }

/* Key row */
.tc-key-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.tc-key {
    font-family: monospace; font-size: 11px; color: var(--text-m);
    background: var(--bg-t); padding: 2px 8px; border-radius: 5px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
.tc-copy {
    font-size: 10px; padding: 2px 9px; border: 1px solid var(--border); border-radius: 5px;
    background: var(--bg); color: var(--accent); cursor: pointer; flex-shrink: 0;
    transition: all .15s;
}
.tc-copy:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Meta row */
.tc-meta { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.tc-group-badge {
    font-size: 10px; padding: 2px 8px; border-radius: 6px;
    background: var(--accent-l); color: var(--accent); font-weight: 500;
}
.tc-ratio {
    font-size: 10px; padding: 2px 7px; border-radius: 5px;
    background: var(--bg-t); color: var(--text-m); font-weight: 500;
}
.tc-ratio.fast { background: #fef2f2; color: #dc2626; }
.tc-ratio.slow { background: #f0fdf4; color: #16a34a; }
body.dark .tc-ratio.fast { background: #450a0a; color: #f87171; }
body.dark .tc-ratio.slow { background: #052e16; color: #4ade80; }

/* Actions column */
.tc-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.tc-btn {
    font-size: 11px; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text-s); cursor: pointer; transition: all .15s;
    white-space: nowrap;
}
.tc-btn:hover { background: var(--bg-t); color: var(--text); }
.tc-btn-use { color: var(--accent); border-color: var(--accent); background: var(--accent-l); }
.tc-btn-use:hover { background: var(--accent); color: #fff; }
.tc-btn-del:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* Empty state */
.tc-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 8px; padding: 32px 16px; color: var(--text-m); font-size: 13px;
}

/* API endpoint info */
.tc-api-info {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin-top: 4px;
    background: var(--bg-s); border: 1px solid var(--border); border-radius: 8px;
}
.tc-api-label { color: var(--text-m); flex-shrink: 0; font-size: 12px; font-weight: 500; }
.tc-api-url {
    flex: 1; font-family: monospace; font-size: 11px; color: var(--accent);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gs-model-select { width: 100%; }
.gs-model-cards { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ===== Token Inline Form ===== */
.token-inline-form {
    margin-top: 14px; padding: 16px 16px 14px;
    background: var(--bg-s); border-radius: 12px; border: 1px solid var(--border);
    animation: fadeIn .15s ease;
}
.token-inline-form.hidden { display: none; }
.token-inline-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.token-inline-title { font-size: 13px; font-weight: 600; color: var(--text); }
.token-inline-cancel {
    width: 24px; height: 24px; border: none; border-radius: 5px;
    background: none; color: var(--text-m); cursor: pointer; font-size: 17px;
    line-height: 1; display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.token-inline-cancel:hover { background: var(--bg-t); color: var(--text); }
.token-inline-field { margin-bottom: 12px; }
.token-inline-field label {
    display: block; font-size: 11px; font-weight: 600; color: var(--text-m);
    margin-bottom: 7px; text-transform: uppercase; letter-spacing: 0.05em;
}
.token-inline-field input {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 13px; background: var(--bg); color: var(--text);
    outline: none; transition: border-color .2s, box-shadow .2s; font-family: inherit;
}
.token-inline-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(217,119,87,0.1); }
.token-inline-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ===== Group Selector Cards ===== */
#token-form-groups { display: flex; flex-direction: column; gap: 6px; }
.grp-card {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 13px; border: 1.5px solid var(--border);
    border-radius: 10px; cursor: pointer;
    background: var(--bg); transition: all .15s;
}
.grp-card:hover { border-color: var(--border-d); background: var(--bg-t); }
.grp-card.active {
    border-color: var(--accent); background: var(--accent-l);
    box-shadow: 0 0 0 3px rgba(217,119,87,0.08);
}
.grp-card-icon {
    width: 34px; height: 34px; border-radius: 8px;
    background: var(--bg-t); display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; color: var(--text-m); transition: all .15s;
}
.grp-card.active .grp-card-icon { background: rgba(217,119,87,0.12); color: var(--accent); }
.grp-card-info { flex: 1; min-width: 0; }
.grp-card-name { font-size: 13px; font-weight: 600; color: var(--text); }
.grp-card.active .grp-card-name { color: var(--accent); }
.grp-card-speed { font-size: 11px; color: var(--text-m); margin-top: 2px; }
.grp-card-speed.fast { color: #e55; }
.grp-card-speed.slow { color: #22c55e; }
.grp-card-check {
    width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--border);
    flex-shrink: 0; transition: all .15s; display: flex; align-items: center; justify-content: center;
}
.grp-card.active .grp-card-check { border-color: var(--accent); background: var(--accent); }
.grp-card.active .grp-card-check::after {
    content: ''; display: block; width: 6px; height: 4px;
    border-left: 1.5px solid #fff; border-bottom: 1.5px solid #fff;
    transform: rotate(-45deg) translateY(-1px);
}

.session-modal-box { min-width: 480px; max-width: 560px; }
.session-modal-field { margin-bottom: 20px; }
.session-modal-field label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px; letter-spacing: 0.02em; }
.session-modal-desc { font-size: 12px; color: var(--text-s); margin-bottom: 12px; }
#session-name-input {
    width: 100%; padding: 12px 16px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; outline: none;
    background: var(--bg); color: var(--text); transition: border-color .2s, box-shadow .2s;
}
#session-name-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(217,119,87,0.1); }
#session-model-cards .model-card { flex: 1 1 calc(50% - 4px); min-width: 0; }

/* ===== File Editor Overlay ===== */
.file-editor-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center; z-index: 200;
    backdrop-filter: blur(2px);
}
.file-editor-overlay.hidden { display: none; }
.file-editor-container {
    width: 90vw; height: 85vh; background: var(--bg);
    border-radius: var(--r); display: flex; flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15); overflow: hidden;
}
.file-editor-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.file-editor-title { font-size: 13px; font-weight: 600; color: var(--text); }
.file-editor-actions { display: flex; align-items: center; gap: 6px; }
.editor-status { font-size: 11px; color: var(--text-m); margin-right: 4px; }
.editor-act-btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 5px 12px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg-s); color: var(--text-s); font-size: 12px;
    cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.editor-act-btn:hover { background: var(--bg-t); border-color: var(--border-d); }
.editor-act-btn svg { flex-shrink: 0; }
.editor-act-save { background: var(--accent); color: #fff; border-color: var(--accent); }
.editor-act-save:hover { background: var(--accent-h); border-color: var(--accent-h); }
.editor-act-close:hover { color: var(--danger); border-color: var(--danger); }
/* Floating close button only shown on mobile via @media */
.editor-mobile-close { display: none; }
.file-editor-cm { flex: 1; overflow: hidden; }
.file-editor-cm .CodeMirror {
    height: 100%; font-size: 13px; line-height: 1.5;
    font-family: 'JetBrains Mono','Cascadia Code','Fira Code','SF Mono','Consolas',monospace;
}

/* ===== Toast ===== */
#toast-container {
    position: fixed; top: 20px; right: 20px; z-index: 9999;
    display: flex; flex-direction: column; gap: 10px;
    max-width: 340px; pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 16px; border-radius: 14px;
    background: var(--bg); border: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0,0,0,0.10), 0 1px 4px rgba(0,0,0,0.06);
    font-size: 13px; color: var(--text);
    animation: toastIn 0.35s cubic-bezier(0.16,1,0.3,1) both;
    backdrop-filter: blur(12px);
    position: relative; overflow: hidden; min-width: 260px;
}
/* Left accent strip */
.toast::before {
    content: ''; position: absolute;
    left: 0; top: 0; bottom: 0; width: 3px;
}
.toast-type-success::before { background: #22c55e; }
.toast-type-error::before { background: var(--danger); }
.toast-type-warning::before { background: #f59e0b; }
.toast-type-info::before { background: var(--accent); }
/* Progress bar */
.toast-progress {
    position: absolute; bottom: 0; left: 0; right: 0; height: 2px;
    transform-origin: left; animation: toastProgress linear both;
}
.toast-type-success .toast-progress { background: rgba(34,197,94,0.45); }
.toast-type-error .toast-progress { background: rgba(239,68,68,0.45); }
.toast-type-warning .toast-progress { background: rgba(245,158,11,0.45); }
.toast-type-info .toast-progress { background: rgba(217,119,87,0.45); }
@keyframes toastProgress { from { transform: scaleX(1); } to { transform: scaleX(0); } }
/* Icon */
.toast-icon {
    flex-shrink: 0; width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; margin-top: 1px;
}
.toast-icon.toast-success { background: #dcfce7; color: #16a34a; }
.toast-icon.toast-error { background: #fee2e2; color: #dc2626; }
.toast-icon.toast-warning { background: #fef3c7; color: #d97706; }
.toast-icon.toast-info { background: var(--accent-l); color: var(--accent); }
.toast-icon svg { width: 15px; height: 15px; }
body.dark .toast-icon.toast-success { background: rgba(34,197,94,0.12); color: #4ade80; }
body.dark .toast-icon.toast-error { background: rgba(239,68,68,0.12); color: #f87171; }
body.dark .toast-icon.toast-warning { background: rgba(245,158,11,0.12); color: #fbbf24; }
/* Content */
.toast-body { flex: 1; min-width: 0; }
.toast-message { line-height: 1.45; word-break: break-word; display: block; padding-top: 7px; }
/* Close button */
.toast-close {
    flex-shrink: 0; width: 20px; height: 20px; margin-top: 5px;
    border: none; background: none; color: var(--text-m);
    cursor: pointer; border-radius: 5px; font-size: 15px; padding: 0;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.toast-close:hover { background: var(--bg-t); color: var(--text); }
.toast-out { animation: toastOut 0.28s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(calc(100% + 24px)); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(calc(100% + 24px)); } }

/* ===== Watermark ===== */
.has-watermark::after {
    content: attr(data-watermark); position: fixed; bottom: 8px; right: 12px;
    font-size: 11px; color: rgba(0,0,0,0.06); pointer-events: none; z-index: 1;
}

/* ===== History ===== */
.sidebar-history { overflow-y: auto; max-height: 200px; scrollbar-width: thin; scrollbar-color: var(--border-d) transparent; }
.sidebar-history::-webkit-scrollbar { width: 5px; }
.sidebar-history::-webkit-scrollbar-track { background: transparent; }
.sidebar-history::-webkit-scrollbar-thumb { background: var(--border-d); border-radius: 3px; }
.sidebar-history::-webkit-scrollbar-thumb:hover { background: var(--text-m); }
#history-list { display: flex; flex-direction: column; gap: 1px; }
.history-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px; border-radius: var(--rs); cursor: default;
    font-size: 12px; color: var(--text-m); transition: background 0.1s;
}
.history-item:hover { background: var(--bg-t); }
.history-restore {
    font-size: 11px; color: var(--accent); cursor: pointer;
    padding: 2px 6px; border-radius: 3px; transition: background 0.1s;
}
.history-restore:hover { background: var(--accent-l); }

.storage-info { padding: 8px 0 0; }
.storage-bar-wrap { display: flex; align-items: center; gap: 6px; }
.storage-bar {
    flex: 1; height: 4px; background: var(--bg-t); border-radius: 2px; overflow: hidden;
}
.storage-bar > div { height: 100%; background: var(--accent); border-radius: 2px; }
.storage-text { font-size: 10px; color: var(--text-m); }

/* Wallet Card - In sidebar bottom */
.wallet-card {
    margin: 8px 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: linear-gradient(135deg, #fff 0%, #fafafa 100%);
    border: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    position: relative;
    overflow: hidden;
}
body.dark .wallet-card {
    background: linear-gradient(135deg, #2a2a42 0%, #22223a 100%);
    border-color: #3a3a52;
}
.wallet-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--accent-h));
    opacity: 0;
    transition: opacity 0.3s;
}
.wallet-card:hover::before {
    opacity: 1;
}
.wallet-card:hover {
    background: linear-gradient(135deg, #fff 0%, #f5f5f5 100%);
    border-color: var(--accent);
    box-shadow: 0 3px 10px rgba(217, 119, 87, 0.12);
    transform: translateY(-1px);
}
body.dark .wallet-card:hover {
    background: linear-gradient(135deg, #2d2d45 0%, #25253d 100%);
    border-color: var(--accent);
}
.wallet-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-h) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: all 0.3s;
    box-shadow: 0 2px 6px rgba(217, 119, 87, 0.2);
}
.wallet-card:hover .wallet-icon {
    transform: scale(1.08) rotate(3deg);
    box-shadow: 0 3px 10px rgba(217, 119, 87, 0.3);
}
.wallet-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.wallet-label {
    font-size: 10px;
    color: var(--text-m);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.7;
}
.wallet-amount {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wallet-amount.low { color: var(--danger); }
.wallet-arrow {
    color: var(--text-m);
    flex-shrink: 0;
    transition: all 0.3s;
    opacity: 0.3;
}
.wallet-card:hover .wallet-arrow {
    opacity: 0.9;
    transform: translateX(3px);
    color: var(--accent);
}

/* ===== Sidebar User Section ===== */
.sidebar-user {
    padding: 10px 12px; display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.sidebar-user-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-h));
    color: #fff; font-size: 12px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; text-transform: uppercase; letter-spacing: 0;
    box-shadow: 0 2px 6px rgba(217,119,87,0.25);
}
.sidebar-user-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.sidebar-username { font-size: 12px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-balance { font-size: 11px; color: var(--accent); cursor: pointer; font-weight: 600; display: none; }
.sidebar-balance.low { color: var(--danger); }
.sidebar-user-actions { display: flex; gap: 1px; flex-shrink: 0; }
.su-btn {
    width: 28px; height: 28px; border: none; border-radius: 6px;
    background: none; color: var(--text-m); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: all 0.15s; line-height: 0; padding: 0;
    text-decoration: none;
}
.su-btn:hover { background: var(--bg-t); color: var(--accent); }
.su-logout:hover { color: var(--danger) !important; }

/* ===== Collapsed Sidebar ===== */
#sidebar.collapsed .sidebar-body { opacity: 0; pointer-events: none; }
#sidebar.collapsed .wallet-card { display: none; }
#sidebar.collapsed .sidebar-user-info { display: none; }
#sidebar.collapsed .sidebar-user-actions { display: none; }
#sidebar.collapsed .sidebar-user { justify-content: center; }

/* ===== Mobile Sidebar ===== */
.mobile-menu-btn {
    display: none; background: none; border: none; color: var(--text-s);
    cursor: pointer; padding: 4px; border-radius: 4px; line-height: 0;
}
.mobile-menu-btn:hover { background: var(--bg-t); }
.mobile-sidebar-close {
    display: none; background: none; border: none; font-size: 20px;
    color: var(--text-m); cursor: pointer; line-height: 1; padding: 2px 6px;
}
.mobile-sidebar-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.3); z-index: 49;
}

/* ===== Mobile Keyboard ===== */
.mobile-kb { display: none; }
.mobile-kb-toggle {
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--bg); border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    color: var(--text-s); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.mobile-kb-panel {
    display: none; flex-wrap: wrap; gap: 6px;
    padding: 8px; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--r); box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 6px;
}
.mobile-kb-panel.open { display: flex; }
.mobile-kb-key {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--rs);
    background: var(--bg); color: var(--text-s); cursor: pointer;
    font-size: 12px; display: flex; align-items: center; justify-content: center;
    transition: all 0.1s;
}
.mobile-kb-key:hover { background: var(--bg-t); }
.mobile-kb-enter { color: var(--success); border-color: var(--success); }
.mobile-kb.kb-hold .mobile-kb-toggle { animation: kb-pulse 0.6s ease infinite; }
.mobile-kb.kb-dragging { opacity: 0.85; }
.mobile-kb.kb-dragging .mobile-kb-toggle { box-shadow: 0 4px 16px rgba(0,0,0,0.15); transform: scale(1.1); }
@keyframes kb-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* ===== Desktop: hide mobile elements ===== */
@media (min-width: 769px) {
    .mobile-menu-btn, .mobile-sidebar-close, .mobile-kb { display: none !important; }
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
    #sidebar {
        position: fixed; left: -260px; top: 0; bottom: 0;
        width: 260px; z-index: 50; transition: left 0.25s;
        box-shadow: none;
    }
    #sidebar.mobile-open { left: 0; box-shadow: 4px 0 16px rgba(0,0,0,0.1); }
    #sidebar.collapsed { width: 260px; left: -260px; }
    #sidebar.collapsed.mobile-open { left: 0; }
    #sidebar.collapsed .sidebar-body { opacity: 1; pointer-events: auto; }
    #sidebar.collapsed .logo-wrap { display: flex; }
    #sidebar.collapsed .sidebar-user { display: flex; }
    #sidebar.collapsed .sidebar-user-info { display: flex; }
    #sidebar.collapsed .sidebar-user-actions { display: flex; }
    #sidebar.collapsed .sidebar-history { display: block; }
    #sidebar.collapsed .sidebar-toggle-btn { display: none; }

    .mobile-menu-btn { display: flex; }
    .mobile-sidebar-close { display: block; }
    .sidebar-toggle-btn { display: none; }
    #sidebar.mobile-open ~ .mobile-sidebar-backdrop,
    .mobile-sidebar-backdrop.active { display: block; }

    #tab-bar { padding: 0 8px; height: 38px; }
    #tab-actions { padding-left: 8px; margin-left: 4px; }

    #cmd-bar { width: calc(100% - 24px); bottom: 12px; }
    #cmd-bar.centered { bottom: 50%; }
    #cmd-bar-inner { border-radius: 16px; }
    .cmd-input-wrap { padding: 12px 12px 4px; }

    #placeholder { transform: translate(-50%, calc(-50% - 140px)); }
    #placeholder-title { font-size: 22px; }
    .placeholder-sparkle { width: 32px; height: 32px; }

    #file-panel {
        position: fixed; inset: 0; width: 100%; z-index: 60;
        border-left: none;
        animation: slideInFromRight 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Mobile file panel header - larger touch targets */
    .file-panel-header {
        padding: 14px 16px;
        min-height: 52px;
    }
    .file-panel-title {
        font-size: 15px;
    }
    .file-panel-close {
        font-size: 24px;
        padding: 4px 8px;
        min-width: 44px;
        min-height: 44px;
        display: flex; align-items: center; justify-content: center;
    }

    /* Mobile toolbar - single compact row with icon buttons */
    .file-toolbar {
        padding: 7px 10px 4px;
        gap: 5px;
        flex-wrap: nowrap;
        border-bottom: none; /* merged visually with upload bar */
    }
    .file-toolbar input {
        order: unset;
        flex: 1 1 auto;
        min-width: 0;
        padding: 6px 9px;
        font-size: 13px;
        min-height: 30px;
    }
    .file-toolbar button:first-of-type { order: unset; flex: 0 0 auto; }
    .file-toolbar button:last-of-type  { order: unset; flex: 0 0 auto; }
    /* Compact icon-only buttons for toolbar & upload bar on mobile */
    .file-btn {
        padding: 5px 8px;
        font-size: 12px;
        min-height: 30px;
        min-width: 30px;
        justify-content: center;
    }

    /* Mobile upload bar - compact single row */
    .file-upload-bar {
        padding: 0 10px 7px;
        gap: 5px;
        flex-wrap: nowrap;
        border-bottom: 1px solid var(--border);
    }
    .file-btn-upload {
        flex: 0 0 auto !important;
        width: auto !important;
    }
    .file-upload-bar .file-btn:not(.file-btn-upload) {
        flex: 0 0 auto;
    }
    #upload-status {
        font-size: 11px;
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Mobile upload progress */
    .upload-progress-wrap {
        padding: 6px 10px;
        margin-top: -1px;
    }

    /* Mobile select bar - compact single row */
    .file-select-bar {
        padding: 5px 10px;
        gap: 5px;
        flex-wrap: nowrap;
    }
    .file-select-all-label {
        font-size: 12px;
        min-height: unset;
        flex-shrink: 0;
    }
    .file-item-checkbox {
        width: 15px;
        height: 15px;
    }
    .file-select-count {
        font-size: 11px;
        flex: 1;
        min-width: 0;
    }
    .file-btn-danger {
        min-height: unset;
        flex-shrink: 0;
    }

    /* Mobile file list - single-row, compact action icons */
    .file-list {
        padding: 2px 0;
    }
    .file-item {
        flex-wrap: nowrap;
        padding: 8px 12px;
        min-height: 44px;
        gap: 8px;
        align-items: center;
    }
    .file-icon {
        width: 18px;
        font-size: 15px;
        flex-shrink: 0;
    }
    .file-name {
        font-size: 13px;
        flex: 1;
        min-width: 0;
    }
    .file-size {
        display: none;
    }
    /* Always show actions on mobile (touch devices have no hover) */
    .file-actions {
        display: flex;
        width: auto;
        padding-left: 0;
        gap: 2px;
        flex-shrink: 0;
        margin-left: auto;
    }
    /* Hide text labels in action buttons on mobile - icon only */
    .file-btn-label {
        display: none;
    }
    .file-action-btn {
        padding: 5px;
        font-size: 11px;
        min-height: 28px;
        min-width: 28px;
        flex: 0 0 auto;
        justify-content: center;
        border-radius: 5px;
    }

    .settings-modal-box { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; border-radius: 0; }
    .settings-modal-body { flex-direction: column; }
    .settings-nav { width: 100%; flex-direction: row; height: 46px; flex-shrink: 0; border-right: none; border-bottom: 1px solid var(--border); overflow-x: auto; overflow-y: visible; padding: 6px 8px; gap: 4px; background: var(--bg-s); }
    .settings-nav-item { width: auto; padding: 5px 12px; flex-shrink: 0; font-size: 12px; border-radius: 16px; }
    .settings-nav-item svg { display: none; }
    .settings-content { padding: 16px; }
    .tc-body { padding: 10px 12px; }
    .tc-actions { flex-direction: row; flex-wrap: wrap; }
    .tc-api-info { flex-wrap: wrap; }

    .modal-box { min-width: auto !important; width: calc(100vw - 32px); padding: 20px; }

    .file-editor-container {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        position: relative;
    }

    /* Mobile file editor header - compact, leave space for bottom bar */
    .file-editor-header {
        padding: 10px 52px 10px 14px; /* right padding for floating close */
        min-height: 48px;
        flex-wrap: wrap;
        gap: 6px;
    }
    .file-editor-title {
        max-width: calc(100vw - 140px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block;
        font-size: 14px;
    }
    /* Hide search/save/close from header on mobile — moved to bottom bar */
    .file-editor-header .editor-act-close,
    .file-editor-header .editor-act-save,
    .file-editor-header .editor-act-btn[onclick="editorSearch()"] { display: none; }
    .editor-status {
        font-size: 12px;
    }

    /* Floating close button (top-right corner) */
    .editor-mobile-close {
        display: flex;
        position: absolute;
        top: 8px; right: 8px;
        z-index: 20;
        align-items: center; justify-content: center;
        width: 36px; height: 36px;
        background: var(--bg-t);
        border: 1px solid var(--border);
        border-radius: 50%;
        cursor: pointer;
        color: var(--text);
        flex-shrink: 0;
    }
    .editor-mobile-close:active { background: var(--danger); color: #fff; border-color: var(--danger); }

    /* Mobile bottom bar for editor */
    .editor-mobile-bottombar {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 14px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        border-top: 1px solid var(--border);
        background: var(--bg);
        flex-shrink: 0;
    }
    .editor-mobile-bottombar-status {
        flex: 1;
        font-size: 12px;
        color: var(--text-m);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .editor-mobile-bar-btn {
        display: inline-flex; align-items: center; gap: 5px;
        padding: 9px 14px; border: 1px solid var(--border);
        border-radius: var(--rs); background: var(--bg);
        color: var(--text-s); font-size: 13px; cursor: pointer;
        white-space: nowrap; transition: all 0.1s; min-height: 40px;
    }
    .editor-mobile-bar-btn:hover { background: var(--bg-t); border-color: var(--border-d); }
    .editor-mobile-bar-save {
        background: var(--accent) !important; color: #fff !important;
        border-color: var(--accent) !important; font-weight: 600;
    }
    .editor-mobile-bar-save:hover { background: var(--accent-h) !important; }

    .mobile-kb {
        display: flex; flex-direction: column; align-items: flex-end;
        position: fixed; bottom: 100px; right: 12px; z-index: 30;
        transition: opacity 0.15s;
    }

    #toast-container { top: 8px; right: 8px; left: 8px; max-width: none; }
    .toast { font-size: 12px; padding: 10px 12px; min-width: 0; border-radius: 12px; }
    .toast-icon { width: 28px; height: 28px; border-radius: 7px; }
    .toast-message { padding-top: 5px; }
}

/* ===== First-Time User Guide ===== */
/* ============ USER GUIDE OVERLAY ============ */
.user-guide-overlay {
    position: fixed; inset: 0; z-index: 10000;
    display: flex; align-items: center; justify-content: center;
    animation: fadeIn 0.25s ease;
}
.user-guide-overlay.hidden { display: none; }

.user-guide-backdrop {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(8px);
}

.user-guide-container {
    position: relative;
    background: var(--bg);
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.28);
    width: 680px; max-width: calc(100vw - 32px);
    max-height: calc(100vh - 64px);
    display: flex; flex-direction: column;
    animation: guideSlideIn 0.38s cubic-bezier(0.16,1,0.3,1);
    overflow: hidden;
}

@keyframes guideSlideIn {
    from { opacity: 0; transform: translateY(-24px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
.user-guide-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.ug-header-inner { display: flex; align-items: center; gap: 14px; }
.ug-header-icon {
    width: 42px; height: 42px; border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-h));
    display: flex; align-items: center; justify-content: center;
    color: #fff; flex-shrink: 0;
}
.user-guide-title {
    font-size: 16px; font-weight: 700; color: var(--text);
    letter-spacing: -0.02em; margin: 0 0 2px 0;
}
.ug-subtitle { font-size: 12px; color: var(--text-s); margin: 0; }
.user-guide-close {
    background: none; border: none; color: var(--text-m);
    cursor: pointer; padding: 6px; border-radius: 8px;
    transition: all 0.2s; line-height: 0; flex-shrink: 0;
}
.user-guide-close:hover { background: var(--bg-t); color: var(--text); }

/* Body */
.user-guide-body {
    flex: 1; overflow-y: auto; padding: 20px 22px 24px;
}

/* Step 1 Card */
.ug-step1-card {
    background: linear-gradient(135deg, rgba(217,119,87,0.09) 0%, rgba(217,119,87,0.03) 100%);
    border: 1px solid rgba(217,119,87,0.22);
    border-radius: 14px; padding: 16px 18px 18px;
    margin-bottom: 20px;
}
.ug-step-badge {
    display: inline-flex; align-items: center;
    background: var(--accent); color: #fff;
    font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
    padding: 2px 8px; border-radius: 20px;
    margin-bottom: 12px;
}
.ug-step1-content {
    display: flex; align-items: center; gap: 14px;
}
.ug-step1-icon {
    width: 46px; height: 46px; border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-h));
    display: flex; align-items: center; justify-content: center;
    color: #fff; flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(217,119,87,0.28);
}
.ug-step1-text { flex: 1; min-width: 0; }
.ug-step1-title {
    font-size: 14px; font-weight: 700; color: var(--text);
    margin-bottom: 5px;
}
.ug-step1-desc { font-size: 12.5px; color: var(--text-s); line-height: 1.55; }
.ug-inline-badge {
    display: inline-flex; align-items: center; gap: 3px;
    background: var(--bg); border: 1px solid var(--border);
    padding: 1px 6px; border-radius: 5px;
    font-size: 11px; font-weight: 600; color: var(--text);
    white-space: nowrap; vertical-align: middle;
}
.ug-arrow-hint {
    flex-shrink: 0; display: flex; flex-direction: column;
    align-items: center; gap: 4px;
    color: var(--accent); font-size: 10px; font-weight: 700;
    opacity: 0.75; text-transform: uppercase; letter-spacing: 0.04em;
}

/* Step 2 Methods */
.ug-methods-label {
    font-size: 11px; font-weight: 700; color: var(--text-s);
    text-transform: uppercase; letter-spacing: 0.07em;
    margin-bottom: 12px;
}
.ug-methods-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.ug-method-card {
    border: 1.5px solid var(--border);
    border-radius: 14px; padding: 18px 18px 16px;
    display: flex; flex-direction: column;
    background: var(--bg);
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.ug-method-card:hover {
    box-shadow: 0 6px 24px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}
.ug-method-web  { border-top: 3px solid var(--accent); }
.ug-method-client { border-top: 3px solid #7c3aed; }

.ug-method-icon-wrap {
    width: 42px; height: 42px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 12px; flex-shrink: 0;
}
.ug-method-web    .ug-method-icon-wrap { background: rgba(217,119,87,0.1);  color: var(--accent); }
.ug-method-client .ug-method-icon-wrap { background: rgba(124,58,237,0.1);  color: #7c3aed; }

.ug-method-type-label {
    display: inline-flex; align-items: center;
    font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
    padding: 2px 8px; border-radius: 20px;
    margin-bottom: 8px; width: fit-content;
    text-transform: uppercase;
}
.ug-method-web    .ug-method-type-label { background: rgba(217,119,87,0.12); color: var(--accent); }
.ug-method-client .ug-method-type-label { background: rgba(124,58,237,0.1);  color: #7c3aed; }

.ug-method-title {
    font-size: 13.5px; font-weight: 700; color: var(--text);
    margin: 0 0 8px 0; letter-spacing: -0.01em;
}
.ug-method-desc {
    font-size: 12px; line-height: 1.6; color: var(--text-s);
    flex: 1; margin-bottom: 16px;
}
.ug-method-desc strong { color: var(--text); font-weight: 600; }

.ug-method-btn {
    display: flex; align-items: center; justify-content: center;
    padding: 9px 14px; border-radius: 9px;
    font-size: 12.5px; font-weight: 600; cursor: pointer;
    text-decoration: none; border: none; width: 100%;
    transition: all 0.2s; letter-spacing: -0.01em; box-sizing: border-box;
}
.ug-method-btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-h));
    color: #fff; box-shadow: 0 3px 10px rgba(217,119,87,0.25);
}
.ug-method-btn-primary:hover {
    box-shadow: 0 5px 16px rgba(217,119,87,0.4); transform: translateY(-1px);
}
.ug-method-btn-outline {
    background: none; border: 1.5px solid #7c3aed; color: #7c3aed;
}
.ug-method-btn-outline:hover { background: rgba(124,58,237,0.07); }

@media (max-width: 640px) {
    .user-guide-container { max-width: calc(100vw - 20px); max-height: calc(100vh - 40px); }
    .user-guide-header { padding: 16px 18px; }
    .user-guide-body { padding: 14px 16px 20px; }
    .ug-methods-grid { grid-template-columns: 1fr; }
    .ug-step1-content { flex-wrap: wrap; }
    .ug-arrow-hint { display: none; }
}
