/* PAL Tracking System - Custom Styles */

:root {
    --primary-color: #0d6efd;
    --success-color: #198754;
    --info-color: #0dcaf0;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f8f9fa;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container-fluid {
    flex: 1;
}

/* Navigation */
.navbar-brand {
    font-weight: 600;
    font-size: 1.3rem;
}

.nav-link {
    font-weight: 500;
    transition: all 0.3s ease;
}

.nav-link:hover {
    transform: translateY(-2px);
}

/* Statistics Cards */
.stat-card {
    border: none;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    margin-bottom: 1rem;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.8rem;
}

/* Cards */
.card {
    border: none;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    margin-bottom: 1.5rem;
}

.card-header {
    border-bottom: 1px solid rgba(0, 0, 0, 0.125);
    font-weight: 600;
}

.quick-link {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.quick-link:hover {
    transform: translateY(-10px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

/* Tables */
.table {
    font-size: 0.95rem;
}

.table thead th {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.table tbody tr {
    transition: background-color 0.2s ease;
}

.table tbody tr:hover {
    background-color: #f8f9fa;
}

.table code {
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem;
    background-color: #f8f9fa;
    border-radius: 4px;
}

/* Timeline Visualization */
.timeline-container {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    min-height: 60px;
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 10px;
}

.timeline-period {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 50px;
    border-radius: 6px;
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px;
    transition: all 0.3s ease;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.timeline-period:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.timeline-label {
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.timeline-time {
    font-size: 0.75rem;
    opacity: 0.9;
}

/* Badges */
.badge {
    font-weight: 500;
    padding: 0.4em 0.8em;
}

/* Buttons */
.btn {
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Forms */
.form-select,
.form-control {
    border-radius: 6px;
    border: 1px solid #ced4da;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

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

/* Footer */
.footer {
    margin-top: auto;
    background-color: #f8f9fa;
    border-top: 1px solid #dee2e6;
}

/* Loading Spinner */
.spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Alerts */
.alert {
    border-radius: 8px;
    border: none;
}

/* Utility Classes */
.text-success {
    color: var(--success-color) !important;
}

.text-danger {
    color: var(--danger-color) !important;
}

.text-warning {
    color: var(--warning-color) !important;
}

.text-info {
    color: var(--info-color) !important;
}

.bg-primary {
    background-color: var(--primary-color) !important;
}

.bg-success {
    background-color: var(--success-color) !important;
}

.bg-info {
    background-color: var(--info-color) !important;
}

.bg-warning {
    background-color: var(--warning-color) !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .stat-card {
        margin-bottom: 1rem;
    }

    .table {
        font-size: 0.85rem;
    }

    .timeline-period {
        min-height: 40px;
        font-size: 0.75rem;
    }

    .stat-icon {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }
}

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

/* Status Indicators */
.status-online {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success-color);
    margin-right: 5px;
}

.status-offline {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--danger-color);
    margin-right: 5px;
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ===== MAP STYLES ===== */

/* Map Container */
.map-container {
    height: calc(100vh - 200px);
    min-height: 500px;
}

#map {
    width: 100%;
    height: 100%;
    background-color: #e0e0e0;
    border-radius: 8px;
}

/* Custom Beacon Marker */
.custom-beacon-marker {
    background: transparent;
    border: none;
}

.beacon-pin {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: #ff4444;
    border: 3px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.beacon-pin:hover {
    transform: scale(1.3);
    box-shadow: 0 4px 12px rgba(255, 68, 68, 0.5);
}

/* Custom Tracker Marker */
.custom-tracker-marker {
    background: transparent;
    border: none;
}

.tracker-pin {
    width: 20px;
    height: 20px;
    background-color: #28a745;
    border: 3px solid #fff;
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    animation: pulse 2s infinite;
}

.tracker-pin:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.5);
}

@keyframes pulse {
    0% {
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    }
    50% {
        box-shadow: 0 2px 6px rgba(40, 167, 69, 0.8), 0 0 0 10px rgba(40, 167, 69, 0);
    }
    100% {
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    }
}

/* Inactive Tracker Marker (now same as active - solid green) */
.tracker-pin-inactive {
    width: 20px;
    height: 20px;
    background-color: #28a745;
    border: 3px solid #fff;
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    animation: pulse 2s infinite;
}

.tracker-pin-inactive:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.5);
}

/* Stale Tracker Marker (last seen > 12 hours) */
.tracker-pin-stale {
    width: 20px;
    height: 20px;
    background-color: #6c757d;
    border: 3px solid #fff;
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.tracker-pin-stale:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.5);
}

/* Room Label */
.room-label {
    background: transparent;
    border: none;
    text-align: left;
    pointer-events: none;
    z-index: 400;
}

.room-label span {
    background-color: rgba(102, 126, 234, 0.75);
    color: white;
    padding: 3px 8px;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.3);
    pointer-events: auto;
    cursor: default;
    display: inline-block;
}

/* Map Legend */
.map-legend {
    background: white;
    padding: 12px 15px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-size: 0.9rem;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-icon {
    width: 20px;
    height: 20px;
    margin-right: 10px;
    border-radius: 50%;
    display: inline-block;
}

.legend-icon.beacon-icon {
    background-color: #ff4444;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.legend-icon.tracker-icon {
    background-color: #28a745;
    border: 2px solid #fff;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.legend-icon.tracker-inactive-icon {
    background-color: #28a745;
    border: 2px solid #fff;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.legend-icon.room-icon {
    background-color: rgba(102, 126, 234, 0.3);
    border: 2px solid #667eea;
    box-shadow: none;
}

/* SSE Status Indicator */
.sse-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    transition: all 0.3s ease;
}

.sse-status.connected {
    background-color: #28a745;
    box-shadow: 0 0 8px rgba(40, 167, 69, 0.6);
    animation: statusPulse 2s infinite;
}

.sse-status.disconnected {
    background-color: #dc3545;
    box-shadow: 0 0 4px rgba(220, 53, 69, 0.4);
}

@keyframes statusPulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

.sse-status-container {
    user-select: none;
}

/* Leaflet Popup Customization */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-content {
    margin: 12px 15px;
    font-size: 0.9rem;
}

.leaflet-popup-content h6 {
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.leaflet-popup-content hr {
    margin: 8px 0;
    border-top: 1px solid #dee2e6;
}

/* Drawing Tools (Leaflet.draw) */
.leaflet-draw-toolbar a {
    background-color: white;
    border-radius: 4px;
}

.leaflet-draw-actions {
    background-color: white;
    border-radius: 4px;
}

/* Map Controls */
.leaflet-control-zoom a {
    border-radius: 4px;
}

.leaflet-bar {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    border-radius: 6px;
}

/* Responsive Map */
@media (max-width: 768px) {
    #map {
        height: 400px;
    }

    .map-legend {
        font-size: 0.8rem;
        padding: 8px 10px;
    }

    .legend-icon {
        width: 16px;
        height: 16px;
        margin-right: 8px;
    }

    .beacon-pin {
        width: 14px;
        height: 14px;
    }

    .tracker-pin {
        width: 18px;
        height: 18px;
    }

    .room-label span {
        font-size: 0.65rem;
        padding: 2px 5px;
    }
}

/* Dashboard Advanced Charts Styling */
#timeRangeSelector .btn-check:checked + .btn-outline-primary {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
}

