/* 
   Botones2Vida - Medical Theme (Warm & Professional)
   Design System for GPS Monitoring
*/

:root {
    /* Medical Warm Palette */
    --primary: #0d9488;        /* Teal Medical professional */
    --primary-light: #ccfbf1;  
    --secondary: #f97316;      /* Orange Warm (Alerts/Urgency) */
    --accent: #0ea5e9;         /* Sky Blue (Trust) */
    
    /* Neutral / Warm Tones */
    --bg-main: #fcfaf7;        /* Soft Cream Background */
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --card-hover: #f1f5f9;
    
    /* Text */
    --text-main: #1e293b;      /* Slate 800 */
    --text-dim: #64748b;       /* Slate 500 */
    --text-on-primary: #ffffff;
    
    /* Semantic */
    --success: #16a34a;
    --danger: #dc2626;         /* Clear Medical Red */
    --warning: #eab308;
    
    /* Misc */
    --radius-lg: 16px;
    --radius-md: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --transition: cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    margin: 0;
    font-family: 'Outfit', 'Inter', sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Loading Overlay */
#loader {
    position: fixed;
    inset: 0;
    background: var(--bg-main);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--primary-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Sidebar Design */
#sidebar {
    width: 380px;
    background: var(--sidebar-bg);
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0,0,0,0.05);
    z-index: 100;
}

header {
    padding: 32px 24px;
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
    border-bottom: 1px solid #f1f5f9;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo-mark {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3);
}

h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: -0.02em;
}

.uptime-indicator {
    font-size: 0.75rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.pulse {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    position: relative;
}

.pulse::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: inherit;
    border-radius: 50%;
    animation: pulse-ring 2s infinite;
}

/* Search & Filters */
.search-box {
    margin-top: 20px;
}

.search-box input {
    width: 100%;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid #e2e8f0;
    font-family: inherit;
    font-size: 0.9rem;
    background: #f8fafc;
    transition: all 0.2s ease;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px var(--primary-light);
}

.filter-controls {
    margin-top: 16px;
}

.switch-container {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-dim);
    font-weight: 500;
}

/* Stats Summary */
.stats-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 20px;
    padding: 12px;
    background: #f8fafc;
    border-radius: var(--radius-md);
    border: 1px solid #f1f5f9;
}

.mini-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.m-val {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.m-lbl {
    font-size: 0.65rem;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--text-dim);
}

/* Map Controls Container */
.map-controls {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Map Buttons */
.map-btn {
    width: 44px;
    height: 44px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    color: var(--text-main);
    transition: all 0.2s ease;
}

.map-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
    transform: scale(1.05);
}

/* Maximize State */
body.maximized-map #sidebar {
    width: 0;
    overflow: hidden;
    border: none;
    opacity: 0;
    pointer-events: none;
}

@keyframes pulse-ring {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(2.5); opacity: 0; }
}

/* Device List */
#device-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

.device-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    border: 1px solid #e2e8f0;
    transition: all 0.3s var(--transition);
    position: relative;
    cursor: pointer;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.device-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    background: var(--card-hover);
}

.device-card.active {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 2px var(--primary-light);
}

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

.imei {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.battery-pill {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.battery-pill.bat-good {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid rgba(22, 163, 74, 0.1);
}

.battery-pill.bat-low {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.1);
}

.telemetry-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.data-point {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.label {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.value {
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 500;
}

/* Map UI */
#map-wrapper {
    flex: 1;
    position: relative;
    background: #e5e7eb;
}

#map {
    width: 100%;
    height: 100%;
}

/* Custom Map Styles (Lighter for medical theme) */
/* Custom Map Styles (Optional overrides) */

/* Floating Controls */
.map-stats {
    position: absolute;
    top: 24px;
    right: 24px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-md);
    border: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: flex;
    gap: 24px;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label { font-size: 0.65rem; color: var(--text-dim); font-weight: 700; text-transform: uppercase; }
.stat-val { font-size: 1.1rem; font-weight: 600; color: var(--primary); }

/* Marker Customization */
.custom-marker {
    background: var(--primary);
    border: 3px solid #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

/* SOS State Classes */
.device-card.alert-sos {
    border-color: var(--danger);
    background: #fef2f2;
    animation: alert-pulse 2s infinite;
}

/* Helpers */
.hidden { display: none !important; }

.text-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    margin-bottom: 20px;
    font-family: inherit;
    font-size: 0.9rem;
}

.text-btn:hover { text-decoration: underline; }

/* Detail View Styles */
#details-view {
    padding: 0 4px;
}

.detail-card {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid #e2e8f0;
    box-shadow: var(--shadow);
}

.detail-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-main);
    text-align: center;
}

.detail-info-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid #f1f5f9;
}

.detail-info-row:last-child { border-bottom: none; }

