:root {
    --bg-color: #010609;
    --card-bg: rgba(15, 23, 42, 0.7);
    --accent: #00e5ff;
    --accent-glow: rgba(0, 229, 255, 0.4);
    --danger: #ff1744;
    --warning: #ffea00;
    --success: #00e676;
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --border-color: rgba(0, 229, 255, 0.15);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --radius-lg: 24px;
    --radius-md: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Rajdhani', sans-serif;
}

body {
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(circle at 0% 0%, rgba(0, 229, 255, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(68, 138, 255, 0.05) 0%, transparent 40%);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem;
    background-attachment: fixed;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 1.5rem;
}

.logo-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.logo-section h1 {
    font-size: 2rem;
    letter-spacing: 4px;
    font-weight: 700;
}

.logo-section h1 span {
    color: var(--accent);
}

.nav-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.dashboard-label {
    font-weight: 900;
    font-size: 1.1rem;
    letter-spacing: 1px;
    margin-right: 0.5rem;
    text-transform: uppercase;
    color: var(--text-primary);
}

.nav-pill {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 10px 24px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 1rem;
    color: white;
    text-decoration: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.nav-pill:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.nav-pill i {
    font-size: 1rem;
}

.pill-monitor {
    background: linear-gradient(90deg, #11998e 0%, #38ef7d 100%);
}

.pill-company {
    background: linear-gradient(90deg, #0082c8, #00c6ff);
}

.pill-cup {
    background: linear-gradient(90deg, #ff8c00 0%, #ffbb00 100%);
}

.status-badge {
    padding: 6px 16px;
    border-radius: 50px;
    font-size: 0.8rem;
    text-transform: uppercase;
    font-weight: 700;
}

header .status-badge {
    margin-left: 1rem;
}

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 2rem;
}

.device-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.8rem;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.device-card:hover {
    transform: translateY(-8px) scale(1.01);
    border-color: var(--accent);
    box-shadow: 0 20px 40px rgba(0, 229, 255, 0.1);
}

.device-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 6px;
    height: 100%;
    background: linear-gradient(to bottom, var(--accent), #448aff);
    box-shadow: 2px 0 10px var(--accent-glow);
}

.device-card.offline::before {
    background-color: var(--text-secondary);
}

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

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

.device-name {
    font-size: 1.5rem;
    font-weight: 600;
}

.device-id {
    font-size: 0.8rem;
    color: var(--text-secondary);
}


.pill-help { background: rgba(68, 138, 255, 0.1); color: var(--blue); }
.pill-help:hover { background: var(--blue); color: white; }

.pill-notify { background: rgba(255, 152, 0, 0.1); color: #ff9800; border: 1px solid rgba(255, 152, 0, 0.2); }
.pill-notify:hover { background: #ff9800; color: white; }
.pill-notify.active { background: #4caf50; color: white; border-color: #4caf50; box-shadow: 0 0 15px rgba(76, 175, 80, 0.3); }

.pill-install { background: rgba(224, 64, 251, 0.1); color: #e040fb; border: 1px solid rgba(224, 64, 251, 0.2); }
.pill-install:hover { background: #e040fb; color: white; }

.status-online {
    background-color: rgba(0, 230, 118, 0.15);
    color: var(--success);
    border: 1px solid rgba(0, 230, 118, 0.3);
    position: relative;
}

.status-online::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    margin-right: 8px;
    box-shadow: 0 0 10px var(--success);
    animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
    0% { transform: scale(0.8); opacity: 0.8; }
    50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 15px var(--success); }
    100% { transform: scale(0.8); opacity: 0.8; }
}

.status-offline {
    background-color: rgba(148, 163, 184, 0.1);
    color: var(--text-secondary);
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.metrics-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-box {
    background: var(--glass-bg);
    padding: 1.2rem;
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.03);
    transition: var(--transition);
}

.metric-box:hover {
    background: rgba(255, 255, 255, 0.07);
    transform: translateY(-2px);
}

/* Flash animation for UI update feedback */
.update-flash {
    animation: flash-border 1.5s ease-out;
}

@keyframes flash-border {
    0% { border-color: var(--accent); box-shadow: 0 0 15px var(--accent-glow); }
    100% { border-color: rgba(255, 255, 255, 0.03); box-shadow: none; }
}

.metric-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.metric-value {
    font-size: 1.8rem;
    font-weight: 700;
}

.metric-pulse .metric-value { color: #ff5252; }
.metric-spo2 .metric-value { color: #448aff; }
.metric-battery .metric-value { color: #bdbdbd; }

.source-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}

.source-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.source-wifi .source-icon { background-color: var(--accent); box-shadow: 0 0 8px var(--accent); }
.source-ble .source-icon { background-color: #2979ff; }

.fall-history {
    margin-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 1rem;
}

.fall-history h3 {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.fall-item {
    background: rgba(255, 23, 68, 0.05);
    border: 1px solid rgba(255, 23, 68, 0.2);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
}

.fall-time {
    color: var(--danger);
    font-weight: 600;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(0, 229, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

[data-vibrate="true"] {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both infinite;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

.history-section {
    margin-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
}

.history-section h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
}

.time-zoom-wrapper {
    display: flex;
    justify-content: center;
    margin: 1.5rem 0;
}

.time-controls {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.05);
    padding: 3px;
    border-radius: 8px;
}

.time-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.time-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.time-btn.active {
    background: var(--accent);
    color: var(--bg-color);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}


.chart-container {
    height: 180px;
    width: 100%;
    margin-top: 0.5rem;
    position: relative;
}

.map-section {
    margin-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
}

.map-section h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.map-container {
    height: 200px;
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background-color: #1a1a1a;
}

/* Leaflet Dark Mode Adjustment */
.leaflet-container {
    background-color: #1a1a1a !important;
}

.leaflet-tile {
    filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

.marker-label {
    background: var(--card-bg);
    border: 1px solid var(--accent);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    white-space: nowrap;
    position: absolute;
    bottom: 30px; /* Position above the icon */
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    line-height: 1.1;
    text-align: center;
}

.marker-time {
    font-size: 8px;
    opacity: 0.8;
    font-weight: 500;
}

.marker-watch {
    color: var(--accent);
    font-size: 24px;
    text-shadow: 0 0 10px var(--accent);
}

.marker-phone {
    color: var(--success);
    font-size: 24px;
    text-shadow: 0 0 10px var(--success);
}

/* === TIMELINE STYLES === */
.timeline-section {
    margin-top: 1rem;
    padding: 0.8rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.timeline-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.timeline-info {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 700;
}

.timeline-slider-container {
    width: 100%;
    position: relative;
    padding: 10px 0;
}

.timeline-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    transition: var(--transition);
}

.timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-glow);
    border: 2px solid var(--bg-color);
    cursor: pointer;
    transition: var(--transition);
}

.timeline-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px var(--accent);
}

.timeline-slider:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.leaflet-watch-path {
    stroke: var(--accent);
    stroke-opacity: 0.6;
    stroke-width: 3;
    stroke-dasharray: 5, 5;
    filter: drop-shadow(0 0 5px var(--accent-glow));
}

.monitor-guide {
    margin-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
}

.monitor-guide h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.8rem;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
    background: rgba(255, 255, 255, 0.03);
    padding: 1rem;
    border-radius: 8px;
}

.guide-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.guide-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.guide-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* === MODAL HELP === */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--card-bg);
    margin: 10% auto;
    padding: 2.5rem;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 550px;
    border-radius: 20px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
    animation: slideDown 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    color: var(--accent);
    font-size: 1.8rem;
    letter-spacing: 2px;
}

.close-btn {
    color: var(--text-secondary);
    font-size: 2.5rem;
    cursor: pointer;
    line-height: 1;
    transition: 0.3s;
}

.close-btn:hover {
    color: var(--accent);
    transform: rotate(90deg);
}

.modal-body h3 {
    color: var(--text-primary);
    margin-bottom: 0.8rem;
    font-size: 1.2rem;
    letter-spacing: 1px;
}

.modal-body p {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.7;
    margin-bottom: 1.8rem;
}

.nav-pill.pill-help {
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-pill.pill-help:hover {
    background: rgba(0, 229, 255, 0.1);
    border-color: var(--accent);
    color: var(--accent);
}

/* === RESPONSIVE DESIGN === */
@media (max-width: 1024px) {
    .nav-container {
        gap: 0.5rem;
    }
    .nav-pill {
        padding: 8px 16px;
        font-size: 0.9rem;
    }
}

@media (max-width: 850px) {
    header {
        flex-direction: column;
        align-items: center;
        gap: 1.5rem;
        padding-bottom: 2rem;
    }
    
    .nav-container {
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
    }

    .dashboard-label {
        width: 100%;
        text-align: center;
        margin-bottom: 0.5rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 1rem;
    }

    .device-card {
        padding: 1rem;
    }

    .metrics-row {
        grid-template-columns: 1fr 1fr;
        gap: 0.8rem;
    }

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

    .modal-content {
        padding: 1.5rem;
        margin: 20% auto;
    }

    .modal-header h2 {
        font-size: 1.4rem;
    }

    .nav-pill {
        width: 100%;
        justify-content: center;
    }

    header .status-badge {
        width: 100%;
        text-align: center;
        margin-left: 0;
        margin-top: 0.5rem;
    }
}
