/* ==========================================
   VARIABLES & BASE CONFIG
   ========================================== */
:root {
    --primary: #1e3a8a;
    --primary-hover: #1d4ed8;
    --success: #22c55e;
    --success-hover: #16a34a;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
    --info: #3b82f6;
    --bg-body: #f8fafc;
    --bg-white: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: rgba(226, 232, 240, 0.8);
    --radius-sm: 4px;
    --radius-md: 6px;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    --nav-height: 70px;
    --sidebar-width: 260px;
}

/* BASE RESET */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body {
    overflow-x: hidden; 
    overflow-y: auto; 
    min-height: 100vh;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* AUTHENTICATION LAYOUT & ANIMATIONS */
body.bg-clean-white, body.bg-soft-gray {
    background-color: var(--bg-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

body:not(.animation-done) {
    overflow: hidden;
}

/* Visibility animations */
.login-section, 
.register-wrapper, 
.register-section {
    opacity: 0;
    visibility: hidden;
    transform: translateX(40px);
    transition: opacity 1s ease, transform 1s ease, visibility 1s;
    width: 100%;
}

body.animation-done .login-section,
body.animation-done .register-wrapper,
body.animation-done .register-section,
html.skip-animation .login-section, 
html.skip-animation .register-wrapper,
html.skip-animation .register-section {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

html:not(.skip-animation) body {
    overflow: hidden;
}

/* FLOATING LOGO ANIMATION */
.giant-floating-logo {
    width: 450px;
    max-width: 100%;
    filter: drop-shadow(0 0 15px rgba(220, 38, 38, 0.7)) 
            drop-shadow(0 0 35px rgba(185, 28, 28, 0.4));
    transition: filter 0.3s ease, transform 0.3s ease;
    cursor: pointer;
    transform-origin: center; 
}

html:not(.skip-animation) .giant-floating-logo {
    animation: angasPopSwirl 3s ease-in-out forwards;
    z-index: 9999;
    position: relative;
}

@keyframes angasPopSwirl {
    0% { transform: translate(35vw, 40vh) scale(0); opacity: 0; }
    10% { transform: translate(35vw, 40vh) scale(0.4); opacity: 1; }
    15% { transform: translate(35vw, 40vh) scale(0.35); }
    25% { transform: translate(35vw, 40vh) scale(0.7); }
    30% { transform: translate(35vw, 40vh) scale(0.65); }
    45% { transform: translate(35vw, 40vh) scale(1.15); }
    55% { transform: translate(35vw, 40vh) scale(1); }
    70% { transform: translate(15vw, 45vh) rotate(360deg) scale(1); }
    85% { transform: translate(-10vw, 15vh) rotate(720deg) scale(1); }
    100% { transform: translate(0, 0) rotate(1080deg) scale(1); }
}

.giant-floating-logo:hover {
    transform: scale(1.04);
    filter: drop-shadow(0 0 25px rgba(239, 68, 68, 0.9)) 
            drop-shadow(0 0 50px rgba(220, 38, 38, 0.6));
}

/* HEADER / NAVBAR */
.top-header, .auth-header {
    display: flex;
    justify-content: flex-end; 
    align-items: center;
    padding: 12px 25px;        
    position: fixed;        
    top: 0;
    left: 0;
    width: 100%;
    box-sizing: border-box;
    z-index: 100;
    background-color: transparent; 
    border-bottom: 2px solid transparent;
    border-image: linear-gradient(to right, #bf953f, #fcf6ba, #b38728, #fbf5b7, #aa771c) 1;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.school-title {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    color: #ffffff;
}

.nav-menu, .header-links {
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav-link, .header-links a {
    color: #ffffff;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.nav-link:hover, .header-links a:hover {
    color: #F5A623;
    transform: translateY(-1px);
}

.link-divider {
    color: #ffffff;
    opacity: 0.7;
    font-size: 0.9rem;
}

/* LAYOUT GRID */
.auth-layout-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    width: 100%;
    min-height: 100vh;
    padding: 80px 4.5% 40px 4.5%;
    align-items: center;
}

.hero-logo-section {
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

.login-container, .register-wrapper {
    width: 100%;
    text-align: left;
}

.welcome-title, .brand-logo {
    color: #f8f9fa;
    font-size: 2em;
    font-weight: 800;
    margin-bottom: 0.4rem;
    letter-spacing: -0.5px;
}

/* INPUT STYLES */
.input-group {
    margin-bottom: 1.2rem;
    text-align: left;
    width: 100%;
}

.input-group label {
    display: block;
    margin-bottom: 0.4rem; 
    font-weight: 600;
    font-size: 0.85rem; 
    color: #334155;
}

.input-group input, .input-group select {
    width: 100%;
    padding: 0.65rem 0.9rem; 
    border: 1px solid #cbd5e1;
    border-radius: 6px; 
    font-size: 0.9rem; 
    outline: none;
    transition: all 0.2s ease;
    background-color: #f8fafc;
}

.input-group input:focus, .input-group select:focus {
    border-color: #1e3a8a;
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}

.auth-footer {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.9rem;
    color: #64748b;
}

.auth-footer a {
    color: #1e3a8a;
    font-weight: 600;
    text-decoration: none;
    margin-left: 5px;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* BUTTONS */
.btn-primary, .upload-btn, .action-submit-btn, .publish-stream-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0.85rem 1.5rem;
    border-radius: var(--radius-sm);
    border: none;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    background-color: var(--primary);
    color: var(--bg-white);
    transition: background-color 0.2s ease, transform 0.1s ease;
    width: 100%;
}

.btn-primary:hover, .upload-btn:hover, .action-submit-btn:hover, .publish-stream-btn:hover { background-color: var(--primary-hover); }
.btn-primary:active, .upload-btn:active, .action-submit-btn:active, .publish-stream-btn:active { transform: scale(0.98); }

.join-btn {
    background: var(--success);
    color: var(--bg-white);
    padding: 0.85rem 1.5rem;
    border-radius: var(--radius-sm);
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    width: auto;
}

.join-btn:hover { background: var(--success-hover); }

/* APP LAYOUT & COMPONENTS */
.upload-card, .form-card-panel, .list-card-panel, .join-class-panel, .workspace-upload-panel, .workspace-feed-stream, .feed-card-node {
    background: var(--bg-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.app-container { display: flex; min-height: 100vh; width: 100%; }

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary);
    display: flex;
    flex-direction: column;
    max-height: 100vh;
    overflow-y: auto;
}

.sidebar-brand { padding: 1.5rem; text-align: center; color: var(--bg-white); font-weight: bold; background-color: #0f2b16; }
.sidebar-menu { display: flex; flex-direction: column; padding: 1rem; gap: 0.8rem; flex-grow: 1; background-color: #0f2b16;}
.sidebar-menu .menu-item { color: var(--bg-white); text-decoration: none; padding: 0.8rem 1rem; border-radius: var(--radius-sm); display: flex; align-items: center; gap: 12px; transition: background 0.3s ease; }
.sidebar-menu .menu-item:hover { background: rgba(255, 255, 255, 0.2); }
.sidebar-menu .logout-item { margin-top: auto; background: rgba(239, 68, 68, 0.2); }

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background-color: rgba(255, 255, 255, 0.2); border-radius: 10px; }

.main-layout { flex: 1; display: flex; flex-direction: column; width: 100%; }
.top-navbar { display: flex; justify-content: space-between; align-items: center; padding: 1rem 2rem; background: var(--bg-white); box-shadow: var(--shadow-sm); width: 100%; height: var(--nav-height); }
.content-wrapper { padding: 2rem; min-height: calc(100vh - var(--nav-height)); }

.alert-msg { padding: 1rem; border-radius: var(--radius-sm); margin-bottom: 1.5rem; display: flex; gap: 10px; }
.success-msg { background: #dcfce7; color: #166534; border-left: 4px solid var(--success); }
.error-msg { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--danger); }

.data-portal-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-portal-table th { background: var(--bg-body); padding: 1rem; border-bottom: 2px solid var(--border-color); color: var(--text-muted); }
.data-portal-table td { padding: 1rem; border-bottom: 1px solid var(--border-color); }

.badge-section { background: var(--bg-body); color: var(--text-muted); padding: 0.25rem 0.75rem; border-radius: 20px; font-size: 0.85rem; font-weight: 500; }
.system-token-code { background: #fef3c7; color: #92400e; padding: 0.4rem 0.8rem; border-radius: var(--radius-sm); font-family: monospace; font-weight: 700; border: 1px dashed var(--warning); }

.subject-cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.5rem; }
.subject-card { background: var(--bg-white); border: 1px solid var(--border-color); border-radius: var(--radius-md); overflow: hidden; transition: transform 0.2s ease, box-shadow 0.2s ease; display: flex; flex-direction: column; height: 100%; }
.subject-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.card-header { padding: 1.5rem; background: linear-gradient(135deg, var(--primary) 0%, var(--info) 100%); color: var(--bg-white); flex-grow: 1; }
.card-footer { padding: 1rem 1.5rem; background: var(--bg-body); border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; }

.classroom-hero-banner { background: linear-gradient(135deg, var(--primary) 0%, #0f172a 100%); color: var(--bg-white); border-radius: var(--radius-md); padding: 2.5rem; display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; box-shadow: 0 4px 15px rgba(30, 58, 138, 0.15); }
.hero-class-code { background: rgba(255, 255, 255, 0.15); border: 2px dashed var(--info); padding: 0.5rem 1.25rem; font-family: monospace; border-radius: var(--radius-sm); color: #fef08a; }

.classroom-workspace-layout { display: grid; grid-template-columns: 1.2fr 2fr; gap: 2rem; align-items: start; }
@media (max-width: 1100px) { .classroom-workspace-layout { grid-template-columns: 1fr; } }
.workspace-upload-panel, .workspace-feed-stream { padding: 2rem; }
.feed-card-node { border: 1px solid var(--border-color); padding: 1.5rem; margin-bottom: 1.5rem; }
.feed-node-header { display: flex; justify-content: space-between; border-bottom: 1px solid var(--bg-body); padding-bottom: 0.75rem; margin-bottom: 1rem; }

/* MODAL */
.modern-modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px); z-index: 9999; justify-content: center; align-items: center; opacity: 0; transition: opacity 0.25s; }
.modern-modal-overlay.show { display: flex; opacity: 1; }
.modern-modal-content { background: var(--bg-white); width: 100%; max-width: 500px; border-radius: var(--radius-md); padding: 24px; transform: translateY(-20px); transition: transform 0.25s; }
.modern-modal-overlay.show .modern-modal-content { transform: translateY(0); }

/* CHAT & BUDDY SYSTEM */
.ai-container { background-color: #f4f4f4; border-radius: var(--radius-md); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03); border: 1px solid #e2e8f0; display: flex; flex-direction: column; height: 70vh; flex: 1; overflow: hidden; }
.grid-container { display: grid; grid-template-rows: 1fr 1fr; gap: 5px; height: 400px; }
.chat-box { flex-grow: 1; padding: 2rem; overflow-y: auto !important; display: flex; flex-direction: column; gap: 1.5rem; background-color: #f8fafc; }
.message-row { display: flex; align-items: flex-end; gap: 1rem; max-width: 80%; }
.ai-row { align-self: flex-start; }
.user-icon { align-self: flex-end; }
.ai-icon { background-color: #0f2b16; color: white; width: 40px; height: 40px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; }
.message-bubble { padding: 1rem 1.5rem; border-radius: 15px; font-size: 0.95rem; line-height: 1.5rem; }
.ai-bubble { background-color: #ffffff; color: #0f2b16; border-bottom-left-radius: var(--radius-md); }
.user-bubble { background-color: #0f2b16; color: white; border-bottom-right-radius: var(--radius-md); }
.chat-input-area { padding: 1.5rem; background-color: white; border: 1px solid #e2e8f0; display: flex; gap: 1rem; }
.chat-input { flex-grow: 1; padding: 1rem 1.5rem; border: 1px solid #000000; border-radius: var(--radius-md); font-size: 0.95rem; outline: none; transition: border-color 0.2s; }
.chat-input-focus { border-color: #1e3a8a; }
.send-btn { background-color: #1e3a8a; color: white; border: none; width: 50px; height: 50px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; transition: background-color 0.2rem; }
.send-btn-hover { background-color: #1d4ed8; }

.buddy-layout { display: flex; gap: 1.5rem; height: 100%; flex: 1; flex-direction: row; overflow: hidden; }
.buddy-sidebar { flex: 1; border-right: 1px solid var(--border-color); padding-right: 1rem; overflow-y: auto !important; display: flex; flex-direction: column; gap: 1.5rem; max-width: 350px; }
.buddy-chat-area { flex: 2; display: flex; flex-direction: column; background-color: var(--bg-body); border: 1px solid var(--border-color); border-radius: var(--radius-md); overflow: hidden; }
.buddy-section h4 { font-size: 0.9rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 1rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
.invite-form { display: flex; flex-direction: column; gap: 0.5rem; }
.invite-card { background-color: var(--bg-body); padding: 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border-color); margin-bottom: 0.5rem; }
.invite-card p { font-size: 0.85rem; margin-bottom: 0.5rem; }
.invite-actions { display: flex; gap: 0.5rem; }
.buddy-link { display: flex; align-items: center; gap: 1rem; padding: 0.8rem 1rem; border-radius: var(--radius-sm); text-decoration: none; color: var(--text-main); transition: background-color 0.2s; border: 1px solid transparent; }
.buddy-link:hover, .buddy-link.active-buddy { background-color: var(--bg-body); border-color: var(--border-color); }
.buddy-link i { font-size: 1.5rem; color: #1e3a8a; }
.buddy-link span { display: block; font-size: 0.75rem; color: var(--text-muted); }
.no-chat-selected { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); }
.no-chat-selected i { font-size: 4rem; margin-bottom: 1rem; opacity: 0.2; }

.todo-board { height: calc(100vh - 200px); display: flex; flex-direction: column; overflow: hidden !important; }
.todo-list-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.tab-content.active { flex: 1; display: flex; flex-direction: column; height: 100%; overflow: hidden; padding: 1rem 1.5rem; }

.hp-dashboard-container {
    overflow: visible;
}

/* ==========================================
   MOBILE & TABLET MEDIA QUERIES
   ========================================== */
@media screen and (max-width: 900px) {
    .top-header, .auth-header { 
        padding: 10px 15px; 
        background: rgba(15, 43, 22, 0.85);
        backdrop-filter: blur(8px);
    }

    .auth-layout-grid { 
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 80px 15px 30px 15px; 
        gap: 15px;
    }

    .hero-logo-section {
        position: relative;
        top: 0;
        left: 0;
        transform: none;
        display: flex;
        justify-content: center;
        width: 100%;
        margin-bottom: 5px;
    }

    .giant-floating-logo { 
        width: 110px; 
        height: 110px;
        border-radius: 50%;
        border: 3px solid #ffffff; 
        background-color: #ffffff;
        box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    }

    .login-section, .register-wrapper { 
        justify-content: center; 
        width: 100%;
        margin-top: 0; 
    }

    body.bg-clean-white, body.bg-soft-gray {
        background-position: center center;
        background-size: cover;
        background-attachment: fixed;
    }
}

@media screen and (max-width: 768px) {
    .app-container { display: block; position: relative; width: 100%; }
    .sidebar { position: fixed; top: 0; left: 0; width: 280px; height: 100vh; z-index: 99999; transform: translateX(-100%); transition: transform 0.3s ease-in-out; box-shadow: 5px 0 15px rgba(0,0,0,0.3); }
    .sidebar.active { transform: translateX(0); }
    .main-layout { width: 100%; }
    .top-navbar { width: 100%; padding: 15px; position: sticky; top: 0; z-index: 999; }
    .todo-board { height: calc(100vh - 150px); }
    .buddy-layout { flex-direction: column; height: auto; }
    .buddy-sidebar { max-width: 100%; height: 150px; flex: none; }
}