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

body {
    font-family: 'Roboto', sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    overflow: hidden; /* Prevent main page scroll */
}

#app {
    height: 100vh; /* Exact viewport height */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #389cb4 0%, #2f7080 100%);
    color: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: white;
    padding: 4px;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 300;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.offline-indicator {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: #ff9800;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.offline-indicator .material-icons {
    font-size: 1rem;
}

.status-led {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 3px solid #555;
    transition: background-color 0.3s;
}

.status-led.status-ok {
    background-color: #00ff00;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

.status-led.status-warning {
    background-color: #ff8000;
    box-shadow: 0 0 10px rgba(255, 128, 0, 0.5);
}

.status-led.status-error {
    background-color: #ff0000;
    box-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}

.header-logo {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: white;
    padding: 4px;
    margin-left: 1rem;
    cursor: pointer;
    transition: transform 0.2s;
}

.header-logo:hover {
    transform: scale(1.1);
}

/* Main Container */
.main-container {
    flex: 1; /* Takes remaining space after header */
    display: flex;
    gap: 2rem;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    overflow: hidden;
    min-height: 0; /* Allow flex item to shrink */
}

/* Timer Section */
.timer-section {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
}

.section-title {
    text-align: center;
    font-size: 1rem;
    color: #666;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.timer-display {
    text-align: center;
    padding: 3rem 1rem;
    border-radius: 8px;
    background: #f8f9fa;
    margin-bottom: 2rem;
    transition: all 0.3s;
    cursor: pointer;
    user-select: none;
    flex: 1;
}

.timer-display.running {
    background: #e3f2fd;
    box-shadow: 0 0 20px rgba(33, 150, 243, 0.3);
}

.timer-value {
    font-size: 4rem;
    font-weight: 300;
    font-family: 'Roboto Mono', monospace;
    color: #2196f3;
    line-height: 1;
}

.timer-status {
    font-size: 1.2rem;
    color: #666;
    margin-top: 1.5rem;
}

.control-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}



/* Copy Button Success Effect */
.copy-success {
    background: #4caf50 !important;
    color: white !important;
    transform: scale(1.05);
    transition: all 0.3s ease;
}

.copy-success:hover {
    background: #45a049 !important;
}

.precision-toggle {
    text-align: center;
    margin: 1rem 0;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 4px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

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

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

.btn-primary {
    background: #2196f3;
    color: white;
}

.btn-secondary {
    background: #757575;
    color: white;
}

.btn-danger {
    background: #f44336;
    color: white;
}

.btn .material-icons {
    font-size: 20px;
}

/* Results Section */
.results-section {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* Results Actions */
.results-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e0e0e0;
}

.section-header h2 {
    color: #333;
    font-weight: 400;
    margin: 0;
}

.results-table-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    min-height: 0; /* Allow flex item to shrink */
}

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

.results-table thead {
    background: #f5f5f5;
    position: sticky;
    top: 0;
}

.results-table th,
.results-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.results-table th {
    font-weight: 500;
    color: #666;
    text-transform: uppercase;
    font-size: 0.875rem;
}

.results-table tbody tr {
    cursor: pointer;
    transition: background-color 0.2s;
}

.results-table tbody tr:hover {
    background: #f5f5f5;
}

.results-table tbody tr.selected {
    background: #e3f2fd;
}

.result-clean {
    color: #4caf50;
    font-weight: 500;
}

.result-fault {
    color: #f44336;
    font-weight: 500;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: white;
    border-radius: 8px;
    padding: 2rem;
    min-width: 400px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.modal h2 {
    margin-bottom: 1.5rem;
    color: #333;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #666;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: #2196f3;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

.form-control.readonly,
.form-control[readonly] {
    background-color: #f5f5f5;
    color: #666;
    cursor: not-allowed;
    border-color: #ddd;
}

.form-control.readonly:focus,
.form-control[readonly]:focus {
    border-color: #ddd;
    box-shadow: none;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 1024px) {
    body {
        overflow: auto; /* Allow scrolling on mobile */
    }
    
    #app {
        height: auto; /* Allow natural height on mobile */
        min-height: 100vh; /* At least full viewport */
    }
    
    .main-container {
        flex-direction: column;
        height: auto; /* Natural height for vertical layout */
        overflow: visible;
    }
    
    .timer-section,
    .results-section {
        overflow: visible; /* No overflow restrictions on mobile */
    }
    
    .results-table-container {
        max-height: 400px; /* Reasonable max height for mobile */
        min-height: 200px;
    }
    
    .timer-value {
        font-size: 3rem;
    }
}

@media (max-width: 640px) {
    .app-header {
        padding: 1rem;
    }
    
    .main-container {
        padding: 1rem;
        gap: 1rem;
    }
    
    .timer-section,
    .results-section {
        padding: 1rem;
    }
    
    .timer-display {
        padding: 2rem 1rem;
    }
    
    .timer-value {
        font-size: 4.5rem;
    }
    
    .control-buttons {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    .modal {
        min-width: auto;
        width: calc(100% - 2rem);
        margin: 1rem;
    }
}

/* Debug Console */
.debug-console {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 300px;
    background: #1e1e1e;
    color: #d4d4d4;
    border-top: 2px solid #2196f3;
    z-index: 999;
    display: flex;
    flex-direction: column;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: #252526;
    border-bottom: 1px solid #3e3e42;
}

.debug-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
}

.btn-small {
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
}

.debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.debug-section {
    margin-bottom: 1.5rem;
}

.debug-section h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.875rem;
    color: #569cd6;
}

