/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1923;
  --bg2: #1a2736;
  --bg3: #243447;
  --surface: #1e2d3d;
  --border: #2a3f53;
  --text: #e0e6ed;
  --text2: #8899aa;
  --accent: #00d4aa;
  --accent2: #0099ff;
  --danger: #ff4757;
  --warning: #ffa502;
  --success: #2ed573;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --header-h: 52px;
  --nav-h: 58px;
  --sidebar-w: 220px;
}
html, body { height: 100%; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
input, button, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--accent2); text-decoration: none; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* === Pages === */
.page { display: none; height: 100%; }
.page.active { display: flex; }

/* === Login === */
#loginPage { align-items: center; justify-content: center; background: linear-gradient(135deg, #0f1923 0%, #1a2736 50%, #0f1923 100%); }
.login-container { width: 100%; max-width: 380px; padding: 20px; }
.login-card { background: var(--surface); border-radius: 16px; padding: 40px 30px; text-align: center; box-shadow: var(--shadow); border: 1px solid var(--border); }
.login-icon { font-size: 48px; color: var(--accent); margin-bottom: 16px; }
.login-card h2 { font-size: 22px; margin-bottom: 4px; }
.login-subtitle { color: var(--text2); font-size: 13px; margin-bottom: 28px; }
.input-group { position: relative; margin-bottom: 16px; }
.input-group .input-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text2); font-size: 16px; }
.input-group input { width: 100%; padding: 12px 12px 12px 42px; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 15px; outline: none; transition: border-color .2s; }
.input-group input:focus { border-color: var(--accent); }
.login-card button { width: 100%; padding: 12px; background: var(--accent); color: #000; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; transition: opacity .2s, transform .1s; }
.login-card button:hover { opacity: .9; }
.login-card button:active { transform: scale(.98); }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 20px; }

/* === App Layout === */
#appPage { flex-direction: column; }

/* Header */
#appHeader { display: flex; align-items: center; justify-content: space-between; height: var(--header-h); padding: 0 16px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; z-index: 100; }
.header-left, .header-right { display: flex; align-items: center; gap: 10px; }
.header-title { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.header-brand { display: none; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; color: var(--accent); }
.header-title i { font-size: 16px; width: auto; }
.header-btn { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: 8px; cursor: pointer; color: var(--text2); transition: background .15s, color .15s; }
.header-btn:hover { background: var(--bg3); color: var(--text); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: block; transition: background .3s; }
.status-dot.connected { background: var(--success); box-shadow: 0 0 6px rgba(46,213,115,.5); }
.status-dot.connecting { background: var(--warning); box-shadow: 0 0 6px rgba(255,171,0,.4); animation: dot-pulse 1.2s ease-in-out infinite; }
.status-dot.disconnected { background: var(--danger); }
@keyframes dot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

/* Sidebar */
#sidebar { position: fixed; left: 0; top: var(--header-h); bottom: 0; width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border); transform: translateX(-100%); transition: transform .2s; z-index: 90; overflow-y: auto; }
#sidebar.open { transform: translateX(0); }
.sidebar-header { padding: 20px 16px; font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.sidebar-nav { padding: 8px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 8px; cursor: pointer; color: var(--text2); transition: background .15s, color .15s; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: rgba(0,212,170,.12); color: var(--accent); }
.nav-item i { width: 20px; text-align: center; font-size: 15px; }

/* Main Content */
#mainContent { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: calc(var(--nav-h) + 16px); margin-left: 0; transition: margin-left .2s; }
.page-content { display: none; }
.page-content.active { display: block; height: 100%; }
.page-title { font-size: 18px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

/* Bottom Nav */
#bottomNav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h); background: var(--bg2); border-top: 1px solid var(--border); z-index: 95; }
#bottomNav .nav-item { flex: 1; flex-direction: column; gap: 2px; padding: 6px 0; font-size: 10px; border-radius: 0; justify-content: center; }
#bottomNav .nav-item i { font-size: 18px; width: auto; }

/* === Dashboard === */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; margin-bottom: 10px; }
.stat-icon.cpu { background: rgba(0,153,255,.15); color: var(--accent2); }
.stat-icon.mem { background: rgba(0,212,170,.15); color: var(--accent); }
.stat-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.stat-label { font-size: 12px; color: var(--text2); }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-bar { height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.stat-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); border-radius: 2px; transition: width .5s; }
.stat-bar-fill.mem { background: linear-gradient(90deg, var(--accent), #00e5a0); }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.info-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.info-label { font-size: 11px; color: var(--text2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .5px; }
.info-value { font-size: 14px; font-weight: 500; word-break: break-all; }
.info-value.small { font-size: 12px; }
/* === Charts === */
.chart-header { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 10px; }
.chart-header .section-title { margin: 0; }
.ws-indicator { font-size: 11px; color: var(--text2); display: flex; align-items: center; gap: 4px; }
.ws-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); display: inline-block; }
.ws-dot.disconnected { background: var(--danger); }
.ws-indicator.reconnecting { color: var(--warning); }
.ws-indicator.reconnecting .ws-dot { background: var(--warning); }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; position: relative; }
.chart-title { font-size: 12px; color: var(--text2); margin-bottom: 8px; }
.chart-card canvas { width: 100%; height: 180px; display: block; border-radius: 4px; }
@media (max-width: 768px) {
  .charts-grid { grid-template-columns: 1fr; }
}
/* === End Charts === */