.detail-label { color: var(--text-dim); font-size: 0.85rem; }
.detail-value { font-weight: 600; font-size: 0.85rem; }

.detail-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    margin-top: 24px;
}

.btn-action {
    padding: 12px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--primary);
    color: white;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s;
}

.btn-action:hover { background: #0b7a6f; }

/* Mobile Responsiveness */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        height: 60vh;
        order: 2;
        border-right: none;
        border-top: 1px solid #e2e8f0;
    }

    #map-wrapper {
        height: 40vh;
        order: 1;
    }

    .map-controls {
        top: 12px;
        left: 12px;
    }

    .map-stats {
        top: 12px;
        right: 12px;
        padding: 8px 12px;
        gap: 12px;
    }

    header {
        padding: 16px 20px;
    }

    .stats-summary {
        margin-top: 12px;
    }

    /* Override maximized behavior on mobile */
    body.maximized-map #sidebar {
        height: 0;
        min-height: 0;
    }

/* Reports Page Specifics */
.reports-page #sidebar {
    background: #4a6d71; /* Darker teal/slate from screenshot */
    color: white;
}

.reports-page header h1 { color: white; }
.reports-page .label { color: rgba(255,255,255,0.8); }

.tabs-report {
    display: flex;
    margin-top: 24px;
    border-bottom: 2px solid rgba(255,255,255,0.1);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 12px;
    color: rgba(255,255,255,0.6);
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    position: relative;
}

.tab-btn.active {
    color: white;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--accent);
}

.report-filters {
    margin-top: 20px;
}

.filter-group {
    margin-bottom: 16px;
}

.filter-group input, .filter-group select {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.2);
    background: white;
    font-family: inherit;
}

.date-range {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Results */
.results-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.result-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--text-main);
    box-shadow: var(--shadow);
}

.res-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
}