.debug-section pre {
    background: #2d2d30;
    padding: 0.5rem;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.875rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

.debug-messages {
    max-height: 200px;
    overflow-y: auto;
}

.debug-message {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.875rem;
    padding: 0.25rem 0;
    border-bottom: 1px solid #3e3e42;
}

/* Debug Toggle Button */
.debug-toggle {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #757575;
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.3s;
    z-index: 1000;
}

.debug-toggle:hover {
    background: #616161;
    transform: scale(1.1);
}

.debug-toggle.active {
    background: #2196f3;
}

.debug-toggle .material-icons {
    font-size: 24px;
}

/* Test Controls */
.test-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}

.test-status {
    font-size: 0.875rem;
    color: #9e9e9e;
    font-style: italic;
}

.btn-danger {
    background: #f44336;
    color: white;
}

.btn-danger:hover {
    background: #d32f2f;
}

/* Confirmation Modal */
.confirmation-modal {
    max-width: 400px;
    text-align: center;
}

.confirmation-modal p {
    margin: 1rem 0 2rem 0;
    color: #666;
    line-height: 1.5;
}

/* Settings Modal */
.settings-modal {
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.info-modal {
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
}

.info-modal h1 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: #222;
}

.info-modal h2 {
    font-size: 1.2rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: #333;
}

.info-modal p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

.info-modal ol {
    padding-left: 1.2rem;
    margin-bottom: 1.5rem;
}

.info-modal ol li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.info-modal code {
    background: #f2f2f2;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.important-notice {
    background: #fff7cc;
    padding: 14px 16px;
    border: 1px solid #e6d88b;
    border-radius: 8px;
    margin: 12px 0 1.5rem 0;
    font-size: 0.95rem;
    line-height: 1.4;
}

.important-notice ul {
    margin: 8px 0 0 18px;
}

.important-notice li {
    margin-bottom: 4px;
}

.important-notice div {
    margin-top: 8px;
    font-size: 0.9em;
}

.integration-section {
    background: #f9f9f9;
    border-left: 4px solid #0073e6;
    padding: 16px;
    margin: 1.5rem 0;
    border-radius: 4px;
}

.integration-section h2 {
    margin-top: 0;
}

.integration-section p {
    margin-bottom: 0.8rem;
}

.settings-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #e0e0e0;
}

.settings-section:last-of-type {
    border-bottom: none;
    margin-bottom: 1rem;
}

.settings-section h3 {
    margin: 0 0 1rem 0;
    color: #333;
    font-size: 1.1rem;
    font-weight: 500;
}

.api-settings {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 4px;
    border-left: 4px solid #2196f3;
}

.api-test-result {
    margin-left: 1rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
}

.api-test-result.success {
    background: #e8f5e8;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}

.api-test-result.error {
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ffcdd2;
}

.form-group select.form-control {
    background: white;
    cursor: pointer;
}

.form-group input[type="password"] {
    font-family: monospace;
}

/* Template Examples */
.template-examples {
    margin-top: 0.5rem;
}

.template-example {
    margin: 0.5rem 0;
    padding: 0.5rem;
    background: #2d2d30;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.template-example:hover {
    background: #3e3e42;
}

.template-example code {
    color: #d4d4d4;
    font-size: 0.875rem;
    word-break: break-all;
}

.form-help {
    display: block;
    margin-top: 0.5rem;
    color: #666;
    font-size: 0.875rem;
    line-height: 1.4;
}

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

@media (max-width: 640px) {
    .settings-modal {
        max-width: calc(100% - 2rem);
        margin: 1rem;
    }
    
    .api-settings {
        padding: 0.75rem;
    }
    
    .template-example code {
        font-size: 0.75rem;
    }
}