.section-title { font-size: 15px; margin: 16px 0 10px; color: var(--text2); }
.disk-item, .net-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; }
.disk-item .disk-info { display: flex; flex-direction: column; gap: 4px; flex: 1; margin: 0 12px; }
.disk-item .disk-name { font-weight: 600; }
.disk-item .disk-bar { height: 6px; background: var(--bg); border-radius: 3px; width: 100%; }
.disk-item .disk-fill { height: 100%; background: var(--accent2); border-radius: 3px; transition: width .5s; }
.disk-item .disk-fill.warning { background: var(--warning); }
.disk-item .disk-fill.danger { background: var(--danger); }
.disk-item .disk-used { font-size: 12px; color: var(--text2); white-space: nowrap; }

/* === File Manager === */
.file-toolbar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; }
.file-path-bar { display: flex; gap: 4px; align-items: center; margin-bottom: 8px; }
.file-path-bar button { padding: 6px 8px; background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); cursor: pointer; font-size: 12px; flex-shrink: 0; }
.file-path-bar button:hover { background: var(--bg3); }
.file-path-bar input { flex: 1; padding: 6px 10px; background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 12px; cursor: pointer; min-width: 0; }
.drive-bar { display: flex; gap: 2px; flex-shrink: 0; }
.drive-bar .drive-btn { padding: 6px 8px; font-size: 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg2); color: var(--text); cursor: pointer; font-weight: 600; line-height: 1; }
.drive-bar .drive-btn:hover { background: var(--bg3); border-color: var(--accent); }

@media (max-width: 768px) {
  .drive-bar .drive-btn { padding: 5px 6px; font-size: 11px; }
}

.file-actions { display: flex; gap: 6px; }
.file-actions button, .upload-btn { padding: 6px 10px; background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); cursor: pointer; display: flex; align-items: center; gap: 4px; }
.file-actions button:hover, .upload-btn:hover { background: var(--bg3); }

/* === File Search Bar === */
.file-search-bar { display: flex; align-items: center; gap: 8px; background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; padding: 0 10px; margin-bottom: 8px; }
.file-search-bar i { color: var(--text2); font-size: 13px; }
.file-search-bar input { flex: 1; padding: 7px 0; background: transparent; border: none; color: var(--text); outline: none; font-size: 13px; }
.file-search-bar input::placeholder { color: var(--text2); }
.file-search-bar:focus-within { border-color: var(--accent); }
.file-search-count { font-size: 11px; color: var(--text2); white-space: nowrap; }

/* === File Filter & Sort Bar === */
.file-filter-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.file-filter-chips { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.filter-chip { padding: 4px 10px; border-radius: 14px; font-size: 12px; background: var(--bg2); border: 1px solid var(--border); color: var(--text2); cursor: pointer; white-space: nowrap; transition: all .15s; display: inline-flex; align-items: center; gap: 4px; }
.filter-chip:hover { border-color: var(--accent); color: var(--text); }
.filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.file-sort-group { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.sort-label { font-size: 12px; color: var(--text2); }
.file-sort-group select { padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); font-size: 12px; outline: none; cursor: pointer; }
.file-sort-group select:focus { border-color: var(--accent); }
.file-sort-group button { padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); cursor: pointer; font-size: 12px; display: flex; align-items: center; }
.file-sort-group button:hover { background: var(--bg3); }

/* File date column (list view) */
.file-date { font-size: 11px; color: var(--text2); display: none; }
.file-grid.list-view .file-date { display: block; flex-shrink: 0; min-width: 140px; text-align: right; }
@media (max-width: 768px) {
  .file-grid.list-view .file-date { min-width: 80px; font-size: 10px; }
}
@media (max-width: 480px) {
  .file-filter-chips { gap: 2px; }
  .filter-chip { padding: 3px 8px; font-size: 11px; }
  .file-sort-group select { font-size: 11px; padding: 3px 6px; }
  .file-grid.list-view .file-date { display: none; }
}

/* === File View Toggle === */
#viewToggleBtn { min-width: 34px; display: flex; align-items: center; justify-content: center; }
#viewToggleBtn.active-view { background: var(--bg3); color: var(--accent); }

/* === File List View === */
.file-grid.list-view { display: flex; flex-direction: column; gap: 4px; }
.file-grid.list-view .file-item { flex-direction: row; padding: 8px 12px; gap: 12px; position: relative; }
.file-grid.list-view .file-item .file-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }
.file-grid.list-view .file-item .file-name { flex: 1; min-width: 0; -webkit-line-clamp: 1; text-align: left; }
.file-grid.list-view .file-item .file-size { margin-left: auto; flex-shrink: 0; }