.res-icon.alert { background: #fecaca; border: 2px solid var(--danger); }
.res-icon.good { background: #dcfce7; border: 2px solid var(--success); }

.res-info {
    display: flex;
    flex-direction: column;
}

.res-name { font-weight: 700; font-size: 0.85rem; }
.res-date { font-size: 0.75rem; color: var(--text-dim); }
.res-type { font-size: 0.75rem; font-weight: 600; }

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.btn-primary-w {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}

/* Main Area */
#main-reports {
    flex: 1;
    padding: 40px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.top-stats-bar {
    display: flex;
    background: white;
    border-radius: 16px;
    padding: 32px;
    box-shadow: var(--shadow);
    gap: 40px;
    align-items: center;
}

.city-box {
    padding: 0 40px;
    border-right: 2px solid #f1f5f9;
}

.city-name { font-size: 2.5rem; font-weight: 800; color: #1e293b; }

.stat-box { display: flex; flex-direction: column; }
.st-label { font-size: 0.9rem; font-weight: 600; color: var(--text-dim); }
.st-value { font-size: 1.5rem; font-weight: 700; color: #1e293b; }

.heatmap-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.section-title { font-size: 1.5rem; color: #1e293b; }

#heatmap-container {
    flex: 1;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow);
}

.nav-link {
    color: var(--text-dim);
    display: flex;
    align-items: center;
    transition: color 0.2s;
}

.nav-link:hover { color: var(--primary); }
}
/* SOS Alert Interface */
.sos-alert-screen {
    position: fixed; inset: 0; background: rgba(220, 38, 38, 0.4);
    backdrop-filter: blur(10px); z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    animation: flash-bg 1s infinite alternate;
}

@keyframes flash-bg {
    from { background: rgba(220, 38, 38, 0.4); }
    to { background: rgba(220, 38, 38, 0.7); }
}

.sos-alert-card {
    background: white; padding: 50px; border-radius: 30px;
    box-shadow: 0 0 100px rgba(0,0,0,0.5); text-align: center;
    width: 90%; max-width: 600px; animation: pop-up 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop-up { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.sos-header { font-weight: 800; color: #dc2626; font-size: 1.5rem; margin-bottom: 20px; letter-spacing: 2px; }
.sos-meta { display: flex; gap: 10px; justify-content: center; margin: 20px 0; }
.sos-meta .pill { background: #fee2e2; color: #dc2626; padding: 6px 15px; border-radius: 20px; font-weight: 700; font-size: 0.8rem; }
.sos-imei { font-family: monospace; color: #64748b; font-size: 1.1rem; }

/* Pulsing SOS Marker in Map */
.alert-sos .custom-marker {
    background: #dc2626 !important;
    animation: pulse-sos 0.6s infinite alternate !important;
    box-shadow: 0 0 20px #dc2626;
}

@keyframes pulse-sos {
    from { transform: scale(1); opacity: 1; }
    to { transform: scale(1.6); opacity: 0.8; }
}

.device-card.alert-sos {
    border: 2px solid #dc2626;
    background: #fff1f2;
    animation: shake 0.5s infinite;
}

@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

/* ===================================================
   ADMIN PORTAL — Estilos del portal de administración
   =================================================== */

body.admin-page {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: #f8fafc;
}

body.admin-page #sidebar {
    width: 270px;
    background: #0f172a;
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    padding: 28px 14px;
    border-right: none;
    box-shadow: 10px 0 30px rgba(0,0,0,0.12);
    flex-shrink: 0;
    overflow-y: auto;
}

body.admin-page #sidebar header {
    padding: 0 12px;
    background: transparent;
    border: none;
}

body.admin-page .brand { margin-bottom: 36px; }
body.admin-page .brand h1 { color: white; font-size: 1.35rem; font-weight: 700; }
body.admin-page .logo-mark { width: 40px; height: 40px; border-radius: 12px; }

.label-section {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 700;
    color: #475569;
    margin: 22px 0 6px 14px;
}

.btn-nav-premium {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 11px 14px;
    border-radius: 11px;
    text-decoration: none;
    color: #94a3b8;
    margin-bottom: 3px;
    transition: all 0.25s ease;
    font-weight: 500;
    font-size: 0.88rem;
}

.btn-nav-premium:hover,
.btn-nav-premium.active {
    background: rgba(255,255,255,0.07);
    color: white;
}

.btn-nav-premium.active i { color: var(--primary); }

.admin-sidebar-footer { margin-top: auto; padding: 20px 14px; }

.admin-exit-btn { background: rgba(220,38,38,0.1); color: #f87171 !important; }
.admin-exit-btn:hover { background: rgba(220,38,38,0.2); }

main.admin-main {
    flex: 1;
    padding: 48px;
    overflow-y: auto;
    background: #f8fafc;
}

.admin-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 36px;
}

.admin-page-header h2 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
}

.admin-card {
    background: white;
    border-radius: 16px;
    padding: 28px;
    border: 1px solid #f1f5f9;
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
}

.tech-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.tech-table th {
    padding: 11px 15px;
    text-align: left;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    font-weight: 700;
    border-bottom: 1px solid #f1f5f9;
}
.tech-table td { padding: 13px 15px; border-bottom: 1px solid #f8fafc; color: var(--text-main); }
.tech-table tr:last-child td { border-bottom: none; }
.tech-table tr:hover td { background: #f8fafc; }

.beneficiary-grid-modern {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 22px;
}

.beneficiary-card {
    background: white;
    padding: 24px;
    border-radius: 18px;
    border: 1px solid #f1f5f9;
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
    transition: all 0.28s ease;
    position: relative;
}

.beneficiary-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 28px rgba(0,0,0,0.06);
    border-color: var(--primary);
}

.card-top { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }

.avatar {
    width: 52px; height: 52px;
    background: #f0fdf4; color: var(--primary);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1.25rem;
    border: 2px solid white; box-shadow: 0 2px 8px rgba(0,0,0,0.05); flex-shrink: 0;
}

.user-info h5 { margin: 0; font-size: 1.05rem; color: #334155; font-weight: 600; }
.user-info p  { margin: 3px 0 0; font-size: 0.82rem; color: #94a3b8; }

.pills-container { display: flex; gap: 7px; flex-wrap: wrap; }
.pill { font-size: 0.68rem; padding: 4px 11px; border-radius: 20px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.pill-rh    { background: #fee2e2; color: #b91c1c; }
.pill-group { background: #f1f5f9; color: #475569; }

.assignments-grid    { display: grid; grid-template-columns: 2fr 1fr; gap: 28px; }
.form-select-admin   { width: 100%; padding: 11px; border-radius: 10px; border: 1px solid #e2e8f0; margin-bottom: 14px; font-family: inherit; font-size: 0.9rem; color: var(--text-main); background: white; }

.grupos-grid         { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; }
.group-stat-card     { text-align: center; }

.empty-state { height: 380px; display: flex; align-items: center; justify-content: center; background: #fafafa; border: 2px dashed #e2e8f0; border-radius: 16px; }
.empty-state p { color: #94a3b8; margin: 0; }

/* Status badge colors for inventory */
.badge-activo   { background: #f0fdf4; color: #16a34a; border: 1px solid rgba(22,163,74,0.15); }
.badge-inactivo { background: #fef2f2; color: #dc2626; border: 1px solid rgba(220,38,38,0.15); }
.badge-stock    { background: #fff7ed; color: #c2410c; border: 1px solid rgba(194,65,12,0.15); }
.status-badge   { padding: 4px 10px; border-radius: 6px; font-size: 0.65rem; font-weight: 800; display: inline-block; }
