        /* ==================== БАЗОВЫЕ СТИЛИ (ДЕСКТОП) ==================== */
[data-theme="light"] { 
    --bg: #f4f7f6; 
    --card-bg: #ffffff; 
    --card-border: #f0f0f0; 
    --text-main: #2c3e50; 
    --text-sec: #666; 
    --text-muted: #888; 
    --border: #ddd; 
    --log-bg: #2d3748; 
    --log-text: #48bb78; 
    --error-bg: #fff5f5; 
    --error-border: #f5c6cb; 
    --error-text: #721c24; 
    --error-card: #f8d7da; 
    --shadow: rgba(0,0,0,0.05); 
    --search-bg: #ffffff; 
    --filter-bg: #ffffff; 
    --filter-active: #007bff; 
    --stat-card-bg: #ffffff; 
    --btn-export-bg: #6c757d; 
    --btn-group-bg: #17a2b8; 
    --btn-history-bg: #fd7e14; 
    --btn-scan-bg: #28a745; 
    --group-bg: #e9ecef; 
    --group-border: #ced4da; 
    --group-text: #495057; 
    --settings-bg: #ffffff; 
}

[data-theme="dark"] { 
    --bg: #1a1d23; 
    --card-bg: #252830; 
    --card-border: #2d3139; 
    --text-main: #e4e6eb; 
    --text-sec: #b0b3b8; 
    --text-muted: #6b7280; 
    --border: #3d4250; 
    --log-bg: #0d1117; 
    --log-text: #3fb950; 
    --error-bg: #3d1f1f; 
    --error-border: #5c2b2b; 
    --error-text: #f85149; 
    --error-card: #4a2020; 
    --shadow: rgba(0,0,0,0.2); 
    --search-bg: #252830; 
    --filter-bg: #252830; 
    --filter-active: #3b82f6; 
    --stat-card-bg: #252830; 
    --btn-export-bg: #495057; 
    --btn-group-bg: #138496; 
    --btn-history-bg: #e06c00; 
    --btn-scan-bg: #198754; 
    --group-bg: #2c303b; 
    --group-border: #3d4250; 
    --group-text: #e4e6eb; 
    --settings-bg: #252830; 
}

* { 
    transition: background-color 0.3s ease, color 0.2s ease, border-color 0.3s ease; 
    box-sizing: border-box; 
}

body { 
    font-family: 'Segoe UI', system-ui, sans-serif; 
    background: var(--bg); 
    margin: 0; 
    padding: 20px; 
    color: var(--text-main); 
    overflow-y: scroll; 
}

/* ==================== HEADER ==================== */
.header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 20px; 
    flex-wrap: wrap; 
    gap: 10px; 
}

.header h1 { 
    font-size: 24px; 
    margin: 0; 
}

.header-right { 
    display: flex; 
    align-items: center; 
    gap: 15px; 
}

.theme-toggle, .settings-btn { 
    background: var(--card-bg); 
    border: 2px solid var(--border); 
    border-radius: 50%; 
    width: 44px; 
    height: 44px; 
    cursor: pointer; 
    font-size: 20px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    box-shadow: 0 2px 5px var(--shadow); 
    color: var(--text-main); 
}

/* ==================== STATS CARDS ==================== */
.stats { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); 
    gap: 15px; 
    margin-bottom: 20px; 
}

.stat-card { 
    background: var(--stat-card-bg); 
    border-radius: 10px; 
    padding: 15px; 
    text-align: center; 
    box-shadow: 0 2px 5px var(--shadow); 
    border-left: 5px solid #007bff; 
    cursor: pointer; 
    transition: transform 0.2s, box-shadow 0.2s; 
    user-select: none; 
}

.stat-card:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 4px 12px var(--shadow); 
}

.stat-card.active { 
    transform: scale(0.98); 
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.3); 
    opacity: 0.85; 
}

