/* Wergonic Device Manager - Material Design 3 Expressive
 * Accessible design with large fonts and touch targets
 * Dynamic color system with expressive shapes
 */

@import url('https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,300;8..144,400;8..144,500;8..144,600;8..144,700&display=swap');

:root {
    /* M3 Color Tokens - Primary (Blue) */
    --md-sys-color-primary: #1a5fb4;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #d4e3ff;
    --md-sys-color-on-primary-container: #001c3a;

    /* Secondary (Teal) */
    --md-sys-color-secondary: #006a67;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #6ff7f1;
    --md-sys-color-on-secondary-container: #00201f;

    /* Tertiary (Orange/Warm) */
    --md-sys-color-tertiary: #9a4520;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #ffdbc9;
    --md-sys-color-on-tertiary-container: #351000;

    /* Error */
    --md-sys-color-error: #ba1a1a;
    --md-sys-color-on-error: #ffffff;
    --md-sys-color-error-container: #ffdad6;
    --md-sys-color-on-error-container: #410002;

    /* Surface & Background */
    --md-sys-color-surface: #fdfcff;
    --md-sys-color-on-surface: #1a1c1e;
    --md-sys-color-surface-variant: #e0e2ec;
    --md-sys-color-on-surface-variant: #43474e;
    --md-sys-color-surface-container: #eeedf2;
    --md-sys-color-surface-container-low: #f4f3f7;
    --md-sys-color-surface-container-high: #e8e7ec;
    --md-sys-color-surface-container-highest: #e2e2e6;

    /* Outline */
    --md-sys-color-outline: #73777f;
    --md-sys-color-outline-variant: #c3c6cf;

    /* Status Colors */
    --md-sys-color-success: #006d3b;
    --md-sys-color-success-container: #98f7b5;
    --md-sys-color-warning: #7d5800;
    --md-sys-color-warning-container: #ffdf9e;

    /* Elevation (tonal) */
    --md-sys-elevation-1: 0 1px 3px 1px rgba(0,0,0,0.15), 0 1px 2px rgba(0,0,0,0.3);
    --md-sys-elevation-2: 0 2px 6px 2px rgba(0,0,0,0.15), 0 1px 2px rgba(0,0,0,0.3);
    --md-sys-elevation-3: 0 4px 8px 3px rgba(0,0,0,0.15), 0 1px 3px rgba(0,0,0,0.3);

    /* Shape - Expressive (more rounded) */
    --md-sys-shape-corner-none: 0;
    --md-sys-shape-corner-extra-small: 8px;
    --md-sys-shape-corner-small: 12px;
    --md-sys-shape-corner-medium: 16px;
    --md-sys-shape-corner-large: 24px;
    --md-sys-shape-corner-extra-large: 32px;
    --md-sys-shape-corner-full: 9999px;

    /* Typography scale */
    font-size: 18px;
}

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

body {
    font-family: 'Roboto Flex', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    line-height: 1.6;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

/* Touch-friendly interactions */
button, input, select, textarea {
    touch-action: manipulation;
    font-family: inherit;
    font-size: inherit;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px;
}

/* ============ Header ============ */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--md-sys-color-primary);
    letter-spacing: -0.5px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* Debug Mode Toggle - M3 Switch style */
.mode-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
}

.mode-toggle input[type="checkbox"] {
    width: 24px;
    height: 24px;
    cursor: pointer;
    accent-color: var(--md-sys-color-primary);
}

.debug-only {
    display: none;
}

body.debug-mode .debug-only {
    display: block;
}

/* ============ Navigation ============ */
.navigation {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 24px;
    padding: 14px 24px;
    background: var(--md-sys-color-surface-container-low);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-left: 0;
    border-right: 0;
    flex-wrap: wrap;
}

.nav-link {
    padding: 12px 20px;
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-primary);
    text-decoration: none;
    border-radius: var(--md-sys-shape-corner-full);
    border: 1px solid var(--md-sys-color-outline-variant);
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.nav-link:hover {
    background: var(--md-sys-color-primary-container);
    border-color: var(--md-sys-color-primary);
}

.nav-link.active {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border-color: var(--md-sys-color-primary);
}