/* drive buttons now in .drive-bar inside file-path-bar (see above) */
.drive-btn:hover { background: var(--bg3); }
.drive-btn.unavailable { opacity: .3; cursor: not-allowed; }
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.file-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 10px; cursor: pointer; transition: border-color .15s, background .15s; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.file-item:hover { border-color: var(--accent); background: rgba(0,212,170,.05); }
.file-item .file-icon { font-size: 28px; color: var(--text2); }
.file-item.dir .file-icon { color: var(--accent2); }
.file-item .file-name { font-size: 12px; word-break: break-all; max-width: 100%; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.file-item .file-size { font-size: 11px; color: var(--text2); }
.file-item .file-actions-overlay { position: absolute; top: 4px; right: 4px; display: none; }

/* === Terminal === */
.term-toolbar { display: flex; gap: 6px; align-items: center; margin-bottom: 0; }
.term-toolbar button { padding: 5px 10px; background: transparent; border: 1px solid var(--border); border-radius: 6px; color: var(--text2); cursor: pointer; font-size: 12px; transition: all .15s; }
.term-toolbar button:hover { background: var(--bg3); color: var(--text); }
.term-status { font-size: 12px; color: var(--text2); margin-left: auto; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.term-status i { font-size: 8px; }
.term-status.connected i { color: var(--success); }
.term-status.disconnected i { color: var(--danger); }
.term-tab-count { font-size: 11px; color: var(--text3); margin-left: 4px; }

/* Tab Bar — VSCode style */
.term-tab-bar { display: flex; background: #252526; border: 1px solid var(--border); border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; overflow-x: auto; overflow-y: hidden; min-height: 35px; }
.term-tab-bar::-webkit-scrollbar { height: 2px; }
.term-tab-bar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.term-tab { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; font-size: 12px; color: #969696; background: #2d2d2d; border-right: 1px solid #252526; cursor: pointer; user-select: none; white-space: nowrap; min-width: 0; position: relative; transition: background .1s; }
.term-tab:hover { background: #353535; color: #ccc; }
.term-tab.active { background: #1e1e1e; color: #e0e0e0; }
.term-tab.active::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 1px; background: #1e1e1e; }
.term-tab .tab-text { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.term-tab .tab-close { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 3px; font-size: 14px; line-height: 1; color: transparent; transition: all .1s; }
.term-tab:hover .tab-close { color: #969696; }
.term-tab .tab-close:hover { background: rgba(255,255,255,.1); color: #e0e0e0; }
.term-tab-add { display: inline-flex; align-items: center; justify-content: center; width: 32px; min-width: 32px; color: #969696; cursor: pointer; font-size: 16px; transition: background .1s; }
.term-tab-add:hover { background: #353535; color: #e0e0e0; }

/* Terminal Container */
.term-container { border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; height: 400px; max-height: 60vh; position: relative; background: #1e1e1e; }
.term-instance { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: none; }
.term-instance.active { display: block; }
.term-instance .xterm { height: 100%; padding: 4px; }

/* === Processes === */
/* Process page */
.proc-toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
#procRefresh.spinning i { animation: fa-spin 2s linear infinite; }
#procRefresh.spinning { pointer-events: none; opacity: .6; }
.proc-toolbar input { flex: 1; padding: 8px 12px; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); outline: none; }
.proc-toolbar input:focus { border-color: var(--accent); }
.proc-toolbar button { padding: 8px 12px; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); cursor: pointer; }
.proc-toolbar button:hover { background: var(--bg3); }
.proc-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between; gap: 8px; transition: opacity .3s; }
.proc-item.loading { opacity: .5; }
.proc-item .proc-info { flex: 1; min-width: 0; }
.proc-item .proc-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proc-item .proc-detail { font-size: 11px; color: var(--text2); }
.proc-item .proc-kill { padding: 4px 10px; background: transparent; border: 1px solid var(--danger); border-radius: 6px; color: var(--danger); cursor: pointer; font-size: 12px; flex-shrink: 0; }
.proc-item .proc-kill:hover { background: var(--danger); color: #fff; }

/* === Network === */
.net-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; }
.net-card-header { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; transition: background .15s; user-select: none; }
.net-card-header:hover { background: var(--bg2); }
.net-card-header.collapsed + .net-card-body { display: none; }
.net-card-header.collapsed .net-collapse-icon { transform: rotate(-90deg); }
.net-type-icon { font-size: 20px; color: var(--accent2); width: 28px; text-align: center; }
.net-card-title { flex: 1; min-width: 0; }
.net-card-title .net-name { font-weight: 600; font-size: 14px; display: block; }
.net-card-title .net-desc { font-size: 11px; color: var(--text2); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.net-status-badge { font-size: 11px; white-space: nowrap; display: flex; align-items: center; }
.net-status-badge.status-off i { color: var(--danger) !important; }
.net-status-badge.status-on i { color: var(--success) !important; }
.net-collapse-icon { font-size: 12px; color: var(--text3); transition: transform .2s; }
.net-card-body { padding: 0 14px 10px 14px; }
.net-detail-table { width: 100%; border-collapse: collapse; }
.net-detail-table tr td { padding: 5px 0; vertical-align: top; }
.net-detail-table tr + tr td { border-top: 1px solid var(--border); }
.nd-label { font-size: 12px; color: var(--text2); white-space: nowrap; width: 60px; padding-right: 12px; }
.nd-label i { width: 14px; margin-right: 4px; text-align: center; font-size: 11px; }
.nd-value { font-size: 13px; color: var(--text); word-break: break-all; }
.text-muted { color: var(--text3); }

/* Network Summary Bar */
.net-summary-bar { display: flex; gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; }
.net-summary-item { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 12px 4px; gap: 3px; border-right: 1px solid var(--border); }
.net-summary-item:last-child { border-right: none; }
.net-summary-item i { font-size: 16px; color: var(--accent); }
.net-summary-item .ns-label { font-size: 10px; color: var(--text3); text-transform: uppercase; }
.net-summary-item .ns-value { font-size: 16px; font-weight: 700; color: var(--text); }

/* Connection Breakdown */
.net-conn-breakdown { display: flex; gap: 6px; margin-bottom: 10px; }
.ncb-item { flex: 1; text-align: center; padding: 8px 4px; border-radius: var(--radius); font-size: 10px; color: var(--text2); }
.ncb-item.established { background: rgba(0,212,170,.1); }
.ncb-item.timewait { background: rgba(255,193,7,.1); }
.ncb-item.closewait { background: rgba(220,53,69,.1); }
.ncb-item .ncb-num { display: block; font-size: 18px; font-weight: 700; margin-bottom: 2px; }
.ncb-item.established .ncb-num { color: var(--success); }
.ncb-item.timewait .ncb-num { color: #ffc107; }
.ncb-item.closewait .ncb-num { color: var(--danger); }

/* Speed badges */
.speed-badge { padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.speed-badge.speed-fast { background: rgba(0,212,170,.15); color: var(--success); }
.speed-badge.speed-ok { background: rgba(255,193,7,.15); color: #ffc107; }
.speed-badge.speed-slow { background: rgba(220,53,69,.15); color: var(--danger); }

/* === Actions === */
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.action-btn { padding: 20px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); cursor: pointer; font-size: 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; transition: border-color .2s, background .15s; }
.action-btn i { font-size: 24px; }
.action-btn:hover { border-color: var(--accent); background: rgba(0,212,170,.05); }
.action-btn.warning { border-color: var(--warning); color: var(--warning); }
.action-btn.warning:hover { background: rgba(255,165,2,.1); }
.action-btn.danger { border-color: var(--danger); color: var(--danger); }
.action-btn.danger:hover { background: rgba(255,71,87,.1); }
.warning-text { font-size: 13px; color: var(--text2); margin-bottom: 16px; padding: 10px 14px; background: rgba(255,165,2,.08); border: 1px solid rgba(255,165,2,.2); border-radius: 8px; }
.warning-text i { color: var(--warning); margin-right: 6px; }

/* Settings */
.settings-section { max-width: 720px; }
.settings-section.collapsed .settings-section-body { display: none; }
.settings-section.collapsed .section-title i { transform: rotate(180deg); }
.section-title.collapsible {
  cursor: pointer; user-select: none;
  display: flex; align-items: center; justify-content: space-between;
  transition: color .15s;
}
.section-title.collapsible:hover { color: #e2e8f0; }
.section-title.collapsible i {
  font-size: 12px; color: #475569;
  transition: transform .2s;
}
.settings-desc { font-size: 13px; color: #64748b; margin-bottom: 16px; }
.model-config-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }

.model-card {
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 10px;
  background: rgba(255,255,255,.015);
  overflow: hidden;
  transition: border-color .2s;
}
.model-card:hover { border-color: rgba(255,255,255,.1); }

.model-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; cursor: pointer;
  user-select: none;
  transition: background .15s;
}
.model-card-header:hover { background: rgba(255,255,255,.02); }
.model-card-summary {
  display: flex; align-items: center; gap: 10px;
  min-width: 0; overflow: hidden;
}
.model-card-name {
  font-size: 14px; font-weight: 600; color: #e2e8f0;
}
.model-card-modelid {
  font-size: 11px; color: #64748b; font-family: monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.model-card-protocol {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: rgba(99,102,241,.12); color: #8b5cf6;
}
.model-card-key-dot {
  font-size: 10px; color: #2ed573;
}
.model-card-key-dot.missing { color: #ef4444; }
.model-card-chevron {
  font-size: 11px; color: #475569; transition: transform .2s;
  margin-left: 8px; flex-shrink: 0;
}
.model-card:not(.expanded) .model-card-chevron { transform: rotate(-90deg); }

.model-card-body {
  display: none;
  padding: 0 14px 14px;
  border-top: 1px solid rgba(255,255,255,.04);
}
.model-card.expanded .model-card-body { display: block; }

.model-card-body label {
  display: block;
  font-size: 11px; color: #64748b;
  margin: 10px 0 4px;
}
.model-card-body input[type="text"],
.model-card-body input[type="password"] {
  width: 100%;
  padding: 8px 11px;
  background: rgba(0,0,0,.2);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 13px;
  outline: none;
  transition: border-color .2s;
}
.model-card-body input:focus { border-color: rgba(99,102,241,.4); }
.model-card-body select {
  padding: 8px 11px;
  background: rgba(0,0,0,.2);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}
.model-card-body select option { background: #1a2736; color: #e2e8f0; }

.model-card-row {
  display: flex; gap: 10px;
}
.model-card-row > div:first-child { min-width: 120px; }
.model-card-row > div:last-child { flex: 1; min-width: 0; }

.model-card-key-row {
  display: flex; gap: 0;
}
.model-card-key-row input { flex: 1; border-radius: 6px 0 0 6px !important; }
.toggle-key-btn {
  background: rgba(0,0,0,.2);
  border: 1px solid rgba(255,255,255,.08);
  border-left: none;
  border-radius: 0 6px 6px 0;
  color: #64748b;
  cursor: pointer;
  padding: 0 12px;
  font-size: 12px;
  transition: color .15s;
}
.toggle-key-btn:hover { color: #94a3b8; }

.model-card-del {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 10px;
  background: none; border: 1px solid rgba(239,68,68,.15);
  border-radius: 6px; color: #ef4444;
  cursor: pointer; padding: 5px 12px;
  font-size: 11px;
  transition: background .15s;
}
.model-card-del:hover { background: rgba(239,68,68,.08); }

.settings-add-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  background: rgba(255,255,255,.02);
  border: 1px dashed rgba(255,255,255,.1);
  border-radius: 8px; color: #64748b; cursor: pointer;
  font-size: 13px;
  margin-bottom: 16px;
}
.settings-add-btn:hover { border-color: rgba(99,102,241,.3); color: #8b5cf6; }
.settings-actions { display: flex; align-items: center; gap: 12px; }
.settings-save-btn {
  padding: 10px 24px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; border: none; border-radius: 8px;
  font-weight: 600; font-size: 14px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(99,102,241,.2);
  transition: opacity .15s, transform .15s;
}
.settings-save-btn:hover { opacity: .9; transform: translateY(-1px); }
.settings-status { font-size: 12px; color: #64748b; }

/* Skill cards (simplified) */
.skill-card-simple {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 10px;
  background: rgba(255,255,255,.015);
  gap: 12px;
  transition: border-color .2s;
}
.skill-card-simple:hover { border-color: rgba(255,255,255,.1); }
.skill-simple-info { min-width: 0; flex: 1; }
.skill-simple-name { font-size: 14px; font-weight: 600; color: #e2e8f0; margin-bottom: 2px; }
.skill-simple-id { font-size: 11px; color: #64748b; font-family: monospace; }
.skill-simple-desc { font-size: 12px; color: #94a3b8; margin-top: 3px; }
.skill-simple-meta { font-size: 10px; color: #64748b; margin-top: 4px; }
.skill-simple-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.skill-simple-del {
  background: none; border: 1px solid rgba(239,68,68,.15);
  border-radius: 6px; color: #64748b;
  cursor: pointer; padding: 6px 10px; font-size: 12px;
  transition: color .15s, background .15s;
}
.skill-simple-del:hover { color: #ef4444; background: rgba(239,68,68,.08); }

/* Toggle switch */
.skill-toggle { position: relative; display: inline-block; width: 40px; height: 22px; cursor: pointer; }
.skill-toggle input { opacity: 0; width: 0; height: 0; }
.skill-toggle-slider {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.08);
  border-radius: 22px;
  transition: background .25s;
}
.skill-toggle-slider::before {
  content: ''; position: absolute;
  left: 2px; top: 2px; width: 18px; height: 18px;
  background: #64748b; border-radius: 50%;
  transition: transform .25s, background .25s;
}
.skill-toggle input:checked + .skill-toggle-slider { background: rgba(99,102,241,.3); }
.skill-toggle input:checked + .skill-toggle-slider::before {
  transform: translateX(18px);
  background: #8b5cf6;
}

/* Skill import modal */
.skill-import-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; width: 520px; max-width: 90vw;
  max-height: 80vh; display: flex; flex-direction: column;
}
.skill-import-box h3 { margin: 0 0 14px; font-size: 16px; color: var(--text); }
.skill-import-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.skill-import-tab {
  padding: 6px 14px; border: 1px solid rgba(255,255,255,.06);
  background: rgba(255,255,255,.02); color: #64748b;
  border-radius: 6px; cursor: pointer; font-size: 12px;
  transition: background .15s, color .15s;
}
.skill-import-tab.active {
  background: rgba(99,102,241,.1); border-color: rgba(99,102,241,.2);
  color: #8b5cf6;
}
.skill-import-hint { font-size: 12px; color: #64748b; margin-bottom: 8px; }
.skill-import-textarea {
  width: 100%; min-height: 160px;
  padding: 10px; background: rgba(0,0,0,.2);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px; color: #e2e8f0;
  font-size: 12px; font-family: monospace;
  outline: none; resize: vertical;
  line-height: 1.5;
}
.skill-import-textarea:focus { border-color: rgba(99,102,241,.4); }
.skill-import-file-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px;
  border: 1px dashed rgba(255,255,255,.12);
  border-radius: 8px; color: #8b5cf6; cursor: pointer;
  font-size: 13px; transition: background .15s;
}
.skill-import-file-btn:hover { background: rgba(99,102,241,.06); }
.skill-import-preview-header {
  font-size: 12px; color: #64748b; margin-bottom: 6px;
  display: flex; align-items: center; gap: 8px;
}
.skill-import-actions {
  display: flex; align-items: center; gap: 10px; margin-top: 14px;
}
#actionResult { text-align: center; font-size: 14px; }

/* === Modal === */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 999; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; max-width: 400px; width: 100%; max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,.4); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header #modalTitle { font-weight: 600; }
.modal-close { font-size: 24px; color: var(--text2); cursor: pointer; line-height: 1; }
.modal-body { padding: 20px; }

/* === Utilities === */
.loading { text-align: center; padding: 40px 20px; color: var(--text2); font-size: 14px; }
.loading i { margin-right: 8px; }
.toast { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); padding: 10px 20px; border-radius: 8px; font-size: 13px; z-index: 9999; animation: toastIn .3s, toastOut .3s 2.5s forwards; }
.toast.success { background: var(--success); color: #000; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--accent2); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(-10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(-50%) translateY(-10px); } }

/* === Responsive === */
@media (min-width: 769px) {
  #sidebarToggle { display: none; }
  #sidebar { transform: translateX(0); }
  #mainContent { margin-left: var(--sidebar-w); padding-bottom: 16px; }
  #bottomNav { display: none; }
  .header-title { display: none; }
  .header-brand { display: inline-flex; }
  .sidebar-header { display: none; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
  .action-grid { grid-template-columns: 1fr 1fr; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .file-item { padding: 10px 8px; }
  .file-item .file-icon { font-size: 24px; }
  .login-card { padding: 30px 20px; }
  .page-content > .page-title { display: none; }
  .sidebar-header { display: none; }
  #mainContent { overflow: hidden; display: flex; flex-direction: column; }
  .page-content.active { overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none; }
  .page-content.active::-webkit-scrollbar { display: none; }
  #vncContainer { height: 100% !important; }
  .term-container { max-height: none; }

  /* Pages with internal scroll (claude, vnc, terminal): flex layout, no outer scroll */
  #page-claude.active,
  #page-vnc.active,
  #page-terminal.active {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: auto;
    flex: 1;
    min-height: 0;
  }
  #page-claude.active .chat-container {
    height: auto;
    flex: 1;
    min-height: 0;
  }
}
@media (max-width: 400px) {
  .action-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .action-btn { padding: 14px 12px; }
  .action-btn i { font-size: 20px; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 6px; }
  .file-item { padding: 8px 6px; }
  .file-item .file-icon { font-size: 20px; }
}

/* Claude Chat UI */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.chat-toolbar button {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
#chatStopBtn {
  background: transparent;
  border: 1px solid rgba(239,68,68,.4);
  color: #ef4444;
  animation: fadeIn .2s ease;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
}
#chatStopBtn:hover {
  background: rgba(239,68,68,.12);
  border-color: #ef4444;
}
#newChatBtn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text3);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  margin-left: 8px;
  vertical-align: middle;
  transition: background .15s, color .15s, border-color .15s;
}
#newChatBtn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.tool-fail-warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 6px;
  padding: 8px 12px;
  color: #d97706;
  font-size: 13px;
}
.tool-fail-warning i { margin-right: 4px; }
.tool-fail-warning pre {
  margin: 6px 0 0;
  padding: 6px 8px;
  background: rgba(0,0,0,0.05);
  border-radius: 4px;
  font-size: 12px;
  color: #92400e;
  max-height: 150px;
  overflow: auto;
}
.tool-fail-warning details summary {
  cursor: pointer;
  color: #92400e;
  font-size: 12px;
}
.chat-status {
  flex: 1;
  font-size: 11px;
  color: #64748b;
  text-align: right;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.chat-msg {
  display: flex;
  gap: 10px;
  max-width: 80%;
  width: fit-content;
  flex-shrink: 0;
  animation: fadeIn .3s ease;
}
.chat-msg.claude {
  min-width: 0;
  width: auto;
  contain: layout style;
}
.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
}
.chat-msg.claude .msg-avatar {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}
.chat-msg.user .msg-avatar {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  box-shadow: 0 2px 8px rgba(59,130,246,.3);
}
.msg-body { min-width: 0; overflow: hidden; }
.msg-content {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}
.chat-msg.claude .msg-content {
  background: rgba(255,255,255,.03);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,.06);
  border-top-left-radius: 6px;
}
/* Full wrapper — contains thinking + text + tools as one visual unit */
.msg-content-full {
  background: rgba(255,255,255,.03) !important;
  border: 1px solid rgba(255,255,255,.06) !important;
  border-radius: 18px !important;
  border-top-left-radius: 6px !important;
  overflow: hidden;
  width: 100%;
  box-sizing: border-box;
}
/* Text block inside full wrapper — transparent, just padding for spacing */
.msg-content-text {
  padding: 0 0 4px 0;
}
.msg-content-text:first-child { padding-top: 12px; }
.msg-content-text:last-child { padding-bottom: 8px; }
/* Thinking panel inside msg-content */
.msg-content-full > .thinking-panel {
  margin: 4px 6px;
  width: auto;
}
.msg-content-full > .thinking-panel:first-child { margin-top: 0; }
/* Tool cards inside msg-content — same margins as thinking for consistency */
.msg-content-full > .tool-call-card {
  margin: 4px 6px;
  width: auto;
}
.msg-content-full > .tool-call-card:last-child { margin-bottom: 10px; }

.chat-msg.user .msg-content {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  border-top-right-radius: 6px;
  box-shadow: 0 2px 12px rgba(37,99,235,.2);
}
.msg-content p { margin: 0 0 10px; }
.msg-content p:last-child { margin: 0; }
.msg-content code {
  background: rgba(255,255,255,.08);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', 'Courier New', monospace;
  color: #e879f9;
}
.chat-msg.user .msg-content code {
  background: rgba(255,255,255,.18);
  color: #fff;
}
.msg-content pre {
  position: relative;
  background: #0d1117;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px;
  padding: 16px;
  padding-top: 34px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
  margin: 12px 0;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', 'Courier New', monospace;
}
.msg-content pre::before {
  content: attr(data-lang);
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 5px 16px;
  font-size: 10px;
  color: #8b949e;
  background: rgba(255,255,255,.03);
  border-bottom: 1px solid rgba(255,255,255,.06);
  border-radius: 10px 10px 0 0;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: .6px;
}
.msg-content pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  color: #c9d1d9;
}
.copy-code-btn {
  position: absolute;
  top: 6px; right: 8px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  color: #8b949e;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  cursor: pointer;
  z-index: 2;
  transition: background .15s, color .15s, border-color .15s;
}
.copy-code-btn:hover {
  background: rgba(255,255,255,.1);
  color: #e2e8f0;
  border-color: rgba(255,255,255,.15);
}
.copy-code-btn.copied {
  color: #2ed573;
  border-color: rgba(46,213,115,.3);
}
.msg-time {
  font-size: 10px;
  color: var(--text2);
  margin-top: 2px;
  opacity: .5;
}
.chat-msg.user .msg-time { text-align: right; }
.chat-thinking {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  border-top-left-radius: 4px;
  font-size: 13px;
  color: var(--text2);
}
.chat-thinking .dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #8b5cf6;
  animation: dotPulse 1.5s infinite ease-in-out both;
  box-shadow: 0 0 6px rgba(139,92,246,.4);
}
.chat-thinking .dot:nth-child(1) { animation-delay: -0.3s; }
.chat-thinking .dot:nth-child(2) { animation-delay: -0.15s; }
.chat-thinking-label {
  margin-left: 6px;
  font-size: 12px;
  color: var(--text2);
}
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.05);
  background: rgba(255,255,255,.01);
  align-items: flex-end;
}
.chat-input-bar textarea {
  flex: 1;
  padding: 12px 18px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  background: rgba(255,255,255,.02);
  color: #e2e8f0;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 130px;
  line-height: 1.5;
  transition: border-color .25s, box-shadow .25s;
}
.chat-input-bar textarea:focus {
  border-color: rgba(99,102,241,.5);
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}
.chat-input-bar textarea::placeholder {
  color: #64748b;
  font-size: 13px;
}
.chat-input-bar button {
  width: 42px; height: 42px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, box-shadow .2s, opacity .2s;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}
.chat-input-bar button:hover {
  box-shadow: 0 4px 14px rgba(99,102,241,.45);
  transform: scale(1.06);
}
.chat-input-bar button:active { transform: scale(.94); }
.chat-input-bar button:disabled {
  opacity: .35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Image preview chips */
.chat-image-previews {
  display: flex; gap: 6px; padding: 6px 16px 0;
  flex-wrap: wrap;
}
.chat-image-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 8px; font-size: 12px;
}
.chat-image-chip img {
  width: 28px; height: 28px; border-radius: 4px; object-fit: cover;
}
.chat-image-chip span {
  max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text2);
}
.chat-image-chip button {
  background: none; border: none; color: var(--danger); cursor: pointer;
  font-size: 14px; padding: 0; line-height: 1;
}

/* Upload button */
.chat-upload-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  color: #64748b; cursor: pointer;
  transition: background .15s, color .15s;
}
.chat-upload-btn:hover { background: rgba(255,255,255,.04); color: #8b5cf6; }

/* Inline chat image */
.chat-image {
  max-width: 240px; max-height: 240px;
  border-radius: 10px; cursor: pointer;
  margin: 4px 0; object-fit: cover;
  border: 1px solid var(--border);
  transition: transform .15s;
}
.chat-image:hover { transform: scale(1.02); }
.msg-content:has(.chat-image) { background: none; }

/* Meta row: time + regen button */
.msg-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2px;
}
.chat-regen-btn {
  background: none;
  border: none;
  color: #64748b;
  font-size: 10px;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: .4;
  transition: opacity .15s, color .15s;
}
.chat-regen-btn:hover {
  opacity: 1;
  color: #94a3b8;
}
@keyframes dotPulse {
  0%, 80%, 100% { opacity: .25; transform: scale(.7); }
  40% { opacity: 1; transform: scale(1.2); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
/* Scroll-to-bottom */
.chat-scroll-bottom {
  position: absolute; bottom: 90px; right: 22px;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,.1);
  color: #94a3b8;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 10;
  opacity: 0; transform: scale(.8) translateY(8px);
  pointer-events: none;
  transition: opacity .2s, transform .25s, background .15s;
}
.chat-scroll-bottom.visible {
  opacity: 1; transform: scale(1) translateY(0);
  pointer-events: auto;
}
.chat-scroll-bottom:hover {
  background: rgba(99,102,241,.2);
  border-color: rgba(99,102,241,.3);
  color: #e2e8f0;
}

@media (max-width: 600px) {
  .chat-msg { max-width: 90%; }
  .chat-toolbar { padding: 6px 10px; }
  .chat-messages { padding: 12px 10px; }
  .chat-input-bar { padding: 10px; }
}

/* ── Tool Call Cards ── */
.tool-call-card {
  margin: 4px 0;
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 10px;
  background: rgba(255,255,255,.015);
  overflow: hidden;
  animation: fadeIn .25s ease;
  flex-shrink: 0;
  min-height: 38px;
  max-width: 100%;
  box-sizing: border-box;
}
.tool-call-card.dangerous {
  background: rgba(239,68,68,.04);
  border-color: rgba(239,68,68,.15);
}
.tool-call-header {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; cursor: pointer;
  font-size: 12px; user-select: none;
}
.tool-call-header i:first-child { font-size: 12px; width: 16px; text-align: center; color: #8b5cf6; }
.tool-call-card.dangerous .tool-call-header i:first-child { color: #ef4444; }
.tool-call-name { font-weight: 500; flex: 1; color: #cbd5e1; }
.tool-call-status {
  font-size: 10px; display: flex; align-items: center; gap: 4px;
  color: #64748b; /* default: running */
}
.tool-call-status.success { color: #2ed573 !important; }
.tool-call-status.error { color: #ef4444 !important; }
.tool-call-status.success i,
.tool-call-status.success i::before,
.tool-call-status.error i,
.tool-call-status.error i::before { color: inherit !important; }
.tool-call-input {
  padding: 0 14px 8px 38px;
  font-size: 11px; color: #64748b;
  font-family: monospace; word-break: break-all;
  overflow: hidden; max-width: 100%;
}
.tool-call-input code {
  background: rgba(255,255,255,.04); padding: 1px 5px; border-radius: 3px;
  font-size: 11px; color: #94a3b8;
}
.tool-call-result {
  padding: 0 14px 10px 38px;
  font-size: 11px; max-height: 200px; overflow-y: auto;
}
.tool-call-result pre {
  background: rgba(0,0,0,.2); border: 1px solid rgba(255,255,255,.04);
  border-radius: 6px; padding: 10px; margin: 0;
  font-size: 11px; white-space: pre-wrap; word-break: break-all;
  max-height: 180px; overflow-y: auto; overflow-x: auto;
  max-width: 100%;
  color: #94a3b8;
}
.tool-call-result .error-msg { color: #ef4444; }
.tool-call-card.collapsed .tool-call-input,
.tool-call-card.collapsed .tool-call-result { display: none; }
.tool-collapse-icon {
  font-size: 9px; color: #475569; transition: transform .2s;
}
.tool-call-card.collapsed .tool-collapse-icon { transform: rotate(-90deg); }

/* Thinking panel */
.thinking-panel {
  margin: 6px 0;
  border: 1px solid rgba(139,92,246,.15);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(139,92,246,.03);
  animation: fadeIn .25s ease;
  flex-shrink: 0;
  min-height: 34px;
}
.thinking-panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 11px; color: #8b5cf6;
  user-select: none;
  transition: background .15s;
}
.thinking-panel-header:hover { background: rgba(139,92,246,.06); }
.thinking-panel-header i { font-size: 10px; transition: transform .2s; }
.thinking-panel-body {
  padding: 10px 14px 14px;
  font-size: 12px; color: #94a3b8;
  line-height: 1.65;
  white-space: pre-wrap;
  border-top: 1px solid rgba(139,92,246,.08);
  max-height: 240px;
  overflow-y: auto;
}
.thinking-panel-body p { margin: 0; }
.thinking-panel.collapsed .thinking-panel-body { display: none; }
.thinking-panel.collapsed .thinking-panel-header i { transform: rotate(-90deg); }
.thinking-panel.streaming .thinking-panel-header { color: #c4b5fd; }
.thinking-panel.streaming { border-color: rgba(139,92,246,.35); }

/* Spinner */
.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Chat DOM Window ── */
.chat-load-more {
  text-align: center; padding: 8px 14px;
  font-size: 11px; color: #8b5cf6; cursor: pointer;
  border-radius: 8px; background: rgba(139,92,246,.06);
  transition: background .15s;
}
.chat-load-more:hover { background: rgba(139,92,246,.12); }
.chat-load-info {
  text-align: center; padding: 4px;
  font-size: 10px; color: #475569;
}

/* ── Chat Connection Status ── */
.chat-conn-status {
  font-size: 10px; padding: 3px 8px; border-radius: 10px;
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
  margin-right: 2px;
}
.chat-conn-status.connected { color: #2ed573; background: rgba(46,213,115,.08); }
.chat-conn-status.connecting { color: #f59e0b; background: rgba(245,158,11,.08); }
.chat-conn-status.disconnected { color: #64748b; background: rgba(100,116,139,.08); }

#chatModelSelect {
  padding: 5px 10px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px;
  color: #94a3b8;
  font-size: 11px;
  cursor: pointer;
  outline: none;
  min-width: 100px;
  transition: border-color .2s;
}
#chatModelSelect:hover { border-color: rgba(255,255,255,.15); }
#chatModelSelect:focus { border-color: rgba(99,102,241,.4); }
#chatModelSelect option { background: #1a2736; color: #e2e8f0; }

