/* Base Styling & Variables */
:root {
    --primary: #1d4ed8;
    /* Tech Blue */
    --primary-light: #2563eb;
    --primary-dark: #1e40af;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;

    --sidebar-width: 250px;

    /* Badge Gradients */
    --badge-gold: linear-gradient(135deg, #f59e0b, #d97706);
    --badge-purple: linear-gradient(135deg, #8b5cf6, #6d28d9);
    --badge-teal: linear-gradient(135deg, #0d9488, #0f766e);
    --badge-rose: linear-gradient(135deg, #e11d48, #be123c);
    --mobile-header-height: 6.75rem;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-padding-top: 1.5rem;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Layout */
.layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: #ffffff;
    border-right: 1px solid var(--border-color);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.03);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    padding: 2.5rem 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    position: relative;
    overflow: hidden;
}

.header-bg-elements {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    opacity: 0.5;
}

.header-bg-elements::before {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 70%);
    top: -30px;
    left: -20px;
    width: 200px;
    height: 200px;
}

.sidebar-header .logo {
    position: relative;
    z-index: 10;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    letter-spacing: -0.025em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-header .subtitle {
    position: relative;
    z-index: 10;
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.85);
}

.nav-menu {
    padding: 1rem 0;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    font-size: 0.95rem;
}

.nav-item:hover {
    background-color: var(--bg-main);
    color: var(--primary);
}

.nav-item.active {
    background-color: #eff6ff;
    /* A soft blue derived from --primary on normal pages */
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}


/* Main Wrapper */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.mobile-header {
    display: none;
    background: rgba(248, 250, 252, 0.92);
    color: var(--text-main);
    position: sticky;
    top: 0;
    z-index: 80;
    border-bottom: 1px solid rgba(226, 232, 240, 0.85);
    box-shadow: 0 10px 24px -22px rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-direction: column;
}

.mobile-header-top {
    padding: 0.75rem 0.9rem 0.55rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.mobile-header .logo {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.mobile-header-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.mobile-nav-wrapper {
    position: relative;
    padding: 0 0.6rem 0.7rem;
}

.mobile-nav {
    display: flex;
    overflow-x: auto;
    gap: 0.45rem;
    padding: 0.2rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(255, 255, 255, 0.86);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.mobile-nav::-webkit-scrollbar {
    display: none;
}

.mobile-nav-item {
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.45rem 0.85rem;
    white-space: nowrap;
    font-size: 0.81rem;
    font-weight: 500;
    border-radius: 999px;
    transition: color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
    min-height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item.active {
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    box-shadow: 0 6px 14px -10px rgba(29, 78, 216, 0.85);
    font-weight: 600;
}

.mobile-nav-item:active {
    transform: scale(0.98);
}

/* Container */
.container {
    padding: 3rem 2.5rem;
    max-width: 1400px;
    width: 100%;
}

.section {
    margin-bottom: 4rem;
}

.section-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    letter-spacing: -0.015em;
    margin-bottom: 2rem;
}

.section-title::before {
    content: '';
    display: inline-block;
    width: 5px;
    height: 24px;
    background-color: var(--primary-light);
    border-radius: 4px;
}

/* Grid Layout */
.grid {
    display: grid;
    gap: 1.25rem;
    padding: 10px;
    margin: -10px;
    grid-auto-flow: dense;
    /* Fill the gaps left by the span-2 components */
}

/* Responsive columns scaling: keeping items roughly same physical size across breakpoints */
@media (min-width: 0px) {
    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 640px) {
    .grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 1.5rem;
    }
}

@media (min-width: 1280px) {
    .grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 1.75rem;
    }
}

@media (min-width: 1536px) {
    .grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 1.75rem;
    }
}

/* Character Card */
.card {
    background-color: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 15px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    border-color: #cbd5e1;
    z-index: 5;
}

/* 1) ENLARGE the leader cards inside the grid structure */
.card-large {
    grid-column: span 2;
    grid-row: span 2;
    border: 2px solid var(--primary-light);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card-large:hover {
    transform: translateY(-4px) scale(1.01);
    box-shadow: 0 20px 25px -5px rgba(29, 78, 216, 0.2), 0 10px 10px -5px rgba(29, 78, 216, 0.1);
    border-color: var(--primary);
}

/* Card Image Area */
.card-image-wrapper {
    position: relative;
    width: 100%;
    padding-top: 100%;
    /* Keeps aspect ratio 1:1, crucial for CSS Gri span-2 to form a square */
    background-color: #f1f5f9;
    overflow: hidden;
}

.card-image-loader {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite linear;
    z-index: 1;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.card-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: #ffffff;
    padding: 10%;
    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: 2;
}

/* Slightly more padding on the bigger image so it matches visually and doesnt touch the edges */
.card-large .card-image {
    padding: 12%;
}

.card-image.loaded {
    opacity: 1;
}

/* Badges */
.badge {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #ffffff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
}

.card-large .badge {
    top: 16px;
    right: 16px;
    padding: 0.35rem 1rem;
    font-size: 0.875rem;
}

.badge-role-学科组长,
.badge-role-英语组长,
.badge-role-物理组长,
.badge-role-化学组长 {
    background: var(--badge-rose);
}

.badge-role-校长 {
    background: var(--badge-gold);
}

.badge-role-校长-数学组长 {
    background: var(--badge-gold);
}

.badge-role-校长助理 {
    background: var(--badge-purple);
}

.badge-role-教务主管 {
    background: var(--badge-teal);
}

.badge-role-校区教务 {
    background: var(--badge-teal);
}

.badge-role-default {
    background: var(--badge-gold);
}

/* Card Content / Name Display */
.card-content {
    padding: 1.25rem 1rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
    background-color: var(--card-bg);
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.25rem;
}

.card-large .card-content {
    padding: 1.5rem 1rem;
    gap: 0.45rem;
}

.card-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.2;
}

.card-large .card-name {
    font-size: 1.5rem;
}

.card-subtitle {
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-weight: 500;
}

.card-large .card-subtitle {
    font-size: 1rem;
}

/* Card tap hint */
.card {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* Error Fallback Icon when Image is Missing */
.error-icon-wrapper {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2;
    background-color: #f8fafc;
    color: #94a3b8;
    gap: 0.5rem;
}

.error-icon-wrapper svg {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}

.error-icon-wrapper span {
    font-size: 0.875rem;
}

.card-large .error-icon-wrapper svg {
    width: 64px;
    height: 64px;
}

.card-large .error-icon-wrapper span {
    font-size: 1rem;
}

/* ===================== QR Modal ===================== */
.qr-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 1.5rem;
}

.qr-modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.qr-modal-card {
    background: #ffffff;
    border-radius: 20px;
    max-width: 380px;
    width: 100%;
    padding: 2rem 1.75rem 1.75rem;
    position: relative;
    box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.25);
    transform: translateY(24px) scale(0.95);
    transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

.qr-modal-overlay.open .qr-modal-card {
    transform: translateY(0) scale(1);
}

/* Close button */
.qr-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #f1f5f9;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    z-index: 10;
}

.qr-modal-close:hover {
    background: #e2e8f0;
    color: #0f172a;
}

/* QR Image */
.qr-modal-image-box {
    width: 100%;
    max-width: 280px;
    aspect-ratio: 1;
    border-radius: 16px;
    overflow: hidden;
    background: #f8fafc;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-modal-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 6%;
}

/* Info area */
.qr-modal-info {
    text-align: center;
}

.qr-modal-name {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.15rem;
}

.qr-modal-dept {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Action buttons area */
.qr-modal-actions {
    display: flex;
    gap: 0.75rem;
    width: 100%;
}

.qr-modal-btn {
    flex: 1;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    border: none;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform 0.15s, box-shadow 0.15s;
    text-decoration: none;
    color: #ffffff;
}

.qr-modal-btn:active {
    transform: scale(0.97);
}

.qr-modal-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* WeChat green button */
.qr-modal-btn-wechat {
    background: linear-gradient(135deg, #07c160, #06ad56);
    box-shadow: 0 4px 14px rgba(7, 193, 96, 0.3);
}

.qr-modal-btn-wechat:hover {
    box-shadow: 0 6px 20px rgba(7, 193, 96, 0.4);
}

/* Save / download button */
.qr-modal-btn-save {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    box-shadow: 0 4px 14px rgba(29, 78, 216, 0.3);
}

.qr-modal-btn-save:hover {
    box-shadow: 0 6px 20px rgba(29, 78, 216, 0.4);
}

/* Hint text */
.qr-modal-hint {
    font-size: 0.8rem;
    color: #94a3b8;
    text-align: center;
    line-height: 1.5;
}

/* Responsive modal */
@media (max-width: 400px) {
    .qr-modal-card {
        padding: 1.5rem 1.25rem 1.25rem;
        border-radius: 16px;
    }

    .qr-modal-image-box {
        max-width: 240px;
    }

    .qr-modal-actions {
        flex-direction: column;
    }
}

/* Footer Section */
.footer {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
}

/* Media Query Responsive Adjusting */
@media (max-width: 1024px) {
    .sidebar {
        display: none;
    }

    .main-wrapper {
        margin-left: 0;
    }

    .mobile-header {
        display: flex;
    }

    html {
        scroll-padding-top: var(--mobile-header-height, 6rem);
    }
}

@media (max-width: 640px) {
    :root {
        --mobile-header-height: 6.35rem;
    }

    .mobile-header-top {
        padding: 0.65rem 0.75rem 0.5rem;
    }

    .mobile-header .logo {
        font-size: 1rem;
    }

    .mobile-header-subtitle {
        font-size: 0.7rem;
    }

    .mobile-nav-wrapper {
        padding: 0 0.5rem 0.6rem;
    }

    .mobile-nav {
        gap: 0.4rem;
        padding: 0.16rem;
    }

    .mobile-nav-item {
        font-size: 0.76rem;
        padding: 0.4rem 0.72rem;
    }

    .container {
        padding: 1rem 0.75rem;
    }

    .section-title {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }

    .section-title::before {
        height: 18px;
        width: 4px;
    }

    .grid {
        gap: 0.75rem;
        padding: 6px;
        margin: -6px;
    }

    .card-content {
        padding: 0.875rem 0.625rem;
    }

    .card-name {
        font-size: 0.9rem;
    }

    .card-subtitle {
        font-size: 0.7rem;
    }

    .card-large .card-name {
        font-size: 1.05rem;
    }

    .card-large .card-subtitle {
        font-size: 0.75rem;
    }

    .card-large .card-content {
        padding: 1rem 0.875rem;
    }

    .badge {
        top: 6px;
        right: 6px;
        padding: 0.2rem 0.5rem;
        font-size: 0.65rem;
    }

    .card-large .badge {
        top: 10px;
        right: 10px;
        padding: 0.3rem 0.75rem;
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    :root {
        --mobile-header-height: 6rem;
    }

    .mobile-header {
        box-shadow: 0 8px 20px -18px rgba(15, 23, 42, 0.4);
    }

    .mobile-nav-wrapper {
        padding: 0 0.4rem 0.5rem;
    }

    .card-large {
        grid-column: span 2;
    }
}