/* Modern Design System & Variables */
:root {
    /* Brand Colors - NCNU Theme (Yellow Updated) */
    --primary-color: #ffc200;
    --primary-light: #ffca28;
    --primary-dark: #ff8f00;
    --accent-color: #FF9800;
    /* Energetic Orange */
    --accent-hover: #F57C00;

    /* Neutral Colors / Base Variables */
    --text-main: #333333;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-light: #FFFFFF;
    --bg-body: #f9fafb;
    --bg-primary: #EFEAE2; /* Chat Background */
    --bg-secondary: #f0f2f5; /* Chat Input Area */
    --bg-card: #FFFFFF;
    --border-color: #E0E0E0;

    /* Chat Elements */
    --chat-bubble-mine: var(--primary-color);
    --chat-bubble-mine-text: #FFFFFF;
    --chat-bubble-other: #FFFFFF;
    --chat-bubble-other-text: #333333;
    --chat-input-bg: #FFFFFF;
    --chat-input-text: #333333;

    /* Shadows & Effects */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;

    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

/* Dark Theme Variables */
:root[data-theme="dark"] {
    --text-main: #E4E6EB;
    --text-primary: #E4E6EB;
    --text-secondary: #B0B3B8;
    --text-light: #f8fafc;
    --bg-body: #18191A;
    --bg-primary: #0F0F0F; /* Dark Chat Background */
    --bg-secondary: #242526; /* Dark Chat Input Area */
    --bg-card: #242526;
    --border-color: #3E4042;
    
    /* Chat Elements Dark */
    --chat-bubble-mine: var(--primary-dark);
    --chat-bubble-mine-text: #FFFFFF;
    --chat-bubble-other: #3A3B3C;
    --chat-bubble-other-text: #E4E6EB;
    --chat-input-bg: #3A3B3C;
    --chat-input-text: #E4E6EB;

    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    padding-bottom: 80px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

/* Typography */
h1,
h2,
h3 {
    color: var(--primary-dark);
    font-weight: 700;
}

h1 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 0.8rem;
}

/* Utilities */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    transition: max-width var(--transition-normal);
}

@media (max-width: 768px) {
    .container {
        max-width: 100%;
    }
}

.btn {
    display: inline-block;
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius-md);
    background-color: var(--primary-color);
    color: var(--text-light);
    font-weight: 600;
    text-align: center;
    border: none;
    cursor: pointer;
    transition: background-color var(--transition-fast), transform var(--transition-fast);
    width: 100%;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-large {
    font-size: 1.1rem;
    padding: 1rem;
}

.btn-full {
    background: #9E9E9E !important;
    color: white !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    opacity: 0.8;
}

.card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.card h1, .card h2, .card h3, .card h4 {
    color: var(--text-primary);
}

.role-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent-color);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
    margin-bottom: 0;
    color: var(--text-main);
}

.role-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

.input-group {
    margin-bottom: 1.2rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-group input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: border-color var(--transition-fast);
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 194, 0, 0.2);
}

.error-msg {
    color: #D32F2F;
    font-size: 0.85rem;
    margin-top: 0.4rem;
    display: none;
}

/* Color Utilities */
.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-white { color: #FFFFFF !important; }
.text-accent { color: var(--accent-color) !important; }

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn var(--transition-normal) forwards;
}

/* Chat Attachment Styles - Premium Upgrade */
.chat-attachment-img {
    max-width: 250px;
    max-height: 350px;
    width: 100%;
    border-radius: 8px; /* Clean radius per request */
    margin-top: 8px;
    display: block;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
    object-fit: cover;
    cursor: pointer;
}

.chat-attachment-img:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
}

.chat-attachment-video {
    max-width: 250px;
    width: 100%;
    aspect-ratio: 16/9; /* Reserve space to prevent UI Jumping */
    object-fit: contain;
    background: #000;
    border-radius: 8px;
    margin-top: 8px;
    display: block;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Elegant File Card (WhatsApp Inspired) */
.file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f0f2f5; /* Light mode default */
    padding: 12px 16px;
    border-radius: 10px;
    margin-top: 8px;
    text-decoration: none;
    color: #1c1e21;
    transition: all 0.2s ease;
    border: 1px solid rgba(0,0,0,0.05);
    min-width: 220px;
    max-width: 280px;
    position: relative;
    overflow: hidden;
}

:root[data-theme="dark"] .file-card {
    background: rgba(255, 255, 255, 0.08);
    color: #e4e6eb;
    border-color: rgba(255, 255, 255, 0.05);
}

.file-card:hover {
    background: #e4e6eb;
    transform: scale(1.01);
}

:root[data-theme="dark"] .file-card:hover {
    background: rgba(255, 255, 255, 0.12);
}

