:root {
    --sidebar-width: 240px;
    --log-panel-height: 200px;
    --sidebar-bg: #1a1a2e;
    --sidebar-text: #a0aec0;
    --sidebar-active: #e53e3e;
    --sidebar-hover: #2a2a42;
    --main-bg: #f7f8fc;
    --card-bg: #ffffff;
    --primary: #e53e3e;
    --primary-hover: #c53030;
    --success: #38a169;
    --info: #3182ce;
    --warning: #dd6b20;
    --danger: #e53e3e;
    --danger-hover: #c53030;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --text-muted: #a0aec0;
    --border: #e2e8f0;
    --border-light: #edf2f7;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --radius: 8px;
    --radius-lg: 12px;
    --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
    --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: var(--main-bg);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
}

.app-layout { display: flex; flex: 1; min-height: 0; overflow: hidden; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.content-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 16px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    gap: 14px;
}

.logo-link {
    display: block;
    width: 100%;
    text-align: center;
    transition: opacity var(--transition);
}

.logo-link:hover { opacity: 0.85; }

.logo-img {
    width: 100%;
    max-width: 176px;
    height: auto;
    filter: brightness(1.1);
    display: block;
    margin: 0 auto;
}

.app-title-group { text-align: center; width: 100%; }
.app-title { font-size: 1.15rem; font-weight: 700; color: #fff; letter-spacing: 0.02em; }
.app-subtitle { font-size: 0.75rem; color: rgba(148,163,184,0.65); margin-top: 4px; }

.sidebar-connection {
    padding: 16px 16px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.btn-connect {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: var(--radius);
    background: transparent;
    color: #e2e8f0;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-connect:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.25); }
.btn-connect:active { transform: scale(0.98); }

.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.disconnected { background: #ef4444; }
.status-dot.connected { background: #10b981; box-shadow: 0 0 6px rgba(16,185,129,0.5); }

.device-brief {
    margin-top: 10px;
    padding: 8px 10px;
    background: rgba(255,255,255,0.05);
    border-radius: 6px;
    font-size: 0.8rem;
}

.device-chip { color: #e2e8f0; font-weight: 600; }

.sidebar-nav {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 6px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
}

.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-item.active { background: var(--sidebar-active); color: #ffffff; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-icon { opacity: 0.7; flex-shrink: 0; }

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.7rem;
    color: rgba(148,163,184,0.6);
    text-align: center;
}

.sidebar-footer p { line-height: 1.6; }

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h2 { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); }
.page-body { display: flex; flex-direction: column; gap: 20px; }
.hidden { display: none !important; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-info { background: var(--info); color: white; }
.btn-info:hover:not(:disabled) { background: #0891b2; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; width: 100%; }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    transition: background var(--transition);
}

.btn-icon:hover { background: rgba(255,255,255,0.1); }

.form-row { display: flex; gap: 16px; align-items: flex-end; }
.form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; }

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

select {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--card-bg);
    color: var(--text-primary);
    transition: border-color var(--transition);
    outline: none;
}

select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(229,62,62,0.12); }

.bsl-hint {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 14px 16px;
    color: #92400e;
    font-size: 0.85rem;
    line-height: 1.6;
}

.bsl-hint svg { flex-shrink: 0; margin-top: 2px; color: var(--warning); }

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--card-bg);
}

.drop-zone:hover { border-color: var(--primary); background: #fff5f5; }
.drop-zone.drag-over { border-color: var(--primary); background: #fed7d7; transform: scale(1.005); }
.drop-zone.has-file { border-style: solid; border-color: var(--success); background: #f0fdf4; }
.file-input-hidden { display: none; }
.drop-zone-content { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.drop-icon { color: var(--text-muted); }
.drop-text { font-size: 0.95rem; color: var(--text-primary); font-weight: 500; }
.drop-hint { font-size: 0.8rem; color: var(--text-muted); }

.file-info {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.info-item { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; letter-spacing: 0.03em; }
.info-value { font-size: 0.9rem; color: var(--text-primary); font-weight: 500; font-family: var(--font-mono); }

.progress-container {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.progress-bar {
    height: 8px;
    background: var(--border-light);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), #fc8181);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.erase-mass {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.erase-mass-info h3 { font-size: 1rem; margin-bottom: 4px; }
.erase-mass-info p { font-size: 0.85rem; color: var(--text-secondary); }

.device-info-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.no-device-hint { color: var(--text-muted); text-align: center; padding: 20px 0; }

.device-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.device-info-item { display: flex; flex-direction: column; gap: 4px; }
.device-info-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }
.device-info-value { font-size: 0.95rem; font-weight: 500; font-family: var(--font-mono); }

.flash-map { display: flex; gap: 4px; margin-bottom: 24px; height: 48px; }

.flash-sector-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    overflow: hidden;
    padding: 2px;
}

.flash-sector-bar span { line-height: 1.2; }

.changelog { display: flex; flex-direction: column; gap: 12px; }

.changelog-item {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.changelog-version {
    display: inline-block;
    background: var(--primary);
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 700;
    margin-right: 8px;
}

.changelog-item p { margin-top: 8px; font-size: 0.9rem; color: var(--text-secondary); line-height: 1.6; }

h3 { font-size: 1rem; margin-bottom: 12px; color: var(--text-primary); }

.log-panel {
    border-top: 1px solid var(--border);
    background: var(--card-bg);
    flex-shrink: 0;
}

.log-panel.collapsed .log-output { display: none; }

.log-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--border);
}

.log-panel-title { font-weight: 600; font-size: 0.85rem; color: var(--text-secondary); }
.log-controls { display: flex; align-items: center; gap: 6px; }

.log-output {
    height: var(--log-panel-height);
    overflow-y: auto;
    padding: 8px 16px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.6;
    background: #1a1a2e;
}

.log-line { padding: 1px 0; }
.log-info { color: #94a3b8; }
.log-success { color: #34d399; }
.log-warn { color: #fbbf24; }
.log-error { color: #f87171; }
.log-time { color: #475569; margin-right: 6px; }

.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    color: white;
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.08);
    pointer-events: auto;
    animation: toastIn 0.3s ease-out;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); color: #1e293b; }
.toast.info { background: var(--info); }

@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }

.site-footer {
    background: var(--sidebar-bg);
    border-top: 1px solid rgba(255,255,255,0.06);
    padding: 10px 20px;
    flex-shrink: 0;
}

.site-footer-inner {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px 4px;
    font-size: 0.72rem;
    color: rgba(148,163,184,0.6);
}

.site-footer-inner a {
    color: rgba(148,163,184,0.7);
    text-decoration: none;
    transition: color var(--transition);
}

.site-footer-inner a:hover { color: #94a3b8; }

.footer-sep {
    color: rgba(148,163,184,0.3);
    user-select: none;
}

@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }
    .sidebar-header { padding: 10px 16px; border-bottom: none; }
    .app-subtitle { display: none; }
    .sidebar-connection { padding: 8px 12px; border-bottom: none; border-left: 1px solid rgba(255,255,255,0.08); margin-left: auto; }
    .device-brief { display: none; }
    .sidebar-nav { flex-direction: row; width: 100%; overflow-x: auto; padding: 4px 8px; border-top: 1px solid rgba(255,255,255,0.08); gap: 2px; }
    .nav-item { padding: 8px 12px; flex-shrink: 0; }
    .nav-text { display: none; }
    .sidebar-footer { display: none; }
    .content-wrapper { padding: 16px; }
    .form-row { flex-direction: column; }
}
