/* Global Styles */
:root {
    --primary-color: #198754;
    --secondary-color: #6c757d;
    --success-color: #20c997;
    --info-color: #0dcaf0;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --light-color: #f8f9fa;
    --dark-color: #212529;
}

/* Map Styles */
.leaflet-container {
    height: 100% !important;
    width: 100% !important;
    border-radius: 8px;
}

#dashboardMap {
    height: 400px !important;
    width: 100% !important;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

#addDeviceMap, #editDeviceMap {
    height: 350px !important;
    width: 100% !important;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    position: relative;
    z-index: 1;
}

#addDeviceMap .leaflet-container,
#editDeviceMap .leaflet-container {
    height: 100% !important;
    width: 100% !important;
    border-radius: 8px;
}

/* Modal map specific fixes */
.modal-dialog .leaflet-container {
    height: 100% !important;
    width: 100% !important;
    position: relative !important;
}

.modal-body #addDeviceMap,
.modal-body #editDeviceMap {
    position: relative !important;
    overflow: hidden;
    min-height: 350px !important;
}

/* Ensure map tiles load properly in modal */
.modal.show #addDeviceMap .leaflet-container,
.modal.show #editDeviceMap .leaflet-container {
    height: 350px !important;
    width: 100% !important;
    min-height: 350px !important;
}

/* Additional fixes for modal map */
.modal-xl .modal-body #addDeviceMap,
.modal-xl .modal-body #editDeviceMap {
    height: 350px !important;
    width: 100% !important;
}

.modal-body .card-body #addDeviceMap,
.modal-body .card-body #editDeviceMap {
    height: 350px !important;
    width: 100% !important;
    display: block;
}

.leaflet-popup-content-wrapper {
    border-radius: 8px;
}

.map-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    background-color: #f8f9fa;
    border-radius: 8px;
    color: #6c757d;
}

/* Logo styling for navbar */
.navbar-brand img {
    height: 24px !important;
    width: auto !important;
    margin-right: 8px !important;
    vertical-align: middle !important;
    max-height: 24px !important;
}

.header-logo img {
    height: 40px;
    width: auto;
    vertical-align: middle;
}

body {
    background-color: #f5f5f5;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
}

/* TopNavbar */
.top-navbar {
    position: fixed;
    top: 0;
    left: 0; /* Adjusted to cover the full width */
    right: 0;
    height: 70px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    z-index: 1040;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.navbar-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 100%;
}

.mobile-toggle {
    display: none; /* This will be handled by responsive adjustments */
    background: none;
    border: none;
    color: #495057;
    font-size: 1.2rem;
    padding: 0.5rem;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Main Content */
.main-content {
    margin-top: 70px;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: calc(100vh - 70px);
    padding: 1.5rem;
}

/* Dashboard Controls */
.dashboard-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.dashboard-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.dashboard-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.dashboard-btn:hover {
    transform: translateY(-1px);
}

.dashboard-btn i {
    min-width: 16px;
}

/* Map Container Styling */
#mapContainer {
    display: none; /* Hidden by default, controlled by toggle */
    width: 100%;
    margin-top: 10px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #dee2e6;
    background: #fff;
    transition: all 0.3s ease;
}

#deviceMap {
    height: 400px !important;
    width: 100% !important;
    z-index: 1;
}

/* Ensure map is visible when parent is shown */
.map-visible #mapContainer {
    display: block !important;
}

.min-vh-75 {
    min-height: 75vh;
}

/* Hero Content Styling */
.hero-content {
    animation: fadeInUp 1s ease-out;
}

.hero-stats {
    margin: 2rem 0;
}

.stat-item {
    padding: 1rem;
}

.stat-number {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: 0.9rem;
    margin-top: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Enhanced Feature Cards */
.feature-card.animated {
    animation: slideInUp 0.8s ease-out forwards;
    opacity: 0;
    transform: translateY(30px);
}

.feature-card.animated.delay-1 {
    animation-delay: 0.2s;
}

.feature-card.animated.delay-2 {
    animation-delay: 0.4s;
}

.feature-card.animated.delay-3 {
    animation-delay: 0.6s;
}

.feature-badge {
    position: absolute;
    top: 10px;
    right: 10px;
}

.feature-badge .badge {
    font-size: 0.7rem;
    animation: pulse 2s infinite;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.hero-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.1'%3E%3Ccircle cx='30' cy='30' r='4'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") repeat;
}

.hero-section .container {
    position: relative;
    z-index: 2;
}

/* Feature Cards */
.feature-cards {
    position: relative;
    z-index: 2;
}

.feature-card {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    padding: 1.5rem;
    text-align: center;
    color: white;
    transition: all 0.3s ease;
}

.feature-card:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.2);
}

