/* Prevent flash of unauthorized content — revealed by JS after auth check */
body { opacity: 0; transition: opacity 0.15s ease; }
body.auth-ready { opacity: 1; }

:root {
    /* Color Palette */

    --bg-color: #0d1117;
    --text-primary: #ffffff;
    --text-secondary: #8b949e;
    --primary-color: #0ea5e9;
    --primary-hover: #0284c7;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    
    /* Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --glass-hover-bg: rgba(255, 255, 255, 0.06);

    /* Animation Timing */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    -webkit-font-smoothing: antialiased;
}

/* Background Animated Orbs */
.bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -1;
    opacity: 0.5;
    animation: drift 20s infinite alternate;
}

.orb-1 {
    width: 300px;
    height: 300px;
    background: #0284c7;
    top: -100px;
    left: -100px;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: #f74040; /* ERMA Group brand color */
    opacity: 0.25;       /* Subtly faded into the dark theme */
    bottom: -100px;
    right: -100px;
    animation-delay: -5s;
}

.orb-3 {
    width: 250px;
    height: 250px;
    background: #064e3b;
    top: 40%;
    left: 40%;
    animation-delay: -10s;
}

@keyframes drift {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(30px, -50px) scale(1.1); }
}

/* App Container */
.app-container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Views Management */
.view {
    display: none;
    flex-direction: column;
    flex: 1;
    padding: 24px 24px 40px 24px;
}

.company-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px 24px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-top: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(12px);
    margin-top: auto;
}

.footer-logo {
    max-height: 24px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(14, 165, 233, 0.2));
}

.view.active {
    display: flex;
}

/* Glass Card Reusable */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: var(--glass-shadow);
    padding: 32px;
}

/* UI Typography */
h1 { font-size: 2.5rem; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.02em; }
h2 { font-size: 1.75rem; font-weight: 600; margin-bottom: 4px; }
h3 { font-size: 1.25rem; font-weight: 500; }
h4 { font-size: 1.1rem; font-weight: 600; }
.subtitle { color: var(--text-secondary); font-size: 1rem; font-weight: 400; }

/* Login View Specifics */
.login-card {
    margin: auto 0;
    text-align: center;
}

/* Auth Tab Switcher */
.auth-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 4px;
    margin: 24px 0 8px;
    gap: 4px;
}

.auth-tab {
    flex: 1;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.auth-tab.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}

.auth-tab:not(.active):hover {
    background: var(--glass-hover-bg);
    color: var(--text-primary);
}

.logo-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.app-logo {
    max-width: 140px;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 8px 16px rgba(14, 165, 233, 0.3));
}

.icon-wrapper-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    box-shadow: 0 8px 16px rgba(14, 165, 233, 0.3);
}

.water-icon {
    width: 40px;
    height: 40px;
    color: white;
}

/* Forms & Inputs */
.input-group {
    margin-top: 24px;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

input[type="text"], input[type="email"], input[type="password"], input[type="time"], input[type="number"], .glass-select {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition-fast);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.glass-select {
    background: rgba(0, 0, 0, 0.2) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 16px center;
}
.glass-select option {
    background-color: var(--bg-color);
}

input:focus, .glass-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.1);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 24px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    transition: var(--transition-fast);
    font-family: inherit;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(14, 165, 233, 0.3);
}

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

.btn-secondary {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--glass-hover-bg);
}

.btn-block {
    width: 100%;
    margin-top: 32px;
}

.btn-icon {
    background: transparent;
    color: var(--text-primary);
    padding: 10px;
    border-radius: 50%;
    border: 1px solid transparent;
}

.btn-icon:hover {
    background: var(--glass-bg);
    border-color: var(--glass-border);
}

/* Dashboards and Headers */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
}

.header-titles {
    flex-grow: 1;
    margin-left: 16px;
}

/* Grid for ECUs */
.grid-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.ecu-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 24px;
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    flex-direction: column;
}

.ecu-card:hover {
    background: var(--glass-hover-bg);
    transform: translateY(-4px);
    border-color: rgba(255, 255, 255, 0.15);
}

.ecu-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.ecu-icon {
    background: rgba(14, 165, 233, 0.1);
    color: var(--primary-color);
    padding: 10px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--success);
    margin-right: 8px;
    display: inline-block;
}
.status-dot.pulsing {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse-green 1.5s infinite;
}
.status-dot.idle {
    background-color: var(--text-secondary);
}

@keyframes pulse-green {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.stat-badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

/* ECU Telemetry Band */
.ecu-data-band {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--glass-border);
    flex-wrap: wrap;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.ecu-data-band div {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.2);
    padding: 4px 10px;
    border-radius: 12px;
}

