/* ============================================
   IoT Dashboard Custom Theme
   Berdasarkan Desain Figma IoT
   ============================================ */

:root {
    /* IoT Color Palette - Sesuaikan dengan Figma */
    --iot-primary: #2563eb;
    --iot-primary-dark: #1e40af;
    --iot-secondary: #10b981;
    --iot-warning: #f59e0b;
    --iot-danger: #ef4444;
    --iot-info: #06b6d4;
    
    /* Background Colors */
    --iot-bg-primary: #ffffff;
    --iot-bg-secondary: #f8fafc;
    --iot-bg-dark: #1e293b;
    --iot-bg-card: #ffffff;
    
    /* Text Colors */
    --iot-text-primary: #0f172a;
    --iot-text-secondary: #64748b;
    --iot-text-muted: #94a3b8;
    
    /* Border & Shadow */
    --iot-border: #e2e8f0;
    --iot-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --iot-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --iot-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    /* Spacing */
    --iot-spacing-xs: 0.25rem;
    --iot-spacing-sm: 0.5rem;
    --iot-spacing-md: 1rem;
    --iot-spacing-lg: 1.5rem;
    --iot-spacing-xl: 2rem;
    
    /* Border Radius */
    --iot-radius-sm: 0.375rem;
    --iot-radius-md: 0.5rem;
    --iot-radius-lg: 0.75rem;
    --iot-radius-xl: 1rem;
}

/* ============================================
   IoT Card Components
   ============================================ */

.iot-card {
    background: var(--iot-bg-card);
    border: 1px solid var(--iot-border);
    border-radius: var(--iot-radius-lg);
    padding: var(--iot-spacing-lg);
    box-shadow: var(--iot-shadow-sm);
    transition: all 0.3s ease;
}

.iot-card:hover {
    box-shadow: var(--iot-shadow-md);
    transform: translateY(-2px);
}

.iot-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--iot-spacing-md);
    padding-bottom: var(--iot-spacing-md);
    border-bottom: 1px solid var(--iot-border);
}

.iot-card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--iot-text-primary);
    margin: 0;
}

.iot-card-body {
    color: var(--iot-text-secondary);
}

/* ============================================
   IoT Status Indicators
   ============================================ */

.iot-status {
    display: inline-flex;
    align-items: center;
    gap: var(--iot-spacing-sm);
    padding: var(--iot-spacing-xs) var(--iot-spacing-md);
    border-radius: var(--iot-radius-md);
    font-size: 0.875rem;
    font-weight: 500;
}

.iot-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.iot-status-online {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--iot-secondary);
}

.iot-status-online .iot-status-dot {
    background-color: var(--iot-secondary);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

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

.iot-status-offline .iot-status-dot {
    background-color: var(--iot-danger);
}

.iot-status-warning {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--iot-warning);
}

.iot-status-warning .iot-status-dot {
    background-color: var(--iot-warning);
}

/* ============================================
   IoT Metric Cards
   ============================================ */

.iot-metric {
    text-align: center;
}

.iot-metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--iot-text-primary);
    margin: var(--iot-spacing-sm) 0;
}

.iot-metric-label {
    font-size: 0.875rem;
    color: var(--iot-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.iot-metric-change {
    font-size: 0.75rem;
    margin-top: var(--iot-spacing-xs);
}

.iot-metric-change.positive {
    color: var(--iot-secondary);
}

.iot-metric-change.negative {
    color: var(--iot-danger);
}

/* ============================================
   IoT Sensor Display
   ============================================ */

.iot-sensor {
    display: flex;
    align-items: center;
    gap: var(--iot-spacing-md);
    padding: var(--iot-spacing-md);
    background: var(--iot-bg-secondary);
    border-radius: var(--iot-radius-md);
    margin-bottom: var(--iot-spacing-sm);
}

.iot-sensor-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--iot-radius-md);
    background: var(--iot-primary);
    color: white;
    font-size: 1.5rem;
}

.iot-sensor-info {
    flex: 1;
}

.iot-sensor-name {
    font-weight: 600;
    color: var(--iot-text-primary);
    margin-bottom: var(--iot-spacing-xs);
}

.iot-sensor-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--iot-primary);
}

.iot-sensor-unit {
    font-size: 0.875rem;
    color: var(--iot-text-secondary);
    margin-left: var(--iot-spacing-xs);
}

/* ============================================
   IoT Chart Container
   ============================================ */

.iot-chart-container {
    position: relative;
    height: 300px;
    padding: var(--iot-spacing-md);
    background: var(--iot-bg-card);
    border-radius: var(--iot-radius-lg);
}