.file-icon {
    width: 44px;
    height: 44px;
    background: var(--primary-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.file-info {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.file-name {
    display: block;
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.file-size {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.8;
}

.file-download-icon {
    font-size: 1.3rem;
    color: var(--primary-dark);
    opacity: 0.7;
    transition: opacity 0.2s;
    margin-left: 4px;
}

.file-card:hover .file-download-icon {
    opacity: 1;
}

/* Glassmorphism Media Actions */
.chat-attachment-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.chat-media-actions {
    position: absolute;
    bottom: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateY(5px);
    z-index: 10;
}

.chat-attachment-wrapper:hover .chat-media-actions {
    opacity: 1;
    transform: translateY(0);
}

.btn-media-download {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 6px 14px;
    border-radius: 20px;
    color: white !important;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.btn-media-download:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.btn-media-download .icon {
    font-size: 1rem;
}

/* Ensure controls are visible for video even if hovered */
.chat-attachment-video:focus, 
.chat-attachment-video:active {
    outline: none;
}

/* ============================================
   Ads Carousel — iOS Safari-Proof
   ============================================ */

/* 1. CAROUSEL CONTAINER */
.ads-carousel-container {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 1;
    overflow: hidden;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;

    /* iOS Safari trick: forces GPU compositing so
       border-radius + overflow:hidden actually clips children */
    -webkit-mask-image: -webkit-radial-gradient(white, black);
    mask-image: radial-gradient(white, black);
    /* Prevent Safari from ignoring overflow on the flex container */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Fallback for browsers that don't support aspect-ratio (older Safari <15) */
@supports not (aspect-ratio: 3 / 1) {
    .ads-carousel-container {
        height: 0;
        padding-bottom: 33.333%; /* 1/3 = 33.333% for 3:1 ratio */
    }
    .ads-carousel-container > .ads-carousel-track {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

/* 2. CAROUSEL TRACK */
.ads-carousel-track {
    display: flex;
    height: 100%;
    transition: transform 0.5s ease-in-out;
    /* Prevent Safari from collapsing flex container height */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* 3. SLIDE ITEMS (the <a> wrappers) */
.ads-carousel-track > a,
.ads-carousel-track > .carousel-slide {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    display: block;
    /* Prevent Safari flex shrink bug */
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
    min-width: 0;
}

/* 4. IMAGE ELEMENT */
.ads-carousel-track img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    /* Prevent Safari from adding weird spacing */
    -webkit-user-drag: none;
}

/* ============================================
   Custom Pull-to-Refresh Indicator
   ============================================ */
.ptr-element {
    position: absolute;
    top: -50px;
    left: 0;
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 1000;
    transition: transform 0.1s linear;
}

.ptr-icon {
    width: 38px;
    height: 38px;
    background: var(--bg-card);
    border-radius: 50%;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--primary-color);
    transform: scale(0);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid var(--border-color);
}

.ptr-element.pulling .ptr-icon {
    transform: scale(1);
}

.ptr-element.refreshing .ptr-icon {
    transform: scale(1);
    animation: ptr-spin 0.8s linear infinite;
}

@keyframes ptr-spin {
    from { transform: scale(1) rotate(0deg); }
    to { transform: scale(1) rotate(360deg); }
}

/* ============================================
   Skeleton Loading Shimmer Effects
   ============================================ */
.skeleton {
    background: #e1e9ee;
    background-image: linear-gradient(
        90deg,
        #e1e9ee 0px,
        #f2f8fc 40px,
        #e1e9ee 80px
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: 4px;
}

:root[data-theme="dark"] .skeleton {
    background: #2a2e33;
    background-image: linear-gradient(
        90deg,
        #2a2e33 0px,
        #3d444d 40px,
        #2a2e33 80px
    );
}

@keyframes shimmer {
    0% { background-position: -100% 0; }
    100% { background-position: 100% 0; }
}

.skeleton-text {
    height: 1.2rem;
    width: 100%;
    margin-bottom: 0.5rem;
}

.skeleton-circle {
    width: 60px;
    height: 60px;
    border-radius: 50% !important;
}

/* ============================================
   Global Header UI Fixes (Overlap & Redundancy)
   ============================================ */
/* 1. Remove redundant/overlapping avatar marked for removal */
.avatar, .header-avatar-legacy {
    display: none !important;
}

/* 2. Fix Dropdown Overlap (Z-Index) */
.lang-selector-dropdown {
    position: relative;
    z-index: 1001; /* Above other header elements */
}

/* 3. Polishing Spacing & Alignment */
header #header-user-avatar {
    margin-right: 4px;
}

/* Ensure flex containers in header have consistent gap */
header div {
    gap: 0.8rem;
}