.nav-version {
    margin-left: auto;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--md-sys-color-on-surface-variant);
    background: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-full);
    padding: 7px 12px;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .navigation {
        padding: 12px 16px;
    }

    .nav-version {
        margin-left: 0;
    }
}

/* Connection Status - M3 Chip style */
.connection-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-full);
    font-size: 1rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
}

.status-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-dot.disconnected {
    background-color: var(--md-sys-color-error);
}

.status-dot.connected {
    background-color: var(--md-sys-color-success);
}

.status-dot.connecting {
    background-color: var(--md-sys-color-warning);
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(0.9); }
}

/* ============ Panels (M3 Cards) ============ */
.panel {
    background: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-sys-shape-corner-extra-large);
    padding: 28px;
    margin-bottom: 24px;
    box-shadow: var(--md-sys-elevation-1);
}

.panel h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    color: var(--md-sys-color-on-surface);
    display: flex;
    align-items: center;
    gap: 12px;
}

.panel h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--md-sys-color-on-surface);
}

/* ============ Buttons (M3 Filled/Tonal/Outlined) ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 28px;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.1px;
    border: none;
    border-radius: var(--md-sys-shape-corner-full);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    min-height: 52px;
    position: relative;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: currentColor;
    opacity: 0;
    transition: opacity 0.2s;
}

.btn:hover::before {
    opacity: 0.08;
}

.btn:active::before {
    opacity: 0.12;
}

.btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

.btn:disabled::before {
    display: none;
}

/* Caching state for Report button */
.btn-success:disabled {
    opacity: 0.5;
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
}

/* Filled Button (Primary) */
.btn-primary {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.btn-primary:hover {
    box-shadow: var(--md-sys-elevation-2);
}

/* Tonal Button (Secondary) */
.btn-secondary {
    background-color: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface);
}

/* Success Button */
.btn-success {
    background-color: var(--md-sys-color-success-container);
    color: var(--md-sys-color-success);
}

/* Warning Button */
.btn-warning {
    background-color: var(--md-sys-color-warning-container);
    color: var(--md-sys-color-warning);
}

/* Success Button */
.btn-success {
    background-color: var(--md-sys-color-success-container, #d4f4dd);
    color: var(--md-sys-color-success, #1e8e3e);
}

/* Danger/Error Button */
.btn-danger {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-error);
}

/* Info Button */
.btn-info {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-secondary);
}

/* Small Button */
.btn-small {
    padding: 12px 20px;
    font-size: 1rem;
    min-height: 48px;
}

/* Active/Selected Button */
.btn.active {
    outline: 3px solid var(--md-sys-color-primary);
    outline-offset: 2px;
}

.btn-success.active {
    outline-color: var(--md-sys-color-success);
}

.btn-danger.active {
    outline-color: var(--md-sys-color-error);
}

.button-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ============ Configuration Grid ============ */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.config-item {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.config-item label {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
}

.config-item label .current-value {
    color: var(--md-sys-color-primary);
    font-weight: 700;
}

.config-item-wide {
    grid-column: 1 / -1;
}

/* ============ Threshold Controls ============ */
.threshold-controls {
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding: 24px;
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-large);
}

