/* ═══════════════════════════════════════════════════════════════════════════
   HVACProbe Dashboard Theme — Shared Design System
   Matches the main dashboard.html styling
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── CSS Variables ─── */
:root {
    --bg-primary: #000000;
    --bg-secondary: #121212;
    --bg-card: #1a1a1a;
    --bg-card-hover: #1e1e1e;
    --bg-header: #1e1e1e;
    --bg-input: #252525;
    --bg-modal-overlay: rgba(0,0,0,0.7);
    --border-color: #333;
    --border-light: #444;
    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --text-muted: #888;
    --text-dim: #666;
    --accent-teal: #4ecdc4;
    --accent-silver: #c0c0c0;
    --accent-silver-light: #e8e8e8;
    --accent-red: #e74c3c;
    --accent-green: #2ecc71;
    --accent-purple: #6c5ce7;
    --accent-blue: #3498db;
    --accent-orange: #f39c12;
    --gradient-header: linear-gradient(145deg, #1e1e1e, #2a2a2a);
    --gradient-silver: linear-gradient(45deg, #c0c0c0, #e8e8e8);
    --gradient-teal: linear-gradient(45deg, #4ecdc4, #44a08d);
    --gradient-red: linear-gradient(45deg, #e74c3c, #c0392b);
    --gradient-purple: linear-gradient(45deg, #6c5ce7, #a29bfe);
    --gradient-blue: linear-gradient(45deg, #2980b9, #3498db);
    --gradient-orange: linear-gradient(45deg, #e67e22, #d35400);
    --gradient-green: linear-gradient(45deg, #27ae60, #2ecc71);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 15px rgba(0,0,0,0.3);
    --shadow-hover: 0 6px 20px rgba(0,0,0,0.4);
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

a { color: var(--accent-teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Header ─── */
.header {
    background: var(--gradient-header);
    border-bottom: 2px solid;
    border-image: linear-gradient(90deg, var(--accent-silver), var(--accent-silver-light), var(--accent-silver)) 1;
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header h1 {
    font-size: 1.5rem;
    background: var(--gradient-silver);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.header .subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.header-left { display: flex; align-items: center; gap: 20px; }
.header-right { display: flex; align-items: center; gap: 15px; }
.header a.back-link {
    color: var(--accent-teal);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 6px 14px;
    border: 1px solid var(--accent-teal);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}
.header a.back-link:hover {
    background: var(--accent-teal);
    color: #121212;
    text-decoration: none;
}

/* ─── Main Content ─── */
.main-container, .content, .page-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 25px 30px;
}

/* ─── Page Title ─── */
.page-title {
    font-size: 2rem;
    background: var(--gradient-silver);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}
.page-subtitle {
    font-size: 1.05rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* ─── Cards ─── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 20px;
    transition: all 0.2s;
}
.card:hover { border-color: var(--border-light); }
.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-silver);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

/* ─── Stats Bar ─── */
.stats-bar {
    display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    flex: 1;
    min-width: 140px;
}
.stat-card label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stat-card .value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent-teal);
    margin-top: 4px;
}

/* ─── Tables ─── */
.table-container {
    overflow-x: auto;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
thead { background: var(--bg-input); }
th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}
td {
    padding: 10px 14px;
    border-bottom: 1px solid #2a2a2a;
    vertical-align: middle;
    color: var(--text-secondary);
}
tr:hover { background: var(--bg-card-hover); }
tr:last-child td { border-bottom: none; }

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}
.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}
.btn:active { transform: translateY(0); }
.btn-sm { padding: 6px 14px; font-size: 0.78rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }

.btn-primary {
    background: var(--gradient-teal);
    color: #fff;
    box-shadow: 0 4px 15px rgba(78, 205, 196, 0.3);
}
.btn-primary:hover {
    background: linear-gradient(45deg, #44a08d, #4ecdc4);
    box-shadow: 0 6px 20px rgba(78, 205, 196, 0.4);
}

.btn-danger {
    background: var(--gradient-red);
    color: #fff;
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}
.btn-danger:hover {
    background: linear-gradient(45deg, #c0392b, #e74c3c);
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.btn-success {
    background: var(--gradient-green);
    color: #fff;
}
.btn-success:hover {
    background: linear-gradient(45deg, #2ecc71, #27ae60);
}

.btn-warning {
    background: var(--gradient-orange);
    color: #fff;
}

.btn-info {
    background: var(--gradient-blue);
    color: #fff;
}

.btn-purple {
    background: var(--gradient-purple);
    color: #fff;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.3);
}
.btn-purple:hover {
    background: linear-gradient(45deg, #a29bfe, #6c5ce7);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.4);
}

.btn-ghost {
    background: transparent;
    color: var(--accent-silver);
    border: 1px solid var(--border-color);
}
.btn-ghost:hover {
    border-color: var(--accent-silver);
    background: rgba(255,255,255,0.05);
}

.btn-silver {
    background: var(--gradient-silver);
    color: #000;
    box-shadow: 0 4px 15px rgba(192, 192, 192, 0.3);
}

/* ─── Form Elements ─── */
input, textarea, select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: var(--font-family);
    transition: border-color 0.2s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent-teal);
    box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.15);
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ─── Modals ─── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-modal-overlay);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
}
.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 {
    color: var(--accent-teal);
    font-size: 1.15rem;
}
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}
.modal-close:hover { color: var(--accent-red); }
.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ─── Status Badges ─── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 3px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.badge-active { background: rgba(46, 204, 113, 0.2); color: var(--accent-green); }
.badge-inactive { background: rgba(231, 76, 60, 0.2); color: var(--accent-red); }
.badge-warning { background: rgba(243, 156, 18, 0.2); color: var(--accent-orange); }
.badge-info { background: rgba(52, 152, 219, 0.2); color: var(--accent-blue); }
.badge-purple { background: rgba(108, 92, 231, 0.2); color: var(--accent-purple); }
.badge-silver { background: rgba(192, 192, 192, 0.2); color: var(--accent-silver); }

.admin-badge {
    background: #2d5a27;
    color: var(--accent-teal);
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.company-badge {
    background: var(--bg-input);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

/* ─── Toolbar / Filters ─── */
.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    align-items: center;
}
.toolbar input, .toolbar select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}
.toolbar input:focus, .toolbar select:focus {
    border-color: var(--accent-teal);
    outline: none;
}

/* ─── Tabs ─── */
.tab-bar {
    display: flex;
    background: var(--bg-card);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border: 1px solid var(--border-color);
    border-bottom: none;
    overflow: hidden;
}
.tab {
    padding: 12px 24px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.tab:hover { color: var(--text-secondary); background: rgba(255,255,255,0.03); }
.tab.active { color: var(--accent-teal); border-bottom-color: var(--accent-teal); }

/* ─── Toast / Alert ─── */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.9rem;
    z-index: 9999;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--accent-green); }
.toast-error { background: var(--accent-red); }
.toast-warning { background: var(--accent-orange); }
.toast-info { background: var(--accent-blue); }

/* ─── Section Title ─── */
.section-title {
    font-size: 1rem;
    color: var(--accent-teal);
    margin: 24px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}
.section-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ─── Empty State ─── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h3 { font-size: 1.2rem; color: var(--text-muted); margin-bottom: 8px; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .header-content { flex-direction: column; gap: 10px; align-items: flex-start; }
    .form-row { grid-template-columns: 1fr; }
    .stats-bar { flex-direction: column; }
    .content, .page-content { padding: 15px; }
    .toolbar { flex-direction: column; }
}
/* ═══════════════════════════════════════════════════════════════════════════
   LIGHT MODE
   ═══════════════════════════════════════════════════════════════════════════ */

.light-mode {
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f3f5;
    --bg-header: #ffffff;
    --bg-input: #ffffff;
    --bg-modal-overlay: rgba(0,0,0,0.5);
    --border-color: #dee2e6;
    --border-light: #ced4da;
    --text-primary: #1a1d21;
    --text-secondary: #343a40;
    --text-muted: #5a6268;
    --text-dim: #6b7280;
    --accent-teal: #2aa198;
    --accent-silver: #6c757d;
    --accent-silver-light: #495057;
    --shadow: 0 4px 15px rgba(0,0,0,0.1);
    --shadow-hover: 0 6px 20px rgba(0,0,0,0.15);
    --gradient-header: linear-gradient(145deg, #ffffff, #f8f9fa);
}

/* Light mode specific adjustments */
.light-mode body {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.light-mode .header {
    background: var(--gradient-header);
    border-bottom: 1px solid var(--border-color);
}

.light-mode .card,
.light-mode .modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.light-mode input,
.light-mode select,
.light-mode textarea {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

/* ═══════════════════════════════════════════════════════════════════════════
   THEME TOGGLE BUTTON (Top Right)
   ═══════════════════════════════════════════════════════════════════════════ */

.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
}

.theme-toggle:hover {
    transform: scale(1.1);
    border-color: var(--accent-teal);
}

.theme-toggle:active {
    transform: scale(0.95);
}

/* Icon states */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }

.light-mode .theme-toggle .icon-sun { display: block; }
.light-mode .theme-toggle .icon-moon { display: none; }

/* Theme Toggle Script */
(function() {
    function initThemeToggle() {
        // Create button if it doesn't exist
        if (document.getElementById('theme-toggle-btn')) return;

        const btn = document.createElement('button');
        btn.id = 'theme-toggle-btn';
        btn.className = 'theme-toggle';
        btn.setAttribute('aria-label', 'Toggle light/dark mode');
        btn.innerHTML = `
            <span class="icon-moon">🌙</span>
            <span class="icon-sun">☀️</span>
        `;

        document.body.appendChild(btn);

        // Load saved theme
        const savedTheme = localStorage.getItem('hvacprobe-theme');
        if (savedTheme === 'light') {
            document.body.classList.add('light-mode');
        } else if (savedTheme === 'dark') {
            document.body.classList.remove('light-mode');
        } else {
            // Respect system preference
            if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
                document.body.classList.add('light-mode');
            }
        }

        // Toggle handler
        btn.addEventListener('click', () => {
            document.body.classList.toggle('light-mode');
            const isLight = document.body.classList.contains('light-mode');
            localStorage.setItem('hvacprobe-theme', isLight ? 'light' : 'dark');
        });
    }

    // Initialize when DOM is ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initThemeToggle);
    } else {
        initThemeToggle();
    }
})();
