* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Dark mode loading state - prevents flash */
html.dark-mode-loading {
    background: #0f172a !important;
    color: #f1f5f9 !important;
}

html.dark-mode-loading body {
    background: #0f172a !important;
    color: #f1f5f9 !important;
}

/* Ensure loading state covers common elements */
html.dark-mode-loading .sidebar,
html.dark-mode-loading .top-bar,
html.dark-mode-loading .main-content {
    background: #0f172a !important;
    color: #f1f5f9 !important;
}

:root {
    --primary-blue: #1a73e8;
    --success-green: #22c55e;
    --danger-red: #ef4444;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-900: #111827;
    --sidebar-width: 220px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.app-container { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: #2c3e50;
    color: white;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    transition: background-color 0.2s ease;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-title {
    font-size: 18px;
    font-weight: 600;
}

.nav-item {
    display: block;
    padding: 12px 20px;
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    border-left: 3px solid transparent;
    text-decoration: none;
    transition: all 0.2s;
}

.nav-item:hover { 
    background: rgba(255,255,255,0.1);
    color: white;
}

.nav-item.active {
    background: rgba(26, 115, 232, 0.2);
    border-left-color: var(--primary-blue);
    color: white;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
}

.top-bar {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.page-title {
    font-size: 32px;
    font-weight: 600;
}

.top-bar-btn {
    padding: 8px 16px;
    border: 1px solid var(--gray-200);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.content-area { padding: 30px; }

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    border: 1px solid var(--gray-200);
}

.stat-card-title {
    font-size: 14px;
    color: var(--gray-600);
    margin-bottom: 12px;
}

.stat-card-value {
    font-size: 36px;
    font-weight: 700;
}

/* Device Status */
.device-status-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    border: 1px solid var(--gray-200);
    margin-bottom: 30px;
}

.device-status-visual {
    display: flex;
    align-items: center;
    gap: 40px;
}

.donut-chart {
    position: relative;
    width: 150px;
    height: 150px;
}

.donut-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.donut-center-value { font-size: 32px; font-weight: 700; }

.legend-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--gray-100);
}

.stat-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
}

/* Section Card */
.section-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    border: 1px solid var(--gray-200);
    margin-bottom: 20px;
}

.section-title { font-size: 16px; font-weight: 600; margin-bottom: 20px; }

/* Progress Bar */
.progress-item { margin-bottom: 16px; }
.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 13px;
}

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

.progress-fill {
    height: 100%;
    background: var(--primary-blue);
}

/* Devices Table */
.devices-table-container {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
}

.table-controls {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    gap: 15px;
}

.search-box {
    padding: 8px 12px;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    flex: 1;
    max-width: 300px;
}

.devices-table {
    width: 100%;
    border-collapse: collapse;
}