.threshold-input-group {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.threshold-input-label {
    font-size: 1.1rem;
    font-weight: 700;
}

.threshold-input-label.yellow-label {
    color: var(--md-sys-color-warning);
}

.threshold-input-label.red-label {
    color: var(--md-sys-color-error);
}

.threshold-slider-container {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* M3 Slider styling */
.threshold-slider {
    flex: 1;
    height: 16px;
    border-radius: var(--md-sys-shape-corner-full);
    appearance: none;
    background: var(--md-sys-color-surface-container-highest);
    cursor: pointer;
}

.threshold-slider::-webkit-slider-thumb {
    appearance: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--md-sys-elevation-2);
    border: 4px solid var(--md-sys-color-surface);
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.threshold-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.threshold-slider.yellow-slider::-webkit-slider-thumb {
    background: var(--md-sys-color-warning);
}

.threshold-slider.red-slider::-webkit-slider-thumb {
    background: var(--md-sys-color-error);
}

.threshold-slider::-moz-range-thumb {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 4px solid var(--md-sys-color-surface);
    cursor: pointer;
    box-shadow: var(--md-sys-elevation-2);
}

.threshold-slider.yellow-slider::-moz-range-thumb {
    background: var(--md-sys-color-warning);
}

.threshold-slider.red-slider::-moz-range-thumb {
    background: var(--md-sys-color-error);
}

.threshold-input-value {
    min-width: 80px;
    font-size: 1.75rem;
    font-weight: 700;
    text-align: right;
    color: var(--md-sys-color-on-surface);
}

.threshold-hint {
    font-size: 0.95rem;
    color: var(--md-sys-color-on-surface-variant);
    margin-top: 8px;
}

.config-section {
    margin-top: 32px;
    padding-top: 28px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
}

/* ============ Inputs (M3 Filled Text Field style) ============ */
input[type="text"],
input[type="datetime-local"] {
    padding: 16px 20px;
    font-size: 1.1rem;
    border: none;
    border-radius: var(--md-sys-shape-corner-small);
    outline: none;
    background: var(--md-sys-color-surface-container-highest);
    color: var(--md-sys-color-on-surface);
    min-height: 56px;
    transition: background 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
input[type="datetime-local"]:focus {
    background: var(--md-sys-color-surface-container);
    box-shadow: inset 0 -2px 0 0 var(--md-sys-color-primary);
}

input::placeholder {
    color: var(--md-sys-color-on-surface-variant);
}

.datetime-input,
.session-input {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.datetime-input input,
.session-input input {
    flex: 1;
    min-width: 220px;
}

/* ============ Live Data (M3 Cards) ============ */
.live-data-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.data-card {
    text-align: center;
    padding: 28px 20px;
    background: var(--md-sys-color-primary-container);
    border-radius: var(--md-sys-shape-corner-large);
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.data-card:hover {
    transform: translateY(-2px);
}

.data-card label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--md-sys-color-on-primary-container);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.data-value {
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--md-sys-color-on-primary-container);
    line-height: 1;
}

.data-unit {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--md-sys-color-on-primary-container);
    opacity: 0.8;
}

.zone-indicator.green {
    color: var(--md-sys-color-success);
}
.zone-indicator.yellow {
    color: var(--md-sys-color-warning);
}
.zone-indicator.red {
    color: var(--md-sys-color-error);
}

/* ============ File List ============ */
.file-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.file-list {
    max-height: 350px;
    overflow-y: auto;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-large);
    background: var(--md-sys-color-surface);
}

.file-list .placeholder {
    padding: 32px;
    text-align: center;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 1.05rem;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    transition: background 0.15s;
}

.file-item:last-child {
    border-bottom: none;
}

.file-item:hover {
    background: var(--md-sys-color-surface-container-low);
}

.file-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.file-name {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--md-sys-color-on-surface);
}

.file-size {
    font-size: 0.9rem;
    color: var(--md-sys-color-on-surface-variant);
}

.file-actions-inline {
    display: flex;
    gap: 8px;
}

/* ============ Progress Bar ============ */
.download-progress {
    margin-top: 20px;
    padding: 20px;
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-medium);
}

.progress-bar {
    height: 8px;
    background: var(--md-sys-color-surface-container-highest);
    border-radius: var(--md-sys-shape-corner-full);
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    background: var(--md-sys-color-primary);
    border-radius: var(--md-sys-shape-corner-full);
    transition: width 0.3s cubic-bezier(0.2, 0, 0, 1);
    width: 0%;
}

#progressText {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
}

/* ============ Console ============ */
.console-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.console-actions input {
    flex: 1;
}

.console-output {
    height: 220px;
    overflow-y: auto;
    background: var(--md-sys-color-on-surface);
    color: var(--md-sys-color-success-container);
    font-family: 'Roboto Mono', 'Monaco', monospace;
    font-size: 0.95rem;
    padding: 20px;
    border-radius: var(--md-sys-shape-corner-medium);
}

.console-output .log-entry {
    margin-bottom: 6px;
    white-space: pre-wrap;
    word-break: break-all;
}

.console-output .log-entry.sent {
    color: var(--md-sys-color-primary-container);
}

.console-output .log-entry.received {
    color: var(--md-sys-color-success-container);
}

