:root {
    /* Modern Theme - Light & Vibrant (Default) */
    --sidebar-bg: #1f2937; /* Dark slate specifically for the sidebar */
    --sidebar-hover: rgba(9, 154, 162, 0.25);
    --main-bg: #ffffff; /* White background for the platform */
    --secondary-bg: #f9fafb; /* Light grey for cards */
    --text-main: #111827; /* Dark text for readability */
    --text-muted: #6b7280; 
    --text-white: #ffffff; /* For sidebar and buttons */
    --accent: #099AA2; /* Teal Main Letters */
    --accent-hover: #2D9C9C; /* Teal Variation / Shading */
    --border-light: rgba(0, 0, 0, 0.08); 
    --border-dark: rgba(255, 255, 255, 0.1);
    --danger: #ef4444;
    --success: #8AB468; /* Greenish Blend */
    --warning: #E9CB3D; /* Yellow Arrow/Glow */
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --radius-md: 8px;
    --radius-lg: 12px;
}

[data-theme="modern"] .btn-primary {
    transition: all 0.3s ease;
}

[data-theme="modern"] .btn-primary:hover {
    box-shadow: 0 4px 15px rgba(233, 203, 61, 0.5); /* Yellow glow on hover */
}

[data-theme="legacy"] {
    /* Color Palette - Legacy (ChatGPT inspired) fallback */
    --sidebar-bg: #202123;
    --sidebar-hover: rgba(255, 255, 255, 0.1);
    --main-bg: #ffffff;
    --secondary-bg: #f7f7f8;
    --text-main: #353740;
    --text-muted: #6e6e80;
    --text-white: #ececf1;
    --accent: #10a37f;
    --accent-hover: #1a7f64;
    --border-light: rgba(0, 0, 0, 0.1);
    --border-dark: rgba(255, 255, 255, 0.1);
    --danger: #ef4444;
    --success: #10a37f;
    --warning: #f59e0b;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Inter', 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--main-bg);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

[dir="rtl"] {
    font-family: 'IBM Plex Sans Arabic', 'Inter', sans-serif;
    text-align: right;
}

[dir="rtl"] .sidebar {
    order: 2;
}

[dir="rtl"] .main-content {
    order: 1;
}

[dir="rtl"] .input-group {
    text-align: right;
}

[dir="rtl"] .btn-primary {
    text-align: center;
}

[dir="rtl"] .top-bar-spacer {
    order: -1;
}

[dir="rtl"] th {
    text-align: right;
}


.screen {
    display: none;
    height: 100vh;
    width: 100%;
}

.screen.view-active {
    display: flex;
}

/* Login Screen - Sleek & Focused */
#login-screen {
    align-items: center;
    justify-content: center;
    background-color: var(--main-bg);
}

.login-box {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    text-align: center;
}

.logo-large {
    width: 48px;
    height: 48px;
    background: var(--accent);
    border-radius: 50%;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    font-weight: 700;
}

.login-box h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 2rem;
}

.input-group {
    text-align: left;
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.input-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus {
    border-color: var(--accent);
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-size: 1rem;
}

.btn-primary {
    background-color: var(--accent);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

/* App Layout */
.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
}

/* Sidebar - Dark Mode ChatGPT Style */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--text-white);
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
    transition: transform 0.3s ease-in-out;
}

.new-task-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    cursor: pointer;
    transition: background 0.2s;
    font-weight: 500;
}

.new-task-btn:hover {
    background-color: var(--sidebar-hover);
}

.nav-section {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    color: var(--text-white);
    text-decoration: none;
    font-size: 0.875rem;
    transition: background 0.2s;
}

.nav-item:hover {
    background-color: var(--sidebar-hover);
}

.nav-item.active {
    background-color: var(--sidebar-hover);
}

.user-section {
    border-top: 1px solid var(--border-dark);
    padding: 0.75rem;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: background 0.2s;
}

.user-section:hover {
    background-color: var(--sidebar-hover);
}

.avatar {
    width: 32px;
    height: 32px;
    background-color: #5436da; /* ChatGPT purple avatar */
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--main-bg);
    position: relative;
}

.top-bar {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    position: sticky;
    top: 0;
    background: var(--main-bg);
    z-index: 100;
}

.menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 0.5rem;
    align-items: center;
    justify-content: center;
}

.top-bar-spacer {
    width: 40px;
    display: none;
}

.content-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.container-narrow {
    width: 100%;
    max-width: 800px;
}

/* Components */
.card {
    background: var(--secondary-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-light);
}

