/**
 * AEGIS v5.0 - DYNAMIC RESPONSIVE ARCHITECTURE
 * Optimized for Mobile, Tablet, and Desktop
 */

 :root {
    color-scheme: dark;
    --primary: #3498db;
    --primary-container: #1e3a5f;
    --on-primary: #ffffff;
    --error: #e74c3c;
    --bg-surface: #1a1c1e;
    --bg-surface-variant: #282a2d;
    --outline: #44474a;
    --text-primary: #e2e2e6;
    --text-secondary: #c4c6cf;
    --elevation-1: 0 1px 3px rgba(0,0,0,0.2);
    --elevation-3: 0 4px 8px rgba(0,0,0,0.3);
}

.theme-light {
    color-scheme: light;
    --bg-surface: #fdfcff;
    --bg-surface-variant: #f0f0f3;
    --text-primary: #1a1c1e;
    --text-secondary: #44474a;
    --outline: #d8dae0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
    background: var(--bg-surface);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* Layout Core */
.app-container {
    display: flex;
    height: 100vh;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease;
}

.app-container.revealed {
    opacity: 1 !important;
    pointer-events: all !important;
}

aside {
    width: 300px;
    padding: 2rem;
    background: var(--bg-surface);
    border-right: 1px solid var(--outline);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

main {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    position: relative;
}

/* Navigation Items */
.nav-item {
    height: 56px;
    border-radius: 28px;
    padding: 0 24px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-item i { width: 20px; text-align: center; }

.tactical-bullet {
    color: var(--primary);
    margin-right: 6px;
    filter: drop-shadow(0 0 4px rgba(52, 152, 219, 0.4));
}

.nav-item:hover { background: rgba(52, 152, 219, 0.1); color: var(--primary); }
.nav-item.active { background: var(--primary-container); color: var(--primary); font-weight: 700; }

/* Dashboard Components */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 24px;
    height: calc(100vh - 280px);
}

.monitor-panel {
    background: var(--bg-surface-variant);
    border-radius: 28px;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-surface-variant);
    padding: 1.5rem;
    border-radius: 24px;
    border: 1px solid var(--outline);
    box-shadow: var(--elevation-1);
}

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

.action-btn:active { transform: scale(0.96); }
.action-btn.outlined { background: transparent; border: 1px solid var(--outline); color: var(--text-primary); }
.action-btn.sos { background: #b3261e; color: white; width: 100%; height: 56px; font-weight: 700; letter-spacing: 1px; }

/* Plan / PPT Components */
.plan-card {
    background: var(--bg-surface-variant);
    border-radius: 28px;
    padding: 40px;
    height: calc(100vh - 180px);
    display: flex;
    flex-direction: column;
}

#ppt-viewport { flex: 1; overflow-y: auto; }
.plan-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
    gap: 16px;
    width: 100%;
    flex-wrap: wrap; /* Allow wrapping if space is tight */
}
.plan-types, .plan-nav { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* Tactical Map */
#main-map { border-radius: 28px; z-index: 10; }
.map-nav-controls {
    position: absolute;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: rgba(26, 28, 30, 0.8);
    padding: 12px;
    border-radius: 50%;
    backdrop-filter: blur(10px);
    border: 1px solid var(--outline);
}

.map-nav-controls button {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
}

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: none;
    place-items: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--bg-surface-variant);
    padding: 2.5rem;
    border-radius: 32px;
    width: 90%;
    max-width: 450px;
    box-shadow: var(--elevation-3);
    border: 1px solid var(--outline);
}

.form-group { margin-bottom: 1.5rem; }
.form-group label { display: block; margin-bottom: 8px; font-size: 0.85rem; color: var(--text-secondary); }
.form-group input {
    width: 100%;
    height: 48px;
    border-radius: 12px;
    border: 1px solid var(--outline);
    background: var(--bg-surface);
    color: var(--text-primary);
    padding: 0 16px;
    font-size: 1rem;
}

/* Animations */
@keyframes toastEnter {
    from { transform: translateX(100%) scale(0.9); opacity: 0; }
    to { transform: translateX(0) scale(1); opacity: 1; }
}