.console-output .log-entry.error {
    color: var(--md-sys-color-error-container);
}

.console-output .log-entry.info {
    color: var(--md-sys-color-surface-variant);
}

/* ============ Modal (M3 Dialog) ============ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--md-sys-color-surface-container-high);
    border-radius: var(--md-sys-shape-corner-extra-large);
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--md-sys-elevation-3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 28px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.modal-header h3 {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
}

.modal-close {
    background: var(--md-sys-color-surface-container);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.modal-close:hover {
    background: var(--md-sys-color-surface-container-highest);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
}

.modal-body pre {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.95rem;
    white-space: pre-wrap;
    word-break: break-all;
    background: var(--md-sys-color-surface-container);
    padding: 20px;
    border-radius: var(--md-sys-shape-corner-medium);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 28px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
}

/* ============ Device Info ============ */
.device-info {
    margin-top: 20px;
    padding: 20px;
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-medium);
}

.device-info p {
    margin-bottom: 10px;
    font-size: 1.05rem;
}

/* ============ Version Badge (M3 Badge) ============ */
.version-badge {
    display: inline-block;
    padding: 6px 14px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--md-sys-shape-corner-full);
    background-color: var(--md-sys-color-success-container);
    color: var(--md-sys-color-success);
}

.version-badge.version-legacy {
    background-color: var(--md-sys-color-warning-container);
    color: var(--md-sys-color-warning);
}

/* Feature Badge */
.feature-badge {
    display: inline-block;
    padding: 4px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--md-sys-shape-corner-full);
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-secondary);
    vertical-align: middle;
    margin-left: 10px;
}

/* Feature Unavailable State */
.feature-unavailable {
    position: relative;
    opacity: 0.5;
    pointer-events: none;
}

.feature-unavailable::after {
    content: "Requires firmware v4.0+";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--md-sys-color-on-surface);
    color: var(--md-sys-color-surface);
    padding: 14px 24px;
    border-radius: var(--md-sys-shape-corner-medium);
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    z-index: 10;
}

.feature-unavailable .feature-badge {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-error);
}