.iot-chart-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--iot-text-secondary);
    margin-bottom: var(--iot-spacing-md);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ============================================
   IoT Device List
   ============================================ */

.iot-device-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--iot-spacing-md);
    border: 1px solid var(--iot-border);
    border-radius: var(--iot-radius-md);
    margin-bottom: var(--iot-spacing-sm);
    transition: all 0.2s ease;
}

.iot-device-item:hover {
    background: var(--iot-bg-secondary);
    border-color: var(--iot-primary);
}

.iot-device-info {
    display: flex;
    align-items: center;
    gap: var(--iot-spacing-md);
}

.iot-device-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--iot-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--iot-bg-secondary);
    color: var(--iot-primary);
}

.iot-device-details h6 {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--iot-text-primary);
}

.iot-device-details p {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--iot-text-secondary);
}

/* ============================================
   IoT Grid Layout
   ============================================ */

.iot-grid {
    display: grid;
    gap: var(--iot-spacing-lg);
}

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

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

.iot-grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1200px) {
    .iot-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .iot-grid-2,
    .iot-grid-3,
    .iot-grid-4 {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   IoT Dashboard V2
   ============================================ */

.iot-dashboard-v2 .hero-panel {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 45%, #0f766e 100%);
    border-radius: 18px;
    padding: 1.25rem;
    color: #e2e8f0;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22);
}

.iot-dashboard-v2 .hero-chip {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .35rem .7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, .16);
    font-size: .78rem;
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, .20);
}

.iot-dashboard-v2 .health-gauge {
    width: 136px;
    height: 136px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    position: relative;
    margin: 0 auto;
}

.iot-dashboard-v2 .health-gauge::after {
    content: "";
    position: absolute;
    inset: 12px;
    background: #f8fafc;
    border-radius: 50%;
}

.iot-dashboard-v2 .health-gauge-inner {
    position: relative;
    z-index: 1;
    text-align: center;
}

.iot-dashboard-v2 .health-gauge-score {
    font-size: 1.8rem;
    line-height: 1;
    font-weight: 800;
    color: #0f172a;
}

.iot-dashboard-v2 .health-gauge-label {
    font-size: .73rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #64748b;
}

.iot-dashboard-v2 .kpi-card {
    border-radius: 14px;
    border: 1px solid var(--iot-border);
    padding: 1rem;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    height: 100%;
}

.iot-dashboard-v2 .kpi-label {
    color: #64748b;
    font-size: .79rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: .25rem;
}

.iot-dashboard-v2 .kpi-value {
    color: #0f172a;
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1.15;
}

.iot-dashboard-v2 .severity-pulse {
    border-radius: 14px;
    background: #0f172a;
    color: #e2e8f0;
    padding: 1rem;
    overflow: hidden;
}

.iot-dashboard-v2 .severity-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .35rem 0;
    border-bottom: 1px dashed rgba(226, 232, 240, .22);
    font-size: .88rem;
}

.iot-dashboard-v2 .severity-item:last-child {
    border-bottom: 0;
}

.iot-dashboard-v2 .severity-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    margin-right: .35rem;
}

.iot-dashboard-v2 .status-count {
    font-weight: 700;
    font-size: 1.05rem;
}

.iot-dashboard-v2 .timeline-item {
    padding: .7rem 0;
    border-bottom: 1px dashed var(--iot-border);
}

.iot-dashboard-v2 .timeline-item:last-child {
    border-bottom: 0;
}

.iot-dashboard-v2 .timeline-head {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    align-items: center;
    margin-bottom: .35rem;
}

.iot-dashboard-v2 .priority-table tbody tr:hover {
    background: #f8fafc;
}

.iot-dashboard-v2 .action-links a {
    text-decoration: none;
    font-size: .78rem;
    font-weight: 600;
    margin-right: .6rem;
}

.iot-dashboard-v2 .severity-chart-wrap {
    position: relative;
    height: 180px;
}

.iot-dashboard-v2 .severity-chart-wrap canvas {
    max-height: 180px !important;
}

.iot-dashboard-v2 .dashboard-card-compact {
    padding: 1rem;
}

.iot-dashboard-v2 .dashboard-card-compact .iot-card-header {
    margin-bottom: .65rem;
    padding-bottom: .65rem;
}

.iot-dashboard-v2 .dashboard-card-compact .iot-card-body {
    font-size: .94rem;
}

.iot-dashboard-v2 .dashboard-scroll {
    overflow-y: auto;
    overscroll-behavior: contain;
}