.devices-table th {
    text-align: left;
    padding: 12px 24px;
    font-size: 13px;
    font-weight: 600;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.devices-table td {
    padding: 16px 24px;
    font-size: 14px;
    border-bottom: 1px solid var(--gray-100);
}

.devices-table tbody tr:hover { background: var(--gray-50); }

/* Settings Button in Table */
.btn-settings {
    padding: 6px 12px;
    background: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-settings:hover {
    background: #1557b0;
    box-shadow: 0 2px 8px rgba(26, 115, 232, 0.3);
    transform: translateY(-1px);
}

.btn-settings:active {
    transform: translateY(0);
}

.status-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.online { background: #dcfce7; color: #166534; }
.status-badge.offline { background: #f3f4f6; color: #6b7280; }
.status-badge.pending { background: #fef3c7; color: #92400e; }

/* Device Details */
.device-details-panel {
    display: none;
    background: var(--gray-50);
    padding: 24px;
}

.device-details-panel.active { display: block; }

/* Bottom Modal for Device Details */
.device-modal {
    display: none;
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    background: white;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    z-index: 1500;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    transition: none; /* Remove transition to prevent animation on resize */
    height: 600px;
    max-height: 80vh;
    min-height: 200px;
}

.device-modal.active {
    display: flex;
    flex-direction: column;
}

.device-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    background: transparent;  /* No dimming effect */
    z-index: 1400;
    pointer-events: none;  /* Allow clicks to pass through */
}

.device-modal-overlay.active {
    display: block;
}

.device-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px 0 24px;  /* Remove bottom padding */
    padding-top: 28px;  /* Make room for resize handle */
    border-bottom: 1px solid var(--gray-200);
    user-select: none;
}

.device-modal-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 32px;  /* Larger hitbox */
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    background: transparent;
    transition: background 0.2s;
}

.device-modal-resize-handle:hover {
    background: rgba(59, 130, 246, 0.08);
}

.device-modal-resize-handle::before {
    content: '';
    width: 50px;
    height: 5px;
    background: var(--gray-400);
    border-radius: 3px;
    transition: all 0.2s;
}

.device-modal-resize-handle:hover::before {
    background: var(--primary-blue);
    width: 60px;
    height: 6px;
}

.device-modal-title {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

.device-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-600);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.device-modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.device-modal-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 24px 24px 24px;  /* Remove top padding */
}

/* Device Tabs */
.device-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 20px;
}

.device-tab {
    padding: 10px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-600);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.device-tab:hover {
    color: var(--primary-blue);
    background: var(--gray-50);
}

.device-tab.active {
    color: var(--primary-blue);
    border-bottom-color: var(--primary-blue);
}

/* Tab Content */
.device-tab-content {
    display: none;
}

.device-tab-content.active {
    display: block;
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 10px;
}

.metric-item {
    padding: 10px;
    background: var(--gray-50);
    border-radius: 6px;
    border: 1px solid var(--gray-200);
}

.metric-label {
    font-size: 12px;
    color: var(--gray-600);
    margin-bottom: 4px;
    font-weight: 500;
}

.metric-value {
    font-size: 14px;
    color: var(--gray-900);
    font-weight: 600;
}