/* ============ Multi-Device Connection Grid ============ */
.device-connection-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.device-card {
    background: var(--md-sys-color-surface);
    border-radius: var(--md-sys-shape-corner-large);
    padding: 24px;
    border: 2px solid var(--md-sys-color-outline-variant);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.device-card.connected {
    border-color: var(--md-sys-color-success);
    box-shadow: var(--md-sys-elevation-2);
}

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

.device-type-label {
    font-size: 1.1rem;
    font-weight: 700;
    padding: 6px 16px;
    border-radius: var(--md-sys-shape-corner-full);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.device-type-label.arm-label {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.device-type-label.trunk-label {
    background: var(--md-sys-color-tertiary-container);
    color: var(--md-sys-color-on-tertiary-container);
}

.device-status-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.device-status-dot.disconnected {
    background-color: var(--md-sys-color-outline);
}

.device-status-dot.connected {
    background-color: var(--md-sys-color-success);
}

.device-status-dot.connecting {
    background-color: var(--md-sys-color-warning);
}

.device-card-body {
    margin-bottom: 20px;
}

.device-card-body .device-name {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
    margin-bottom: 4px;
}

.device-card-body .device-firmware {
    font-size: 0.95rem;
    color: var(--md-sys-color-on-surface-variant);
}

.device-card-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.device-card-actions .btn {
    flex: 1;
    min-width: 120px;
}

/* Both Devices Actions */
.both-devices-actions {
    display: flex;
    gap: 16px;
    padding-top: 20px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
}

.both-devices-actions .btn {
    flex: 1;
}

/* ============ Config Target Selector ============ */
.config-target-selector {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
    padding: 20px;
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-medium);
}

.config-target-selector > label {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
    white-space: nowrap;
}

.config-target-selector .button-group {
    flex: 1;
}

.config-hint {
    font-size: 0.9rem;
    color: var(--md-sys-color-on-surface-variant);
    font-style: italic;
    margin-top: 8px;
}

/* ============ Device-Specific Threshold Sections ============ */
.threshold-device-section {
    padding: 20px;
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-large);
    border: 2px solid var(--md-sys-color-outline-variant);
}

.threshold-device-section .threshold-controls {
    background: transparent;
    padding: 0;
}

.threshold-device-label {
    display: inline-block;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 8px 16px;
    border-radius: var(--md-sys-shape-corner-small);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.threshold-device-label.arm-label {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.threshold-device-label.trunk-label {
    background: var(--md-sys-color-tertiary-container);
    color: var(--md-sys-color-on-tertiary-container);
}

/* ============ Disconnected Device State ============ */
.device-disconnected {
    opacity: 0.4;
    pointer-events: none;
    position: relative;
}

.device-disconnected::after {
    content: 'Not Connected';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--md-sys-color-surface-container-highest);
    color: var(--md-sys-color-on-surface-variant);
    padding: 10px 20px;
    border-radius: var(--md-sys-shape-corner-full);
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    z-index: 10;
    box-shadow: var(--md-sys-elevation-1);
}

/* Allow clicking on live data even when disconnected (for visual feedback) */
.live-data-device.device-disconnected {
    pointer-events: auto;
}

.live-data-device.device-disconnected::after {
    display: none;
}

/* ============ Dual Live Data Display ============ */
.dual-live-data {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.live-data-device {
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-large);
    padding: 24px;
}

.live-data-device .live-data-grid {
    grid-template-columns: repeat(2, 1fr);
}

.device-data-label {
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 20px;
    padding: 8px 16px;
    border-radius: var(--md-sys-shape-corner-small);
    display: inline-block;
}

.device-data-label.arm-label {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.device-data-label.trunk-label {
    background: var(--md-sys-color-tertiary-container);
    color: var(--md-sys-color-on-tertiary-container);
}

/* ============ File Device Selector ============ */
.file-device-selector {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px 20px;
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-medium);
}

.file-device-selector > label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
}

/* Console device select */
.console-actions select {
    padding: 12px 16px;
    font-size: 1rem;
    border: none;
    border-radius: var(--md-sys-shape-corner-small);
    background: var(--md-sys-color-surface-container-highest);
    color: var(--md-sys-color-on-surface);
    min-height: 48px;
    cursor: pointer;
}

/* ============ Utilities ============ */
.hidden {
    display: none !important;
}

/* ============ Responsive - Tablet ============ */
@media (max-width: 768px) {
    :root {
        font-size: 17px;
    }

    .container {
        padding: 20px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .config-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .live-data-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .data-value {
        font-size: 2.75rem;
    }

    .btn {
        padding: 14px 22px;
    }

    .btn-small {
        padding: 12px 18px;
    }

    .threshold-slider::-webkit-slider-thumb {
        width: 40px;
        height: 40px;
    }

    .threshold-slider::-moz-range-thumb {
        width: 40px;
        height: 40px;
    }

    /* Multi-device tablet */
    .device-connection-grid {
        grid-template-columns: 1fr;
    }

    .dual-live-data {
        grid-template-columns: 1fr;
    }

    .config-target-selector {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .both-devices-actions {
        flex-direction: column;
    }
}

/* ============ Responsive - Mobile ============ */
@media (max-width: 600px) {
    :root {
        font-size: 16px;
    }

    .container {
        padding: 16px;
    }

    header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }

    header h1 {
        font-size: 1.4rem;
    }

    .header-controls {
        flex-direction: column;
        gap: 16px;
        width: 100%;
    }

    .connection-status {
        width: 100%;
        justify-content: center;
    }

    .mode-toggle {
        justify-content: center;
    }

    .panel {
        padding: 20px;
        border-radius: var(--md-sys-shape-corner-large);
    }

    .panel h2 {
        font-size: 1.2rem;
    }

    .config-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .config-item-wide {
        grid-column: 1;
    }

    .live-data-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .data-card {
        padding: 24px;
    }

    .data-value {
        font-size: 3rem;
    }

    .button-group {
        flex-wrap: wrap;
        justify-content: stretch;
    }

    .button-group .btn {
        flex: 1;
        min-width: calc(50% - 6px);
    }

    .btn {
        padding: 16px 24px;
        font-size: 1.05rem;
        min-height: 56px;
    }

    .btn-small {
        padding: 14px 20px;
        font-size: 1rem;
        min-height: 52px;
    }

    /* Threshold controls mobile */
    .threshold-controls {
        padding: 20px;
    }

    .threshold-slider-container {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .threshold-slider {
        height: 20px;
    }

    .threshold-slider::-webkit-slider-thumb {
        width: 44px;
        height: 44px;
    }

    .threshold-slider::-moz-range-thumb {
        width: 44px;
        height: 44px;
    }

    .threshold-input-value {
        text-align: center;
        font-size: 2rem;
    }

    .threshold-hint {
        text-align: center;
    }

    /* Inputs mobile */
    .datetime-input,
    .session-input {
        flex-direction: column;
    }

    .datetime-input input,
    .session-input input {
        width: 100%;
        padding: 16px 20px;
        font-size: 1.1rem;
        min-height: 56px;
    }

    /* Console mobile */
    .console-output {
        height: 180px;
        font-size: 0.9rem;
    }

    .console-actions {
        flex-wrap: wrap;
    }

    .console-actions input {
        width: 100%;
        margin-bottom: 12px;
    }

    /* File list mobile */
    .file-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
        padding: 20px;
    }

    .file-actions-inline {
        width: 100%;
        justify-content: flex-end;
    }

    /* Modal mobile */
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 16px;
        border-radius: var(--md-sys-shape-corner-large);
    }

    .modal-header {
        padding: 20px;
    }

    .modal-body {
        padding: 20px;
    }

    .modal-body pre {
        font-size: 0.85rem;
    }

    .modal-footer {
        padding: 16px 20px;
        flex-direction: column;
        gap: 12px;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* Multi-device mobile */
    .device-card {
        padding: 20px;
    }

    .device-card-actions {
        flex-direction: column;
    }

    .device-card-actions .btn {
        width: 100%;
    }

    .live-data-device {
        padding: 20px;
    }

    .live-data-device .live-data-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .file-device-selector {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
}

/* ============ Responsive - Small Mobile ============ */
@media (max-width: 380px) {
    .container {
        padding: 12px;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .panel {
        padding: 16px;
    }

    .btn-small {
        padding: 12px 16px;
        font-size: 0.95rem;
    }

    .button-group {
        gap: 8px;
    }

    .threshold-input-label {
        font-size: 1rem;
    }

    .data-value {
        font-size: 2.5rem;
    }
}

/* ============ Report Modal ============ */

.modal-wide {
    max-width: 95vw;
    width: 1400px;
}

.report-container {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.report-section {
    background: var(--md-sys-color-surface-container-low);
    padding: 24px;
    border-radius: 16px;
}

.report-section h4 {
    margin: 0 0 20px 0;
    color: var(--md-sys-color-primary);
    font-size: 1.3rem;
    font-weight: 600;
}

/* Metadata Grid */
.metadata-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.metadata-item {
    padding: 12px 16px;
    background: var(--md-sys-color-surface);
    border-radius: 12px;
    border-left: 4px solid var(--md-sys-color-primary);
}

.metadata-item strong {
    color: var(--md-sys-color-on-surface-variant);
    display: block;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.metadata-item.highlight {
    background: var(--md-sys-color-tertiary-container);
    border-left-color: var(--md-sys-color-tertiary);
    font-weight: 500;
}

/* Time Range Selection Controls */
.time-range-controls {
    background: var(--md-sys-color-surface-container-low);
    padding: 20px;
    border-radius: 16px;
    border: 2px solid var(--md-sys-color-outline-variant);
}

.range-slider-container {
    margin-bottom: 16px;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.95rem;
    color: var(--md-sys-color-on-surface-variant);
}

.range-duration {
    font-weight: 600;
    color: var(--md-sys-color-primary);
    font-size: 1rem;
}

.dual-range-wrapper {
    position: relative;
    height: 40px;
}

.range-slider {
    position: absolute;
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    outline: none;
    pointer-events: none;
}

.range-slider::-webkit-slider-track {
    height: 8px;
    background: var(--md-sys-color-outline-variant);
    border-radius: 4px;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--md-sys-color-primary);
    border: 3px solid white;
    border-radius: 50%;
    cursor: pointer;
    pointer-events: all;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

.range-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.range-slider::-moz-range-track {
    height: 8px;
    background: var(--md-sys-color-outline-variant);
    border-radius: 4px;
}

.range-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--md-sys-color-primary);
    border: 3px solid white;
    border-radius: 50%;
    cursor: pointer;
    pointer-events: all;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

.range-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.range-slider.range-start {
    z-index: 2;
}

.range-slider.range-end {
    z-index: 1;
}

.range-slider.range-end::-webkit-slider-thumb {
    background: var(--md-sys-color-secondary);
}

.range-slider.range-end::-moz-range-thumb {
    background: var(--md-sys-color-secondary);
}

.range-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Chart Container */
#reportChart {
    max-height: 500px;
    width: 100%;
}

/* Statistics Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--md-sys-color-surface);
    padding: 20px;
    border-radius: 16px;
    text-align: center;
    border: 2px solid var(--md-sys-color-outline-variant);
    transition: all 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.stat-label {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 8px;
}

.stat-value {
    color: var(--md-sys-color-on-surface);
    font-size: 1.8rem;
    font-weight: 700;
}

.stat-card.green-stat {
    background: var(--md-sys-color-success-container);
    border-color: var(--md-sys-color-success);
}

.stat-card.green-stat .stat-value {
    color: var(--md-sys-color-success);
}

.stat-card.yellow-stat {
    background: #fff8e1;
    border-color: var(--md-sys-color-warning);
}

.stat-card.yellow-stat .stat-value {
    color: var(--md-sys-color-warning);
}

.stat-card.red-stat {
    background: var(--md-sys-color-error-container);
    border-color: var(--md-sys-color-error);
}

.stat-card.red-stat .stat-value {
    color: var(--md-sys-color-error);
}

.stat-card.improvement {
    background: linear-gradient(135deg, #e3f2fd 0%, #c8e6c9 100%);
    border-color: var(--md-sys-color-success);
}

.stat-card.improvement .stat-value {
    color: var(--md-sys-color-success);
}

/* Histogram Statistics */
.histogram-stats {
    margin-top: 24px;
}

.histogram-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.hist-stat-card {
    background: var(--md-sys-color-surface-container-low);
    padding: 16px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid var(--md-sys-color-outline-variant);
    transition: all 0.2s ease;
}

.hist-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.hist-stat-card.primary {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border: 2px solid var(--md-sys-color-primary);
}

.hist-stat-label {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 6px;
}

.hist-stat-value {
    color: var(--md-sys-color-on-surface);
    font-size: 1.4rem;
    font-weight: 700;
}

.hist-stat-card.primary .hist-stat-value {
    color: var(--md-sys-color-primary);
}

.skewness-interpretation {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    padding: 16px;
    border-radius: 12px;
    text-align: center;
    font-size: 0.95rem;
    margin-top: 16px;
}

.skewness-interpretation strong {
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}

/* Achievements Grid */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.achievement-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--md-sys-color-surface);
    border-radius: 16px;
    border: 2px solid var(--md-sys-color-outline-variant);
    transition: all 0.3s ease;
}

.achievement-card:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.achievement-card.gold {
    background: linear-gradient(135deg, #fff9c4 0%, #ffeb3b 100%);
    border-color: #fbc02d;
}

.achievement-card.silver {
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
    border-color: #9e9e9e;
}

.achievement-card.bronze {
    background: linear-gradient(135deg, #ffe0b2 0%, #ffb74d 100%);
    border-color: #f57c00;
}

.achievement-icon {
    font-size: 3rem;
    line-height: 1;
}

.achievement-content {
    flex: 1;
}

.achievement-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
    margin-bottom: 4px;
}

.achievement-description {
    font-size: 0.95rem;
    color: var(--md-sys-color-on-surface-variant);
}

/* Report Responsive */
@media (max-width: 768px) {
    .modal-wide {
        width: 95vw;
        max-width: 95vw;
    }
    
    .report-section {
        padding: 16px;
    }
    
    .metadata-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }
    
    .stat-value {
        font-size: 1.4rem;
    }
    
    .achievements-grid {
        grid-template-columns: 1fr;
    }
    
    .achievement-icon {
        font-size: 2.5rem;
    }
}