.iot-dashboard-v2 .dashboard-scroll-priority {
    max-height: 360px;
}

.iot-dashboard-v2 .dashboard-scroll-timeline {
    max-height: 360px;
}

@media (max-width: 991.98px) {
    .iot-dashboard-v2 .hero-panel {
        padding: 1rem;
    }

    .iot-dashboard-v2 .health-gauge {
        width: 120px;
        height: 120px;
    }
}

/* ============================================
   Global Theme Bridge (Light/Dark)
   Works across IoT + Settings pages
   ============================================ */

:root,
[data-bs-theme="light"] {
    --iot-page-bg: #f4f7fb;
    --iot-surface: #ffffff;
    --iot-surface-soft: #f8fafc;
    --iot-surface-muted: #f1f5f9;
    --iot-border-strong: #dbe3ee;
    --iot-text-main: #0f172a;
    --iot-text-soft: #475569;
}

[data-bs-theme="dark"] {
    --iot-bg-primary: #0f172a;
    --iot-bg-secondary: #1e293b;
    --iot-bg-card: #111827;
    --iot-text-primary: #e2e8f0;
    --iot-text-secondary: #cbd5e1;
    --iot-text-muted: #94a3b8;
    --iot-border: #334155;
    --iot-page-bg: #0b1220;
    --iot-surface: #111827;
    --iot-surface-soft: #1f2937;
    --iot-surface-muted: #334155;
    --iot-border-strong: #334155;
    --iot-text-main: #e2e8f0;
    --iot-text-soft: #cbd5e1;
    --iot-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.35);
    --iot-shadow-md: 0 6px 12px -2px rgba(0, 0, 0, 0.45);
    --iot-shadow-lg: 0 14px 24px -6px rgba(0, 0, 0, 0.55);
}

.app-wrapper {
    background: var(--iot-page-bg);
}

.iot-card {
    background: var(--iot-bg-card);
    border-color: var(--iot-border);
    color: var(--iot-text-secondary);
}

.iot-card .table,
.iot-card .table > :not(caption) > * > * {
    color: var(--iot-text-secondary);
    border-color: var(--iot-border);
}

.iot-card .table thead th {
    color: var(--iot-text-primary);
    background: var(--iot-surface-soft);
}

[data-bs-theme="dark"] .iot-card .table-light,
[data-bs-theme="dark"] .iot-card .table-light > th,
[data-bs-theme="dark"] .iot-card .table-light > td {
    --bs-table-bg: #1f2937;
    --bs-table-color: #e2e8f0;
    --bs-table-border-color: #334155;
}

[data-bs-theme="dark"] .iot-card .device-row:hover {
    background: rgba(148, 163, 184, 0.12);
}

[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .dropdown-menu,
[data-bs-theme="dark"] .source-panel,
[data-bs-theme="dark"] .notification-container {
    background: var(--iot-surface);
    color: var(--iot-text-main);
    border-color: var(--iot-border-strong);
}

[data-bs-theme="dark"] .card-header,
[data-bs-theme="dark"] .modal-header,
[data-bs-theme="dark"] .modal-footer,
[data-bs-theme="dark"] .iot-card-header {
    border-color: var(--iot-border);
}

[data-bs-theme="dark"] .card.bg-light,
[data-bs-theme="dark"] .bg-light {
    background: var(--iot-surface-soft) !important;
    color: var(--iot-text-main);
}

[data-bs-theme="dark"] .table-primary,
[data-bs-theme="dark"] .table-primary > th,
[data-bs-theme="dark"] .table-primary > td {
    --bs-table-bg: #1e3a8a;
    --bs-table-color: #e5edff;
    --bs-table-border-color: #3757b8;
}

[data-bs-theme="dark"] .text-muted,
[data-bs-theme="dark"] .text-body-secondary {
    color: #9fb0c5 !important;
}

/* WA page dark compatibility */
[data-bs-theme="dark"] .wa-container-wrapper .source-item,
[data-bs-theme="dark"] .wa-container-wrapper .recipients-slot,
[data-bs-theme="dark"] .wa-container-wrapper .source-panel {
    background: #0f172a;
    border-color: #334155;
}

[data-bs-theme="dark"] .wa-container-wrapper .canvas-area {
    background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
}

[data-bs-theme="dark"] .wa-container-wrapper .source-item:hover,
[data-bs-theme="dark"] .wa-container-wrapper .recipients-slot.drag-over {
    background: #1d4ed8;
    border-color: #3b82f6;
    color: #eff6ff;
}

/* Security modal/table compatibility */
[data-bs-theme="dark"] .photo-item {
    background: #111827;
    border-color: #334155;
}

[data-bs-theme="dark"] .photo-item-info {
    background: #0f172a;
    color: #e2e8f0;
}

[data-bs-theme="dark"] #deviceDetailModal .modal-header,
[data-bs-theme="dark"] #deviceDetailModal .modal-footer {
    border-color: #334155 !important;
}