.danger-pulse { animation: dangerPulse 1.5s infinite; }
@keyframes dangerPulse {
    0% { filter: drop-shadow(0 0 2px #e74c3c); transform: scale(1); }
    50% { filter: drop-shadow(0 0 12px #e74c3c); transform: scale(1.1); }
    100% { filter: drop-shadow(0 0 2px #e74c3c); transform: scale(1); }
}

/* Tactical Map Markers */
.tactical-marker-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.tactical-marker-core {
    width: 12px;
    height: 12px;
    background: white;
    border: 3px solid var(--error);
    border-radius: 50%;
    z-index: 2;
    box-shadow: 0 0 10px var(--error);
}

.tactical-marker-pulse {
    position: absolute;
    width: 30px;
    height: 30px;
    background: rgba(231, 76, 60, 0.4);
    border-radius: 50%;
    animation: tacticalPulse 2s infinite ease-out;
    z-index: 1;
}

@keyframes tacticalPulse {
    0% { transform: scale(0.5); opacity: 1; }
    100% { transform: scale(2.5); opacity: 0; }
}

/* Responsive View Management */
.view-content { display: none; }
.view-content.active { display: block; animation: viewEnter 0.4s ease-out; }

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

/* =========================================
   TACTICAL MEDIA QUERIES (Mobile & Tab)
   ========================================= */

@media (max-width: 1024px) {
    aside { width: 260px; padding: 1.5rem; }
    .dashboard-stats { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr !important; height: auto !important; gap: 16px; }
    #main-map { height: 450px !important; min-height: 400px; }
}

@media (max-width: 768px) {
    aside {
        position: fixed;
        left: 0; top: 0;
        height: 100vh;
        transform: translateX(-100%);
        box-shadow: 20px 0 50px rgba(0,0,0,0.5);
    }
    aside.mobile-active { transform: translateX(0); }

    main { padding: 0.75rem; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
    #mobile-menu-toggle { display: flex !important; }
    .desktop-only { display: none !important; }

    .dashboard-grid { 
        display: flex !important;
        flex-direction: column;
        gap: 16px; 
        height: auto !important; 
    }
    
    #main-map { 
        height: 300px !important; 
        width: 100%;
        order: -1; /* Move map above the monitor */
    }

    .dashboard-stats { 
        grid-template-columns: repeat(3, 1fr) !important; 
        gap: 8px !important; 
        margin-bottom: 16px !important;
    }
    
    .stat-card { 
        padding: 8px !important; 
        text-align: center;
        border-radius: 12px !important;
    }
    
    .stat-card div:first-child { font-size: 0.5rem !important; margin-bottom: 4px; }
    .stat-card div:last-child { font-size: 0.9rem !important; }

    .monitor-panel { padding: 16px !important; }

    .modal-content { padding: 1.5rem; border-radius: 24px; }
    
    /* Responsive Chat */
    #view-discussion > div { grid-template-columns: 1fr !important; height: auto !important; }
    #discussion-list { margin-bottom: 1rem; max-height: 200px; overflow-y: auto; }
    #thread-messages { height: 400px !important; }

    /* Responsive PPT */
    .plan-card { padding: 1.5rem; height: auto; min-height: 70vh; }
    .plan-controls { flex-direction: column; align-items: stretch; gap: 20px; }
    .plan-types { display: flex; flex-direction: row; flex-wrap: wrap; width: 100%; gap: 10px; justify-content: center; }
    .plan-types button { flex: 1; min-width: 120px; height: 50px; font-size: 0.9rem; }
    .plan-nav { justify-content: space-between; border-top: 1px solid var(--outline); padding-top: 20px; gap: 12px; }
    .plan-nav .action-btn { flex: 1; height: 44px; }
    #ppt-viewport h1 { font-size: 1.4rem; margin-bottom: 16px; color: var(--primary); }
    
    /* Profile Responsive */
    #view-profile > div { padding: 1.5rem !important; }
}

@media (max-width: 480px) {
    .nav-arrows { gap: 4px; }
    .action-btn { padding: 8px 12px; font-size: 0.75rem; min-width: 60px; }
    header { margin-bottom: 16px; }
    .stat-card div:first-child { font-size: 0.65rem; }
}

/* Splash Screen Styling */
#splash-screen {
    position: fixed;
    inset: 0;
    background: #0d0f12;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.splash-logo {
    width: 120px;
    animation: logoPulse 2s infinite cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes logoPulse {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.05); filter: brightness(1.5); }
    100% { transform: scale(1); filter: brightness(1); }
}

/* Chat Bubbles */
.chat-msg {
    margin-bottom: 16px;
    max-width: 85%;
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    position: relative;
    line-height: 1.5;
    transition: transform 0.2s ease;
}

.chat-msg.sent {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    margin-left: auto;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.chat-msg.received {
    background: var(--bg-surface);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--outline);
}

.chat-msg small { 
    display: block; 
    font-size: 0.7rem; 
    opacity: 0.8; 
    margin-bottom: 4px; 
    font-weight: 600;
}

.chat-msg .delete-msg-btn {
    position: absolute;
    right: 8px;
    top: 8px;
    background: rgba(0,0,0,0.2);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    font-size: 0.7rem;
    z-index: 10;
}

.chat-msg.sent .delete-msg-btn { color: white; background: rgba(0,0,0,0.1); }
.chat-msg.sent .delete-msg-btn:hover { background: var(--error); }

.chat-msg:hover .delete-msg-btn { opacity: 1; }