.stat-card.error { border-left-color: #dc3545; } 
.stat-card.moving { border-left-color: #ffc107; } 
.stat-card.ok { border-left-color: #28a745; }

.stat-value { 
    font-size: 36px; 
    font-weight: bold; 
} 

.stat-label { 
    font-size: 13px; 
    color: var(--text-sec); 
    margin-top: 5px; 
}

/* ==================== TOOLBAR ==================== */
.toolbar-compact {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
    padding: 8px 12px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    background: var(--bg);
    color: var(--text-main);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--filter-active);
    color: white;
    transform: translateY(-2px);
}

.icon-btn.scan { 
    background: var(--btn-scan-bg); 
    color: white; 
}

.icon-btn.scan:hover { 
    opacity: 0.8; 
    transform: translateY(-2px); 
}

.compact-select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-main);
    font-size: 13px;
    cursor: pointer;
}

.filter-group {
    display: flex;
    gap: 5px;
    background: var(--bg);
    padding: 4px;
    border-radius: 10px;
}

.filter-chip {
    padding: 6px 12px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-sec);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-chip.active {
    background: var(--filter-active);
    color: white;
}

.filter-chip:hover:not(.active) {
    background: var(--border);
    color: var(--text-main);
}

.search-wrapper {
    flex: 1;
    min-width: 150px;
}

.search-wrapper .search-box {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-main);
}

/* ==================== GRID & CARDS ==================== */
.grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); 
    gap: 15px; 
}

.card { 
    background: var(--card-bg); 
    border-radius: 12px; 
    padding: 15px; 
    box-shadow: 0 4px 6px var(--shadow); 
    border-left: 5px solid #007bff; 
}