/* ECU Details View Telemetry Panel */
.ecu-telemetry-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.panel-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.panel-item .icon {
    font-size: 1.5rem;
    background: rgba(0,0,0,0.2);
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px;
}
.panel-item .data { display: flex; flex-direction: column; }
.panel-item .data small { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.panel-item .data strong { font-size: 1rem; font-weight: 500; }

/* Valve List */
.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.badge {
    background: var(--primary-color);
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

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

.valve-row {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: var(--transition-fast);
}

.valve-row:hover {
    background: var(--glass-hover-bg);
    border-color: rgba(255, 255, 255, 0.15);
}

.valve-row.is-running {
    border-color: var(--primary-color);
    box-shadow: 0 0 16px rgba(14, 165, 233, 0.15);
}
.running-badge {
    color: var(--primary-color);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    animation: flash 2s infinite;
}
@keyframes flash { 0%, 100% {opacity:1;} 50% {opacity:0.5;} }

.valve-info h4 {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.valve-config {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.config-bubble {
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--glass-border);
}

.telemetry-icons {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.85rem;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid var(--glass-border);
}
.batt-low { color: var(--danger); }

/* QR Scanner Box Simulation */
.qr-scanner-box {
    width: 100%;
    height: 200px;
    background: #000;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed rgba(255,255,255,0.2);
    position: relative;
    overflow: hidden;
}
.scan-frame {
    width: 120px;
    height: 120px;
    border: 4px solid var(--primary-color);
    border-radius: 12px;
    margin-bottom: 12px;
    box-shadow: 0 0 0 200vw rgba(0,0,0,0.5); /* Dim surroundings */
    animation: scanner 2s linear infinite;
}
@keyframes scanner {
    0% { transform: translateY(-5px); }
    50% { transform: translateY(5px); }
    100% { transform: translateY(-5px); }
}

/* Modal Overlay Rest */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    opacity: 1;
    transition: opacity var(--transition-smooth);
}

.modal-content {
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding: 32px 24px;
    margin-bottom: -16px;
}

@media (min-width: 600px) {
    .modal-overlay {
        align-items: center;
    }
    .modal-content {
        border-radius: 24px;
        margin-bottom: 0;
    }
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

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

.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 32px;
}

/* Multi-Program Inputs */
.program-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 16px;
    animation: fadeIn var(--transition-fast) forwards;
}

.program-row .input-group {
    margin-top: 0;
    flex: 1;
}

.btn-small {
    padding: 6px;
    border-radius: 8px;
    background: rgba(14, 165, 233, 0.1);
    color: var(--primary-color);
}
.btn-small:hover {
    background: rgba(14, 165, 233, 0.2);
}

.btn-danger {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.3);
}

/* Smart Features Toggles & Thresholds */
.smart-features-section {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--glass-border);
}

.smart-features-section h4 {
    margin-bottom: 16px;
}

.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 0;
    position: relative;
    z-index: 2;
}

.toggle-info h5 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.toggle-info p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 34px;
    border: 1px solid var(--glass-border);
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

/* Threshold Settings Panels */
.threshold-settings {
    margin: -6px 0 16px 0;
    padding: 20px 16px 16px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0 0 12px 12px;
    border: 1px solid var(--glass-border);
    border-top: none;
    transition: all var(--transition-fast);
    animation: slideDown var(--transition-fast) forwards;
}

.threshold-settings.hidden {
    display: none;
}

.threshold-settings label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: block;
}

.range-group {
    display: flex;
    align-items: center;
    gap: 16px;
}

.range-group input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.1);
    height: 6px;
    border-radius: 3px;
    outline: none;
    padding: 0;
    border: none;
}

.range-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 0 8px rgba(14, 165, 233, 0.5);
}

.range-group span {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--primary-color);
    min-width: 48px;
    text-align: right;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: var(--success);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    opacity: 1;
}

.toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

/* Animations */
.fade-in { animation: fadeIn var(--transition-smooth) forwards; }
.slide-up { animation: slideUp var(--transition-smooth) forwards; }
.slide-down { animation: slideDown var(--transition-smooth) forwards; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }

/* ── Persistent Brand Bar ──────────────────────────────────────────────────── */
.brand-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 50;
    flex-shrink: 0;
}
.brand-bar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-bar-logo {
    max-height: 22px;
    width: auto;
    filter: drop-shadow(0 2px 4px rgba(14,165,233,0.3));
}
.brand-bar-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
}
.brand-bar-name strong {
    color: var(--text-primary);
}

/* ── Language Switcher Dropdown ────────────────────────────────────────────── */
.lang-select {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 5px 28px 5px 10px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: var(--transition-fast);
}
.lang-select:hover {
    border-color: rgba(14,165,233,0.5);
    background-color: rgba(14,165,233,0.08);
}
.lang-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(14,165,233,0.15);
}
.lang-select option {
    background-color: #1a1f2e;
    color: var(--text-primary);
}