/* Metric Cards */
.metric-card {
    padding: 16px;
    background: white;
    border-radius: 10px;
    border: 1px solid var(--gray-200);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.metric-card:hover {
    border-color: var(--primary-blue);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.metric-card-temp {
    background: linear-gradient(135deg, #fff 0%, #fff8f8 100%);
    border-left: 3px solid #ff6b6b;
}

.metric-card-eye {
    background: linear-gradient(135deg, #fff 0%, #f0f9ff 100%);
    border-left: 3px solid #3b82f6;
}

.metric-card-voltage {
    background: linear-gradient(135deg, #fff 0%, #fff8e6 100%);
    border-left: 3px solid #ffa500;
}

.metric-card-current {
    background: linear-gradient(135deg, #fff 0%, #f0f8ff 100%);
    border-left: 3px solid #4a90e2;
}

.metric-card-digital {
    background: linear-gradient(135deg, #fff 0%, #f0fff4 100%);
    border-left: 3px solid #10b981;
}

/* Historical Metrics */
.historical-metrics-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-record {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 16px;
}

/* Commands Tab Styles */
.commands-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.commands-section {
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 20px;
    background: white;
}

.commands-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.command-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 12px;
    background: white;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
    color: var(--gray-700);
}

.command-btn:hover {
    background: var(--primary-blue);
    border-color: var(--primary-blue);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(26, 115, 232, 0.25);
}

.command-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(26, 115, 232, 0.2);
}

.command-icon {
    font-size: 24px;
}

.command-label {
    font-weight: 500;
    text-align: center;
}

.custom-command-input {
    display: flex;
    align-items: center;
    gap: 10px;
}

.command-btn-send {
    background: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s ease;
}

.command-btn-send:hover {
    background: #1557b0;
    box-shadow: 0 2px 8px rgba(26, 115, 232, 0.3);
}

.command-btn-send:active {
    transform: scale(0.98);
}

.command-response {
    min-height: 80px;
    padding: 15px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    font-size: 14px;
}


.history-record-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--gray-200);
}

/* Status Badge */
.status-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.online {
    background: #E8F5E9;
    color: #2E7D32;
}

.status-badge.idle {
    background: #FFF9C4;
    color: #F57F17;
}

.status-badge.offline {
    background: #FFEBEE;
    color: #C62828;
}

/* Adjust main content when modal is open */
body.modal-open {
    overflow: hidden;
}

@media (max-width: 768px) {
    .device-modal {
        height: 60vh;
        max-height: 90vh;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .device-tab {
        padding: 8px 12px;
        font-size: 13px;
    }
}

.device-tabs {
    display: flex;
    gap: 5px;
    border-bottom: 2px solid var(--gray-200);
    margin: 20px 0;
}

.device-tab {
    padding: 10px 20px;
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.device-tab.active {
    color: var(--primary-blue);
    border-bottom-color: var(--primary-blue);
}

.device-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.device-info-label {
    font-size: 12px;
    color: var(--gray-600);
    margin-bottom: 4px;
}

.device-info-value {
    font-size: 14px;
    font-weight: 500;
}

/* Coming Soon */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state-icon { font-size: 48px; margin-bottom: 16px; }
.coming-soon {
    padding: 6px 12px;
    background: var(--gray-100);
    color: var(--gray-600);
    border-radius: 6px;
    font-size: 13px;
}

.d-none { display: none !important; }

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1100;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.mobile-menu-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--gray-900);
    margin: 4px 0;
    transition: all 0.3s;
}

.mobile-menu-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-btn.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Mobile Overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.mobile-overlay.active {
    display: block;
}

/* Responsive Styles */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 10px rgba(0,0,0,0.3);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-menu-btn {
        display: block;
    }

    .top-bar {
        padding: 15px 15px 15px 60px;
        flex-wrap: wrap;
    }

    .page-title {
        font-size: 24px;
    }

    .top-bar > div:last-child {
        display: none;
    }

    .content-area {
        padding: 15px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-card-value {
        font-size: 28px;
    }

    .device-status-visual {
        flex-direction: column;
        gap: 20px;
    }

    .donut-chart {
        width: 120px;
        height: 120px;
    }

    .section-card,
    .device-status-card {
        padding: 16px;
    }

    .section-title {
        font-size: 14px;
    }

    /* Mobile Table */
    .table-controls {
        flex-direction: column;
        padding: 15px;
        gap: 10px;
    }

    .search-box {
        max-width: 100%;
    }

    .devices-table-container {
        border-radius: 8px;
    }

    .devices-table {
        font-size: 12px;
    }

    .devices-table th,
    .devices-table td {
        padding: 10px 8px;
        font-size: 11px;
    }

    .devices-table th:nth-child(3),
    .devices-table td:nth-child(3),
    .devices-table th:nth-child(4),
    .devices-table td:nth-child(4),
    .devices-table th:nth-child(6),
    .devices-table td:nth-child(6) {
        display: none;
    }

    .status-badge {
        font-size: 10px;
        padding: 3px 8px;
    }

    .device-details-panel {
        padding: 15px;
    }

    .device-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .device-tab {
        padding: 8px 15px;
        font-size: 13px;
        white-space: nowrap;
    }

    .device-info-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .empty-state {
        padding: 40px 15px;
    }

    .empty-state-icon {
        font-size: 36px;
    }

    .top-bar-btn {
        font-size: 13px;
        padding: 6px 12px;
    }

    /* Device modal full width on mobile */
    .device-modal {
        left: 0;
        height: 60vh;
        max-height: 90vh;
    }

    .device-modal-overlay {
        left: 0;
    }
}

@media (max-width: 480px) {
    .page-title {
        font-size: 20px;
    }

    .stat-card-value {
        font-size: 24px;
    }

    .donut-chart {
        width: 100px;
        height: 100px;
    }

    .donut-center-value {
        font-size: 24px;
    }

    .devices-table th:nth-child(5),
    .devices-table td:nth-child(5) {
        display: none;
    }
}

/* ==================== Device Settings Modal ==================== */

.settings-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
}

.settings-modal-overlay.active {
    display: block;
}

.settings-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    display: none;
    flex-direction: column;
    opacity: 0;
    transition: all 0.3s ease;
}

.settings-modal.active {
    display: flex;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.settings-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 2px solid var(--gray-200);
    background: linear-gradient(135deg, var(--primary-blue) 0%, #1557b0 100%);
    color: white;
    border-radius: 12px 12px 0 0;
}

.settings-modal-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.settings-modal-close {
    background: none;
    border: none;
    font-size: 32px;
    cursor: pointer;
    color: white;
    opacity: 0.9;
    transition: opacity 0.2s ease;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.settings-modal-close:hover {
    opacity: 1;
}

.settings-modal-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.settings-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    border-radius: 0 0 12px 12px;
}

/* Settings Tabs */
.settings-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--gray-200);
}