.card.moving { border-left-color: #ffc107; } 
.card.error { border-left-color: #dc3545; background: var(--error-bg); animation: pulse 2s infinite; }
.card.fault { border-left-color: #ff9800; background: rgba(255, 152, 0, 0.1); }

@keyframes pulse { 
    50% { box-shadow: 0 4px 15px rgba(220,53,69,0.3); } 
}

.card-title { 
    font-size: 16px; 
    font-weight: 700; 
    margin-bottom: 12px; 
    border-bottom: 2px solid var(--card-border); 
    padding-bottom: 10px; 
    word-break: break-word; 
}

.main-data { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 10px; 
}

.floor { 
    font-size: 52px; 
    font-weight: 800; 
    line-height: 1; 
}

.state { 
    font-size: 13px; 
    font-weight: bold; 
    padding: 5px 10px; 
    border-radius: 6px; 
}

.state-moving { background: #fff3cd; color: #856404; } 
.state-stopped { background: #d4edda; color: #155724; } 
.state-error { background: var(--error-card); color: var(--error-text); }
.state-fault { background: #fff3cd; color: #e67700; }

.details { 
    font-size: 13px; 
    color: var(--text-sec); 
    display: flex; 
    justify-content: space-between; 
    margin-bottom: 8px; 
}

.quality-ok { color: #28a745; font-weight: 600; } 
.quality-bad { color: #dc3545; font-weight: 600; }

.error-box { 
    background: var(--error-card); 
    border: 1px solid var(--error-border); 
    border-radius: 6px; 
    padding: 10px; 
    margin-top: 10px; 
    font-size: 12px; 
    color: var(--error-text); 
}

.log { 
    margin-top: 20px; 
    background: var(--log-bg); 
    color: var(--log-text); 
    padding: 15px; 
    height: 80px; 
    overflow-y: auto; 
    font-family: monospace; 
    font-size: 12px; 
    border-radius: 6px; 
}

/* ==================== MODALS ==================== */
.modal-overlay { 
    display: none; 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(0,0,0,0.7); 
    z-index: 9999; 
    justify-content: center; 
    align-items: center; 
}

.modal-content { 
    background: var(--settings-bg); 
    padding: 30px; 
    border-radius: 12px; 
    width: 90%; 
    max-width: 500px; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.3); 
    text-align: center; 
}

.modal-content.large { 
    max-width: 900px; 
    max-height: 90vh; 
    overflow-y: auto; 
}

.modal-input { 
    width: 100%; 
    padding: 12px; 
    margin: 10px 0; 
    border: 2px solid var(--border); 
    border-radius: 6px; 
    background: var(--search-bg); 
    color: var(--text-main); 
    box-sizing: border-box; 
}

.modal-btn { 
    padding: 12px 24px; 
    background: #007bff; 
    color: white; 
    border: none; 
    border-radius: 6px; 
    cursor: pointer; 
    font-weight: 600; 
}

.modal-btn:hover { opacity: 0.9; }

.setting-row { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 10px 0; 
    border-bottom: 1px solid var(--border); 
}

.switch { 
    position: relative; 
    display: inline-block; 
    width: 46px; 
    height: 24px; 
} 

.switch input { 
    opacity: 0; 
    width: 0; 
    height: 0; 
}

.slider { 
    position: absolute; 
    cursor: pointer; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    background-color: #ccc; 
    transition: .4s; 
    border-radius: 24px; 
}

.slider:before { 
    position: absolute; 
    content: ""; 
    height: 18px; 
    width: 18px; 
    left: 3px; 
    bottom: 3px; 
    background-color: white; 
    transition: .4s; 
    border-radius: 50%; 
}

input:checked + .slider { background-color: #2196F3; } 
input:checked + .slider:before { transform: translateX(22px); }

input[type=range] { 
    -webkit-appearance: none; 
    width: 100px; 
    height: 6px; 
    background: var(--border); 
    border-radius: 5px; 
}

input[type=range]::-webkit-slider-thumb { 
    -webkit-appearance: none; 
    width: 16px; 
    height: 16px; 
    border-radius: 50%; 
    background: #2196F3; 
    cursor: pointer; 
}

/* ==================== TABLES ==================== */
.history-table-container { 
    max-height: 400px; 
    overflow-y: auto; 
    margin-top: 20px; 
    border: 1px solid var(--border); 
    border-radius: 6px; 
}

.history-table { 
    width: 100%; 
    border-collapse: collapse; 
    text-align: left; 
}

.history-table th, .history-table td { 
    padding: 10px; 
    border-bottom: 1px solid var(--border); 
}

.history-table th { 
    background: var(--bg); 
    position: sticky; 
    top: 0; 
}

.badge { 
    padding: 3px 8px; 
    border-radius: 4px; 
    font-size: 12px; 
    font-weight: bold; 
}

.badge-error { background: #f8d7da; color: #721c24; } 
.badge-move { background: #fff3cd; color: #856404; } 
.badge-sys { background: #d1ecf1; color: #0c5460; }

/* ==================== ANALYTICS ==================== */
.chart-container { 
    position: relative; 
    height: 300px; 
    width: 100%; 
    margin-bottom: 20px; 
}

.analytics-grid { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 20px; 
    margin-top: 20px; 
}

.period-selector { 
    display: flex; 
    gap: 10px; 
    margin: 15px 0; 
    flex-wrap: wrap; 
    align-items: center; 
}

.period-btn { 
    padding: 8px 16px; 
    border: 2px solid var(--border); 
    border-radius: 6px; 
    background: var(--filter-bg); 
    cursor: pointer; 
    font-size: 13px; 
    color: var(--text-main); 
}

.period-btn.active { 
    background: var(--filter-active); 
    color: white; 
    border-color: var(--filter-active); 
}

.metrics-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); 
    gap: 15px; 
    margin: 20px 0; 
}

.metric-card { 
    background: var(--card-bg); 
    padding: 15px; 
    border-radius: 8px; 
    text-align: center; 
    border-left: 4px solid #007bff; 
}

.metric-value { 
    font-size: 28px; 
    font-weight: bold; 
    color: var(--text-main); 
}

.metric-label { 
    font-size: 12px; 
    color: var(--text-sec); 
    margin-top: 5px; 
}

/* ==================== DISCRETE BLOCKS ==================== */
.discrete-block { 
    margin-top: 10px; 
    padding-top: 8px; 
    border-top: 1px dashed var(--border); 
    display: flex; 
    flex-direction: column; 
    gap: 6px; 
}

.discrete-row { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    font-size: 13px; 
    padding: 4px 8px; 
    border-radius: 6px; 
    background: var(--bg); 
}

.discrete-row.ok { color: #28a745; background: rgba(40, 167, 69, 0.1); }
.discrete-row.alarm { color: #dc3545; background: rgba(220, 53, 69, 0.15); font-weight: bold; }
.discrete-row.fault { color: #e67700; background: rgba(230, 119, 0, 0.15); }

.discrete-icon { 
    font-size: 16px; 
    width: 20px; 
    text-align: center; 
}

.refresh-status-btn { 
    margin-top: 8px; 
    padding: 5px 10px; 
    font-size: 11px; 
    border-radius: 4px; 
    border: none; 
    cursor: pointer; 
    background: #007bff; 
    color: white; 
    transition: opacity 0.2s; 
    width: 100%; 
}

.refresh-status-btn:hover { opacity: 0.8; }

.voice-buttons { 
    display: flex; 
    gap: 8px; 
    margin-top: 8px; 
}

.call-btn { 
    padding: 5px 10px; 
    font-size: 11px; 
    border-radius: 4px; 
    border: none; 
    cursor: pointer; 
    transition: opacity 0.2s; 
    flex: 1; 
}

.call-btn:hover { opacity: 0.8; }
.call-btn.active { background: #dc3545; color: white; }
.call-machine { background: #17a2b8; color: white; }
.call-cab { background: #28a745; color: white; }

/* ==================== MOBILE OPTIMIZATIONS ==================== */
@media (max-width: 768px) {
    body { padding: 8px; padding-bottom: 80px; }
    .header { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
    .header h1 { font-size: 16px; margin: 0; line-height: 1.2; }
    .header-right { width: 100%; justify-content: space-between; gap: 8px; }
    .theme-toggle, .settings-btn { width: 36px; height: 36px; font-size: 18px; }
    #lastUpdate, #connStatus { font-size: 11px; padding: 4px 8px; }
    .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
    .stat-card { padding: 12px 8px; }
    .stat-value { font-size: 28px; }
    .stat-label { font-size: 11px; }
    .toolbar-compact { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 8px; margin-bottom: 10px; }
    .icon-btn { width: 100%; height: auto; padding: 8px 4px; flex-direction: column; font-size: 10px; gap: 2px; }
    .icon-btn::before { font-size: 20px; }
    .compact-select { grid-column: span 3; font-size: 12px; padding: 6px; }
    .filter-group { grid-column: span 3; justify-content: center; }
    .filter-chip { padding: 6px 10px; font-size: 11px; }
    .search-wrapper { grid-column: span 3; width: 100%; min-width: auto; }
    .grid { grid-template-columns: 1fr; gap: 10px; }
    .card { padding: 12px; }
    .floor { font-size: 40px; }
    .card-title { font-size: 14px; }
    .modal-content.large { max-width: 95%; padding: 20px 15px; max-height: 95vh; }
    .analytics-grid { grid-template-columns: 1fr !important; gap: 15px !important; }
    .chart-container { height: 250px !important; margin-bottom: 15px; }
    .modal-content h2 { font-size: 18px; }
    .modal-content h3 { font-size: 14px; }
    .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .metric-value { font-size: 22px; }
    .metric-label { font-size: 10px; }
    .voice-buttons { flex-direction: column; }
    .history-table-container { overflow-x: auto; }
    .history-table th, .history-table td { padding: 6px; font-size: 12px; }
    .bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card-bg); border-top: 1px solid var(--border); display: flex; justify-content: space-around; padding: 8px 0; z-index: 1000; box-shadow: 0 -2px 10px var(--shadow); }
    .bottom-nav button { background: none; border: none; color: var(--text-sec); font-size: 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; padding: 4px 8px; }
    .bottom-nav button.active { color: var(--filter-active); }
    .bottom-nav button i { font-size: 20px; }
}

@media (max-width: 360px) {
    .header h1 { font-size: 14px; }
    .stats { gap: 6px; }
    .stat-value { font-size: 24px; }
    .toolbar-compact { grid-template-columns: repeat(4, 1fr); }
    .icon-btn { font-size: 9px; padding: 6px 2px; }
    .icon-btn span { display: none; }
    .compact-select, .filter-group { grid-column: span 4; }
    .floor { font-size: 36px; }
}

@media (max-width: 768px) and (orientation: landscape) {
    body { padding: 5px; }
    .header { flex-direction: row; margin-bottom: 8px; }
    .header h1 { font-size: 14px; }
    .stats { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .stat-card { padding: 8px 4px; }
    .stat-value { font-size: 20px; }
    .stat-label { font-size: 9px; }
    .toolbar-compact { grid-template-columns: repeat(6, 1fr); }
    .compact-select, .filter-group, .search-wrapper { grid-column: span 6; }
}

@keyframes loader-slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}