.feature-card i {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    display: block;
}

.feature-card h5 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.feature-card p {
    font-size: 0.9rem;
    margin: 0;
    opacity: 0.9;
}

/* Sensor Cards */
.sensor-card {
    background: white;
    border-radius: 15px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sensor-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.sensor-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sensor-icon i {
    font-size: 1.5rem;
    color: white;
}

.sensor-content {
    flex: 1;
}

.sensor-title {
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 0.25rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sensor-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #212529;
    margin-bottom: 0.25rem;
}

.sensor-status {
    font-size: 0.875rem;
    color: #6c757d;
    font-weight: 500;
}

/* Status Colors */
.status-kering { color: #dc3545; }
.status-cukup { color: #ffc107; }
.status-basah { color: #198754; }
.status-hujan { color: #0dcaf0; }

/* Serial button styling */
.btn-text {
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-text i {
    font-size: 1rem;
    line-height: 1;
}

.btn-label {
    white-space: nowrap;
}

/* Device info styling */
.device-status-indicator .badge {
    font-size: 0.875rem;
}

/* Multi-port serial styling */
#serial-ports-list {
    max-width: 300px;
}

#serial-ports-list .badge {
    position: relative;
    padding-right: 2rem;
}

#serial-ports-list .btn-close {
    position: absolute;
    right: 0.25rem;
    top: 50%;
    transform: translateY(-50%);
    padding: 0;
    width: 1rem;
    height: 1rem;
    background-size: 0.8rem;
}

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

#device-info-section .card {
    border: 1px solid #dee2e6;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

#device-info-section .fw-bold {
    font-weight: 600;
    color: #495057;
}

/* Device Cards */
.device-card {
    background: white;
    border-radius: 15px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    cursor: pointer;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.device-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
    border-color: var(--primary-color);
}

.device-card-header {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

/* Serial Device Cards */
.serial-device-card {
    border-left: 4px solid #0d6efd;
    background: linear-gradient(135deg, #f8f9ff 0%, #ffffff 100%);
}

.serial-device-card:hover {
    border-left-color: #0a58ca;
}

.serial-device-card .device-card-title {
    color: #0d6efd;
}

.serial-device-card .badge {
    font-size: 0.7rem;
}

.mini-chart-container {
    position: relative;
    height: 140px;
    margin: 1rem 0;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 0.5rem;
    border: 1px solid rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.mini-chart-container canvas {
    border-radius: 6px;
    width: 100% !important;
    height: 100% !important;
    background: white;
}

.device-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.device-card-subtitle {
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 0.5rem;
}

.device-card-sensors {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.mini-sensor {
    text-align: center;
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 8px;
}

.mini-sensor-icon {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.5rem;
}

.mini-sensor-icon i {
    font-size: 1rem;
    color: white;
}

.mini-sensor-value {
    font-size: 1rem;
    font-weight: 600;
    color: #212529;
    margin-bottom: 0.25rem;
}

.mini-sensor-label {
    font-size: 0.75rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Adjusted mini-chart-container for better appearance */
.mini-chart-container {
    height: 120px;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
}

/* Analytics Styles */
.analytics-item {
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.analytics-label {
    font-size: 0.75rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.analytics-value {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0;
}

/* Device Form Styles */
.form-label {
    font-weight: 600;
    color: #495057;
}

.form-control:focus {
    border-color: #28a745;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
}

.form-text {
    font-size: 0.8rem;
    color: #6c757d;
}

/* Code output styles */
#espCodeOutput {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    font-family: 'Courier New', monospace;
    line-height: 1.4;
}

/* Device status indicator */
.device-status-online {
    color: #28a745;
}

.device-status-offline {
    color: #dc3545;
}

.device-status-warning {
    color: #ffc107;
}

.device-card-footer {
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Status Indicator */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.badge {
    font-size: 0.8rem;
    padding: 0.5rem 1rem;
}

.badge i {
    margin-right: 0.25rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Cards */
.card {
    border: none;
    border-radius: 15px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.card-header {
    background: white;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 15px 15px 0 0 !important;
    padding: 1.25rem 1.5rem;
}

.card-body {
    padding: 1.5rem;
}

/* Charts */
canvas {
    max-height: 400px;
}

/* Tables */
.table {
    margin-bottom: 0;
}

.table th {
    border-top: none;
    font-weight: 600;
    font-size: 0.875rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #000000 !important;
    background-color: #f8f9fa !important;
}

.table td {
    vertical-align: middle;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

/* Sortable Table Headers */
.sortable-header {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
    position: relative;
}

.sortable-header:hover {
    background-color: #e9ecef !important;
}

.sort-icon {
    margin-left: 0.5rem;
    opacity: 0.5;
    transition: opacity 0.2s ease;
    font-size: 0.8rem;
}

.sortable-header:hover .sort-icon {
    opacity: 1;
}

.sortable-header.sort-default .sort-icon,
.sortable-header .sort-icon {
    opacity: 0.5;
}

.sortable-header.sort-asc .sort-icon {
    opacity: 1;
}

.sortable-header.sort-desc .sort-icon {
    opacity: 1;
}

/* Alerts */
.alert {
    border: none;
    border-radius: 10px;
    border-left: 4px solid;
}

.alert-warning {
    border-left-color: #ffc107;
    background-color: rgba(255, 193, 7, 0.1);
}

.alert-danger {
    border-left-color: #dc3545;
    background-color: rgba(220, 53, 69, 0.1);
}

.alert-info {
    border-left-color: #0dcaf0;
    background-color: rgba(13, 202, 240, 0.1);
}

/* Buttons */
.btn {
    border-radius: 8px;
    font-weight: 500;
    padding: 0.625rem 1.25rem;
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

/* Form Controls */
.form-control, .form-select {
    border-radius: 8px;
    border: 1px solid #ddd;
    padding: 0.625rem 1rem;
    transition: all 0.3s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(25, 135, 84, 0.25);
}

/* Pagination */
.pagination .page-link {
    border-radius: 8px;
    margin: 0 2px;
    border: none;
    color: var(--primary-color);
}

.pagination .page-item.active .page-link {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Analytics Cards */
.analytics-card {
    border: 1px solid #e9ecef;
    border-radius: 15px;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    height: 100%;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
    transition: all 0.3s ease;
    border-left: 4px solid;
}

.analytics-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.analytics-card.card-primary {
    border-left-color: #0d6efd;
}

.analytics-card.card-success {
    border-left-color: #198754;
}

.analytics-card.card-warning {
    border-left-color: #ffc107;
}

.analytics-card.card-info {
    border-left-color: #0dcaf0;
}

.analytics-header {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 15px;
    color: #495057;
    display: flex;
    align-items: center;
    gap: 8px;
}

.analytics-header i {
    font-size: 18px;
}

.analytics-item {
    margin-bottom: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.analytics-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.analytics-label {
    font-size: 12px;
    color: #6c757d;
    font-weight: 500;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.analytics-value {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
    color: #212529;
}

/* Chart Cards Styling */
.chart-card {
    cursor: pointer;
    transition: all 0.3s ease;
}

.chart-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.chart-card .card-header {
    border-radius: 15px 15px 0 0 !important;
}

body {
    background-color: #f8f9fa !important;
    color: #212529 !important;
}

.card {
    background-color: white !important;
    border-color: #dee2e6 !important;
}

.sensor-card {
    background-color: white !important;
    border-color: #dee2e6 !important;
}

.table {
    color: #212529 !important;
    background-color: white !important;
}

.table th {
    border-color: #dee2e6 !important;
    background-color: #f8f9fa !important;
    color: #000000 !important;
    font-weight: 600 !important;
}

.table td {
    border-color: #dee2e6 !important;
    background-color: white !important;
}

/* Responsive Design */
@media (max-width: 992px) {
    .mobile-toggle {
        display: block;
    }
}

@media (max-width: 768px) {
    .hero-section {
        min-height: 60vh;
        text-align: center;
    }

    .sensor-card {
        flex-direction: column;
        text-align: center;
    }

    .sensor-icon {
        margin-bottom: 1rem;
    }

    .sensor-value {
        font-size: 1.5rem;
    }

    /* Mobile Dashboard Button Styles */
    .dashboard-btn .btn-label {
        display: none;
    }

    .dashboard-btn {
        padding: 0.5rem;
        min-width: 40px;
        justify-content: center;
    }

    .dashboard-btn i {
        margin: 0;
    }

    .dashboard-buttons {
        justify-content: flex-end;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .dashboard-buttons .btn-group {
        display: flex;
        gap: 0.5rem;
    }
}

@media (max-width: 576px) {
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .sensor-card {
        padding: 1rem;
    }

    .table-responsive {
        font-size: 0.875rem;
    }
}