/* Strong overrides for IoT pages shown in screenshots */
html[data-bs-theme="dark"] .iot-card {
    background: #111827 !important;
    color: #e5e7eb !important;
    border-color: #334155 !important;
}

html[data-bs-theme="dark"] .iot-card .iot-card-header,
html[data-bs-theme="dark"] .iot-card .iot-card-body {
    background: #111827 !important;
    color: #e5e7eb !important;
    border-color: #334155 !important;
}

html[data-bs-theme="dark"] .iot-card .iot-card-title,
html[data-bs-theme="dark"] .iot-card h1,
html[data-bs-theme="dark"] .iot-card h2,
html[data-bs-theme="dark"] .iot-card h3,
html[data-bs-theme="dark"] .iot-card h4,
html[data-bs-theme="dark"] .iot-card h5,
html[data-bs-theme="dark"] .iot-card h6,
html[data-bs-theme="dark"] .iot-card .fw-semibold,
html[data-bs-theme="dark"] .iot-card b,
html[data-bs-theme="dark"] .iot-card strong {
    color: #f8fafc !important;
}

html[data-bs-theme="dark"] .iot-card .table {
    --bs-table-bg: transparent;
    --bs-table-striped-bg: #1f2937;
    --bs-table-hover-bg: #243041;
    --bs-table-border-color: #334155;
    --bs-table-color: #dbe4ee;
    background: transparent !important;
}

html[data-bs-theme="dark"] .iot-card .table > :not(caption) > * > * {
    background: transparent !important;
    color: #dbe4ee !important;
    border-color: #334155 !important;
}

html[data-bs-theme="dark"] .iot-card .table thead th,
html[data-bs-theme="dark"] .iot-card .table thead td,
html[data-bs-theme="dark"] .iot-card .table-light,
html[data-bs-theme="dark"] .iot-card .table-light > tr > th,
html[data-bs-theme="dark"] .iot-card .table-light > tr > td,
html[data-bs-theme="dark"] .iot-card .table-light > * > tr > th,
html[data-bs-theme="dark"] .iot-card .table-light > * > tr > td {
    background: #1f2937 !important;
    color: #f1f5f9 !important;
    border-color: #334155 !important;
}

html[data-bs-theme="dark"] .iot-card .text-muted,
html[data-bs-theme="dark"] .iot-card .text-body-secondary,
html[data-bs-theme="dark"] .iot-card small,
html[data-bs-theme="dark"] .iot-card .small {
    color: #a9b8ca !important;
}

html[data-bs-theme="dark"] #deviceDetailModal .modal-content,
html[data-bs-theme="dark"] #deviceDetailModal .nav-tabs,
html[data-bs-theme="dark"] #deviceDetailModal .nav-tabs .nav-link {
    background: #0f172a !important;
    color: #dbe4ee !important;
    border-color: #334155 !important;
}

html[data-bs-theme="dark"] #deviceDetailModal .nav-tabs .nav-link.active {
    background: #1f2937 !important;
    color: #f8fafc !important;
}

/* ============================================
   IoT Real-time Badge
   ============================================ */

.iot-realtime-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--iot-spacing-xs);
    padding: var(--iot-spacing-xs) var(--iot-spacing-sm);
    background: rgba(239, 68, 68, 0.1);
    color: var(--iot-danger);
    border-radius: var(--iot-radius-md);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.iot-realtime-badge::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--iot-danger);
    animation: pulse 2s infinite;
}

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

/* ============================================
   IoT Dark Mode Support
   ============================================ */

[data-theme="dark"] {
    --iot-bg-primary: #0f172a;
    --iot-bg-secondary: #1e293b;
    --iot-bg-card: #1e293b;
    --iot-text-primary: #f1f5f9;
    --iot-text-secondary: #cbd5e1;
    --iot-text-muted: #94a3b8;
    --iot-border: #334155;
}

/* ============================================
   IoT Responsive Utilities
   ============================================ */

@media (max-width: 768px) {
    .iot-card {
        padding: var(--iot-spacing-md);
    }
    
    .iot-metric-value {
        font-size: 1.5rem;
    }
    
    .iot-chart-container {
        height: 250px;
    }
}