.card h3 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.stat-box {
    text-align: center;
    padding: 1rem;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Quick Action Bar */
.action-bar-container {
    padding: 1rem 1rem 2rem;
    display: flex;
    justify-content: center;
    width: 100%;
}

.action-bar {
    width: 100%;
    max-width: 800px;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: 0 0 15px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
}

.action-bar input {
    flex: 1;
    border: none;
    outline: none;
    padding: 0.75rem;
    font-size: 1rem;
}

.action-bar .send-btn {
    background: var(--accent);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s;
}

.action-bar .send-btn:hover {
    opacity: 0.8;
}

/* Utility */
.pill {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(0,0,0,0.05);
}

.status-online { color: var(--success); }
.status-offline { color: var(--danger); }

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

th {
    text-align: left;
    padding: 0.75rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

td {
    padding: 0.75rem;
    border-top: 1px solid var(--border-light);
    font-size: 0.875rem;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 900;
    display: none;
    opacity: 0;
    transition: opacity 0.3s;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 768px) {
    .menu-btn { display: flex; }
    .top-bar-spacer { display: block; }
    
    .sidebar { 
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transform: translateX(-100%);
        box-shadow: 10px 0 20px rgba(0,0,0,0.2);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }

    .grid-2 { grid-template-columns: 1fr; }
    .device-grid { grid-template-columns: 1fr; }
    
    .content-wrapper {
        padding: 1rem 0.75rem;
    }
    
    .action-bar-container {
        padding: 1rem;
    }
}

/* ===== IoT Device Dashboard ===== */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.device-card {
    background: var(--main-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    transition: box-shadow 0.2s, border-color 0.2s;
    position: relative;
}

.device-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
}

.device-card.offline {
    opacity: 0.55;
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.device-name {
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.3;
}

.device-category {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-top: 2px;
}

.device-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
}

.device-status-dot.online {
    background: var(--success);
    box-shadow: 0 0 6px rgba(16, 163, 127, 0.5);
    animation: pulse-green 2s infinite;
}

.device-status-dot.offline {
    background: #999;
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 6px rgba(16, 163, 127, 0.4); }
    50% { box-shadow: 0 0 12px rgba(16, 163, 127, 0.8); }
}

.device-data {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.data-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--secondary-bg);
    border: 1px solid var(--border-light);
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.data-chip .data-label {
    color: var(--text-muted);
}

.data-chip .data-value {
    color: var(--text-main);
    font-weight: 600;
}

.data-chip.presence-active {
    background: rgba(16, 163, 127, 0.1);
    border-color: rgba(16, 163, 127, 0.3);
    color: var(--success);
}

.data-chip.presence-active .data-value {
    color: var(--success);
}

/* Toggle Switch */
.toggle-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-light);
}

.toggle-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

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

.toggle-slider {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc;
    border-radius: 24px;
    transition: background 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* AC Control Panel */
.ac-panel {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-light);
}

.ac-panel .ac-temp-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 0.75rem 0;
}

.ac-temp-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border-light);
    background: var(--secondary-bg);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-main);
}

.ac-temp-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.ac-temp-display {
    font-size: 1.75rem;
    font-weight: 700;
    min-width: 60px;
    text-align: center;
}

.ac-controls-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.ac-mode-btn {
    flex: 1;
    min-width: 65px;
    padding: 5px 8px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--secondary-bg);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    color: var(--text-main);
    text-transform: capitalize;
}

.ac-mode-btn:hover, .ac-mode-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Energy Monitor */
.energy-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.energy-stat {
    text-align: center;
    padding: 0.5rem;
    background: var(--secondary-bg);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}

.energy-stat .e-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
}

.energy-stat .e-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.03em;
}

.energy-stat .e-unit {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
}

/* Summary stats bar */
.iot-summary {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.iot-summary-item {
    background: var(--main-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 0.75rem 1.25rem;
    flex: 1;
    min-width: 120px;
    text-align: center;
}

.iot-summary-item .s-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.iot-summary-item .s-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}

/* Refresh button */
.refresh-btn {
    background: none;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.refresh-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.refresh-btn.spinning .refresh-icon {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Loading shimmer */
.loading-shimmer {
    background: linear-gradient(90deg, var(--secondary-bg) 25%, #e8e8e8 50%, var(--secondary-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
    height: 200px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.error-text {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

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

.modal-overlay.active {
    display: flex;
}

.video-modal-content {
    background: var(--bg-card);
    width: 90%;
    max-width: 800px;
    border-radius: 20px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-light);
}

.modal-header {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
}

.btn-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.btn-close:hover {
    color: var(--text);
}

.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
}

#live-video-player {
    width: 100%;
    height: 100%;
}

.video-loader {
    position: absolute;
    color: #fff;
    font-size: 0.9rem;
    background: rgba(0,0,0,0.5);
    padding: 10px 20px;
    border-radius: 20px;
}

/* New Data Chip Styles */
.presence-active {
    background: rgba(16, 185, 129, 0.1) !important;
    color: var(--success) !important;
}


/* ===== Notification Bar & Center ===== */
.notif-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.notif-item:hover {
    background: rgba(16, 163, 127, 0.05);
}

.notif-item.unread {
    background: rgba(16, 163, 127, 0.1);
    border-left: 3px solid var(--accent);
}

.notif-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.notif-title {
    font-weight: 600;
    font-size: 0.85rem;
}

.notif-body {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== Ticket Detail & Cards ===== */
.detail-container {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    cursor: pointer;
}

.detail-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.timeline {
    position: relative;
    padding-left: 1.5rem;
    margin-top: 1rem;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-light);
}

.timeline-item {
    position: relative;
    padding-bottom: 1.5rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.85rem;
    top: 0.25rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid white;
}

.media-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.media-item {
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--secondary-bg);
}

.media-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Mobile Ticket Cards (Technician View) */
.ticket-card {
    background: var(--main-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1rem;
    transition: transform 0.2s;
    cursor: pointer;
}

.ticket-card:hover {
    transform: scale(1.02);
}

.ticket-card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.ticket-card-id {
    font-weight: 700;
    color: var(--text-muted);
}

.ticket-card-body {
    margin-bottom: 1rem;
}

.ticket-card-footer {
    display: flex;
    gap: 0.5rem;
}

@media (max-width: 768px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
}