.settings-tab {
    padding: 12px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-600);
    transition: all 0.2s ease;
    margin-bottom: -2px;
}

.settings-tab:hover {
    color: var(--primary-blue);
    background: var(--gray-50);
}

.settings-tab.active {
    color: var(--primary-blue);
    border-bottom-color: var(--primary-blue);
}

.settings-tab-content {
    display: none;
}

.settings-tab-content.active {
    display: block;
}

/* Settings Sections */
.settings-section {
    margin-bottom: 32px;
}

.settings-section h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: var(--gray-900);
}

.settings-help-text {
    color: var(--gray-600);
    font-size: 14px;
    margin-bottom: 20px;
}

/* Form Styles */
.settings-form {
    max-width: 600px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

/* I/O Configuration Grid */
.io-config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.io-config-item {
    padding: 20px;
    background: var(--gray-50);
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    transition: border-color 0.2s ease;
}

.io-config-item:hover {
    border-color: var(--primary-blue);
}

.io-config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.io-config-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
}

/* Calibration Styles */
.calibration-info {
    padding: 16px;
    background: var(--gray-50);
    border-radius: 6px;
    margin-bottom: 20px;
}

#calibration-points-container {
    margin-bottom: 20px;
}

.calibration-point {
    padding: 16px;
    background: white;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    margin-bottom: 16px;
}

.calibration-point-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.calibration-point-header h5 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
}

.calibration-point-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.calibration-formula-box {
    padding: 20px;
    background: linear-gradient(135deg, #e8f4fd 0%, #d4e9f7 100%);
    border: 2px solid var(--primary-blue);
    border-radius: 8px;
    margin-top: 20px;
}

.calibration-formula-box h4 {
    margin: 0 0 12px 0;
    font-size: 16px;
    color: var(--primary-blue);
}

.formula-display {
    padding: 12px 16px;
    background: white;
    border-radius: 6px;
    margin-bottom: 12px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.formula-stats {
    color: var(--gray-700);
    font-size: 13px;
}

/* Button Styles */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-blue);
    color: white;
}