#timeRangeSelector .btn-outline-primary {
    border-color: var(--primary-color);
    color: var(--primary-color);
    transition: all 0.3s ease;
}

#timeRangeSelector .btn-outline-primary:hover {
    background-color: rgba(13, 110, 253, 0.1);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

#customRangeSelector {
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
    animation: slideDown 0.3s ease-out;
}

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

/* Chart Cards Enhancement */
.card-header h5 {
    margin-bottom: 0.25rem;
}

.card-header small {
    display: block;
    margin-top: 0.25rem;
    color: #6c757d;
}

/* Equal height cards in rows */
.row .card.h-100 {
    height: 100%;
}

.row .card.h-100 .card-body {
    display: flex;
    flex-direction: column;
}

.row .card.h-100 canvas {
    flex: 1;
    min-height: 300px;
}

/* Dashboard Chart Containers */
.dashboard-chart-container {
    position: relative;
    min-height: 350px;
}

/* Responsive Chart Heights */
@media (max-width: 992px) {
    .row .card.h-100 canvas {
        min-height: 250px;
    }

    #timeRangeSelector {
        flex-direction: column;
        gap: 0.5rem;
    }

    #timeRangeSelector .btn {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .row .card.h-100 canvas {
        min-height: 200px;
    }

    .card-header h5 {
        font-size: 1rem;
    }

    .card-header small {
        font-size: 0.75rem;
    }
}

/* Loading Animation for Charts */
.chart-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.chart-loading::after {
    content: "";
    display: block;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Chart Legend Improvements */
.chart-legend {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e9ecef;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

/* Enhanced Stats Cards for Dashboard */
.stat-card h3 {
    font-size: 2rem;
    font-weight: 700;
    color: #212529;
}

.stat-card h6 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Smooth transitions for all interactive elements */
.btn, .card, .form-control, .form-select {
    transition: all 0.3s ease;
}

/* Custom scrollbar for chart tooltips if needed */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}