.btn-primary:hover {
    background: #1557b0;
    box-shadow: 0 2px 8px rgba(26, 115, 232, 0.3);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-icon-danger {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.btn-icon-danger:hover {
    background: #fee;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-top: 12px;
    font-size: 13px;
}

.alert-info {
    background: #e3f2fd;
    border: 1px solid #90caf9;
    color: #1565c0;
}

.alert-warning {
    background: #fff3e0;
    border: 1px solid #ffb74d;
    color: #e65100;
}

/* Responsive Design */
@media (max-width: 768px) {
    .settings-modal {
        width: 95%;
        max-height: 90vh;
    }
    
    .io-config-grid {
        grid-template-columns: 1fr;
    }
    
    .calibration-point-inputs {
        grid-template-columns: 1fr;
    }
}

/* Dark Mode Styles */
body.dark-mode {
    --gray-50: #0f172a;
    --gray-100: #1e293b;
    --gray-200: #334155;
    --gray-600: #cbd5e1;
    --gray-700: #e2e8f0;
    --gray-900: #f1f5f9;
    background: #0f172a !important;
    color: #f1f5f9 !important;
}

body.dark-mode .sidebar {
    background: #1e293b;
}

body.dark-mode .top-bar {
    background: #1e293b;
    border-bottom: 1px solid #334155;
}

body.dark-mode .top-bar-btn {
    background: #334155;
    color: #f1f5f9;
}

body.dark-mode .top-bar-btn:hover {
    background: #475569;
}

body.dark-mode .stat-card {
    background: #1e293b;
    border: 1px solid #334155;
}

body.dark-mode .devices-table {
    background: #1e293b;
    border: 1px solid #334155;
}

body.dark-mode .devices-table thead {
    background: #334155;
    color: #f1f5f9;
}

body.dark-mode .devices-table tbody tr {
    border-bottom: 1px solid #334155;
    background: #1e293b;
}

body.dark-mode .devices-table tbody tr:hover {
    background: #334155;
}

body.dark-mode .device-modal {
    background: #1e293b;
    border-top: 1px solid #334155;
}

body.dark-mode .device-modal-header {
    border-bottom: 1px solid #334155;
}

body.dark-mode .device-modal-close:hover {
    background: #334155;
}

body.dark-mode .device-tab {
    color: #cbd5e1;
    border-bottom: 2px solid transparent;
}

body.dark-mode .device-tab:hover {
    background: #334155;
}

body.dark-mode .device-tab.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

body.dark-mode .metric-card {
    background: #334155;
    border: 1px solid #475569;
}

body.dark-mode .metric-card-temp {
    background: linear-gradient(135deg, #1e3a5f 0%, #2d5a8e 100%);
}

body.dark-mode .metric-card-eye {
    background: linear-gradient(135deg, #1e3a5f 0%, #2d5a8e 100%);
}

body.dark-mode .device-info-label {
    color: #94a3b8;
}

body.dark-mode .device-info-value {
    color: #f1f5f9;
}

body.dark-mode .search-box {
    background: #334155;
    border: 1px solid #475569;
    color: #f1f5f9;
}

body.dark-mode .search-box::placeholder {
    color: #94a3b8;
}

body.dark-mode .settings-modal {
    background: #1e293b;
    border: 1px solid #334155;
}

body.dark-mode .settings-header {
    border-bottom: 1px solid #334155;
}

body.dark-mode .settings-close:hover {
    background: #334155;
}

body.dark-mode .settings-tab {
    color: #cbd5e1;
}

body.dark-mode .settings-tab:hover {
    background: #334155;
}

body.dark-mode .settings-tab.active {
    background: #334155;
    color: #3b82f6;
}

body.dark-mode .form-group input,
body.dark-mode .form-group textarea,
body.dark-mode .form-group select {
    background: #334155;
    border: 1px solid #475569;
    color: #f1f5f9;
}

body.dark-mode .btn-primary {
    background: #3b82f6;
}

body.dark-mode .btn-primary:hover {
    background: #2563eb;
}

body.dark-mode .btn-secondary {
    background: #475569;
    color: #f1f5f9;
}

body.dark-mode .btn-secondary:hover {
    background: #64748b;
}

body.dark-mode .command-btn {
    background: #334155;
    color: #f1f5f9;
    border: 1px solid #475569;
}

body.dark-mode .command-btn:hover {
    background: #475569;
    border-color: #64748b;
}

body.dark-mode .command-response {
    background: #334155;
    border: 1px solid #475569;
    color: #cbd5e1;
}

body.dark-mode .hex-dump-container {
    background: #0f172a;
    border: 1px solid #334155;
}

body.dark-mode .hex-offset {
    color: #64748b;
}

body.dark-mode .hex-byte {
    color: #3b82f6;
}

body.dark-mode .hex-ascii {
    color: #10b981;
}
