/* ==========================================
   ACADEMIC PORTFOLIO GLOBAL STYLESHEET
   Refined Institutional design system
   ========================================== */

/* --- Design Tokens --- */
:root {
    --primary-color: #0F172A;
    --accent-color: #0284C7;
    --link-color: #0284C7;
    --bg-color: #F8FAFC;
    --card-bg: #FFFFFF;
    --hero-bg: #E0F2FE;
    --hero-border: #BAE6FD;
    --text-color: #0F172A;
    --text-muted: #475569;
    --border-color: #CBD5E1;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 10px -2px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 28px -6px rgba(15, 23, 42, 0.16);
    --card-shadow: var(--shadow-md); /* legacy alias */

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-pill: 999px;
    --border-radius: var(--radius-md); /* legacy alias */

    --space-xs: 0.4rem;
    --space-sm: 0.75rem;
    --space-md: 1.25rem;
    --space-lg: 2rem;
    --space-xl: 3rem;

    --font-heading: 'Merriweather', 'Georgia', serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* --- Dynamic Theme Color Palettes (Admin Controlled, legacy body-class support) --- */
body.theme-oxford {
    --primary-color: #0F172A;
    --accent-color: #0284C7;
    --hero-bg: #E0F2FE;
    --hero-border: #BAE6FD;
}

body.theme-harvard {
    --primary-color: #A51C30;
    --accent-color: #D97706;
    --hero-bg: #FEF3C7;
    --hero-border: #FDE68A;
}

body.theme-forest {
    --primary-color: #14532D;
    --accent-color: #059669;
    --hero-bg: #DCFCE7;
    --hero-border: #BBF7D0;
}

body.theme-slate {
    --primary-color: #334155;
    --accent-color: #0EA5E9;
    --hero-bg: #E0F2FE;
    --hero-border: #BAE6FD;
}

/* ==========================================
   NIGHT / DARK MODE DIRECT OVERRIDES
   ========================================== */
body.mode-dark {
    --bg-color: #0F172A !important;
    --card-bg: #1E293B !important;
    --hero-bg: #1E293B !important;
    --hero-border: #334155 !important;
    --text-color: #F8FAFC !important;
    --text-muted: #94A3B8 !important;
    --link-color: #38BDF8 !important;
    --border-color: #334155 !important;
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.45);
}

/* Base App Container Overrides in Dark Mode */
body.mode-dark .stApp,
body.mode-dark [data-testid="stSidebar"],
body.mode-dark [data-testid="stHeader"] {
    background-color: var(--bg-color) !important;
    color: var(--text-color) !important;
}

body.mode-dark p,
body.mode-dark h1,
body.mode-dark h2,
body.mode-dark h3,
body.mode-dark h4,
body.mode-dark h5,
body.mode-dark h6,
body.mode-dark span,
body.mode-dark label,
body.mode-dark [data-testid="stMarkdownContainer"] p {
    color: var(--text-color) !important;
}

/* Hyperlinks in Light and Dark Mode */
a, a:visited {
    color: var(--link-color) !important;
    font-weight: 500;
}

body.mode-dark a,
body.mode-dark a:visited {
    color: #38BDF8 !important;
}

/* ==========================================
   BUTTONS & FORM SUBMIT BUTTONS
   ========================================== */
.stButton > button,
.stDownloadButton > button,
.stFormSubmitButton > button,
[data-testid="stFormSubmitButton"] > button {
    border-radius: var(--radius-sm) !important;
    font-weight: 600 !important;
    transition: all 0.15s ease !important;
}

.stButton > button:hover:not(:disabled),
.stDownloadButton > button:hover,
.stFormSubmitButton > button:hover,
[data-testid="stFormSubmitButton"] > button:hover {
    border-color: var(--accent-color) !important;
    color: var(--accent-color) !important;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

body.mode-dark .stButton > button,
body.mode-dark .stDownloadButton > button,
body.mode-dark .stFormSubmitButton > button,
body.mode-dark [data-testid="stFormSubmitButton"] > button {
    background-color: #334155 !important;
    color: #F8FAFC !important;
    border: 1px solid #475569 !important;
    font-weight: 600 !important;
}

body.mode-dark .stButton > button p,
body.mode-dark .stDownloadButton > button p,
body.mode-dark .stFormSubmitButton > button p,
body.mode-dark [data-testid="stFormSubmitButton"] > button p {
    color: #F8FAFC !important;
}

body.mode-dark .stButton > button:not(:disabled):hover,
body.mode-dark .stDownloadButton > button:hover,
body.mode-dark .stFormSubmitButton > button:hover,
body.mode-dark [data-testid="stFormSubmitButton"] > button:hover {
    background-color: var(--accent-color) !important;
    color: #FFFFFF !important;
    border-color: var(--accent-color) !important;
}

body.mode-dark .stButton > button:not(:disabled):hover *,
body.mode-dark .stDownloadButton > button:hover p,
body.mode-dark .stFormSubmitButton > button:hover p,
[data-testid="stFormSubmitButton"] > button:hover p {
    color: #FFFFFF !important;
}

body.mode-dark .stButton > button:disabled {
    background-color: #1E293B !important;
    border-color: #334155 !important;
    opacity: 0.5;
    cursor: not-allowed;
}

body.mode-dark .stButton > button:disabled * {
    color: #64748B !important;
}

/* --- Multiselect & Inputs Fix (Dark Mode) --- */
body.mode-dark [data-baseweb="select"] > div {
    background-color: #1E293B !important;
    border-color: #334155 !important;
}

body.mode-dark [data-baseweb="tag"] {
    background-color: var(--accent-color) !important;
}

body.mode-dark [data-baseweb="tag"] span {
    color: #FFFFFF !important;
}

body.mode-dark input,
body.mode-dark select,
body.mode-dark textarea,
body.mode-dark [data-baseweb="input"] {
    background-color: #1E293B !important;
    color: #F8FAFC !important;
    border-color: #334155 !important;
}

/* ==========================================
   PROFILE HERO BANNER (Single HTML Grid Card)
   ========================================== */
.profile-hero-banner {
    position: relative;
    background-color: var(--hero-bg) !important;
    border: 1px solid var(--hero-border) !important;
    border-radius: var(--radius-lg);
    padding: 2.25rem 2rem 2rem;
    margin-bottom: var(--space-lg);
    box-shadow: var(--shadow-lg);
    display: grid;
    grid-template-columns: 200px 1fr 280px;
    gap: var(--space-lg);
    align-items: center;
    overflow: hidden;
}

/* Thin gradient accent strip along the top edge */
.profile-hero-banner::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
}

.hero-avatar-col {
    display: flex;
    justify-content: center;
    align-items: center;
}

.hero-bio-col {
    display: flex;
    flex-direction: column;
}

.hero-contact-col {
    border-left: 1px solid var(--border-color);
    padding-left: 1.5rem;
}

/* Profile Avatar & Initial Placeholder */
.profile-avatar-placeholder {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #FFFFFF !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
    font-weight: bold;
    border: 3px solid var(--card-bg);
    box-shadow: 0 0 0 3px var(--accent-color), var(--shadow-lg);
}

.profile-avatar-img {
    width: 180px !important;
    height: 180px !important;
    max-width: 180px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    border: 3px solid var(--card-bg);
    box-shadow: 0 0 0 3px var(--accent-color), var(--shadow-lg);
}

/* Hero contact link chips (Scholar / GitHub / LinkedIn) */
.hero-link-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.hero-link-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.85rem;
    font-size: 0.82rem;
    font-weight: 600;
    background-color: var(--card-bg) !important;
    color: var(--text-color) !important;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    text-decoration: none !important;
    transition: all 0.15s ease;
}

.hero-link-chip:hover {
    background-color: var(--accent-color) !important;
    color: #FFFFFF !important;
    border-color: var(--accent-color) !important;
    transform: translateY(-1px);
}

/* Custom HTML VCF Download Button inside Banner */
.hero-vcf-btn {
    display: block;
    width: 100%;
    text-align: center;
    background-color: var(--card-bg) !important;
    color: var(--text-color) !important;
    border: 1px solid var(--border-color) !important;
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-decoration: none !important;
    transition: all 0.2s ease;
}

.hero-vcf-btn:hover {
    background-color: var(--accent-color) !important;
    color: #FFFFFF !important;
    border-color: var(--accent-color) !important;
}

body.mode-dark .hero-vcf-btn {
    background-color: #334155 !important;
    color: #F8FAFC !important;
    border-color: #475569 !important;
}

body.mode-dark .hero-link-chip {
    background-color: #334155 !important;
    color: #F8FAFC !important;
    border-color: #475569 !important;
}

/* ==========================================
   ACADEMIC CARDS & BADGES
   ========================================== */
.academic-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-left: 4px solid transparent;
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-sm);
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.academic-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.65rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    border-radius: var(--radius-pill);
    border: 1px solid transparent;
    margin-right: 0.3rem;
    margin-top: 0.3rem;
    text-transform: uppercase;
}

.badge-peer {
    background-color: var(--card-bg);
    color: var(--text-color) !important;
    border-color: var(--border-color);
}

.badge-sci {
    background-color: #DCFCE7;
    color: #15803D !important;
    border-color: rgba(21, 128, 61, 0.25);
}

.badge-scopus {
    background-color: #E0F2FE;
    color: #0369A1 !important;
    border-color: rgba(3, 105, 161, 0.25);
}

.badge-ongoing {
    background-color: #FEF3C7;
    color: #B45309 !important;
    border-color: rgba(180, 83, 9, 0.25);
}

.badge-completed {
    background-color: #DCFCE7;
    color: #15803D !important;
    border-color: rgba(21, 128, 61, 0.25);
}

/* High-Contrast Badges in Dark Mode */
body.mode-dark .badge-sci {
    background-color: #14532D !important;
    color: #86EFAC !important;
    border-color: rgba(134, 239, 172, 0.25);
}

body.mode-dark .badge-scopus {
    background-color: #0C4A6E !important;
    color: #7DD3FC !important;
    border-color: rgba(125, 211, 252, 0.25);
}

body.mode-dark .badge-ongoing {
    background-color: #78350F !important;
    color: #FDE68A !important;
    border-color: rgba(253, 230, 138, 0.25);
}

body.mode-dark .badge-completed {
    background-color: #14532D !important;
    color: #86EFAC !important;
    border-color: rgba(134, 239, 172, 0.25);
}

/* Metric / Stat Tile Styles */
.grant-metric-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.grant-metric-value {
    font-size: 2.1rem;
    font-weight: 700;
    font-family: var(--font-heading);
    color: var(--text-color);
    margin-top: 0.3rem;
}

body.mode-dark .grant-metric-title {
    color: #94A3B8 !important;
}

body.mode-dark .grant-metric-value {
    color: #38BDF8 !important;
}

/* Hide Default Streamlit Menu & Footer (Keep Header Toggle Visible) */
#MainMenu, footer {
    visibility: hidden;
}

/* ==========================================
   SECTION HEADINGS (st.subheader)
   ========================================== */
[data-testid="stMarkdownContainer"] h3 {
    font-family: var(--font-heading);
    font-weight: 700;
    padding-bottom: 0.6rem;
    margin-bottom: 1.1rem;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

[data-testid="stMarkdownContainer"] h3::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -1px;
    width: 44px;
    height: 3px;
    background: var(--accent-color);
    border-radius: var(--radius-pill);
}

/* ==========================================
   TABS
   ========================================== */
[data-testid="stTabs"] button[role="tab"] {
    font-family: var(--font-body);
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.85rem 1.35rem;
}

[data-testid="stTabs"] button[aria-selected="true"] {
    color: var(--accent-color) !important;
}

[data-testid="stTabs"] [data-baseweb="tab-highlight"] {
    background-color: var(--accent-color) !important;
    height: 3px !important;
}

[data-testid="stTabs"] [data-baseweb="tab-border"] {
    background-color: var(--border-color) !important;
}

/* ==========================================
   MOBILE & RESPONSIVE LAYOUT (Media Queries)
   ========================================== */
@media screen and (max-width: 900px) {
    .profile-hero-banner {
        grid-template-columns: 1fr;
        gap: var(--space-md);
        padding: 1.5rem 1.25rem 1.25rem;
    }

    .hero-contact-col {
        border-left: none;
        border-top: 1px solid var(--border-color);
        padding-left: 0;
        padding-top: 1rem;
    }

    .profile-avatar-placeholder,
    .profile-avatar-img {
        width: 130px !important;
        height: 130px !important;
        max-width: 130px !important;
        font-size: 2.8rem;
    }
}

/* ==========================================
   EXPERIENCE & QUALIFICATIONS STYLING
   ========================================== */

/* Desktop Default: Vertical Separator Line */
.bio-vertical-separator {
    width: 2px;
    background: linear-gradient(180deg, rgba(37, 99, 235, 0.1) 0%, var(--accent-color) 50%, rgba(37, 99, 235, 0.1) 100%);
    height: 100%;
    min-height: 380px;
    margin: 0 auto;
    border-radius: 2px;
}

/* Mobile Viewport Override (< 768px): Convert to Horizontal Divider */
@media screen and (max-width: 768px) {
    .bio-vertical-separator {
        width: 100% !important;
        height: 2px !important;
        min-height: 2px !important;
        margin: 1.5rem 0 !important;
        background: linear-gradient(90deg, rgba(37, 99, 235, 0.1) 0%, var(--accent-color) 50%, rgba(37, 99, 235, 0.1) 100%) !important;
    }
}

/* Dark Mode Support for Separator */
body.mode-dark .bio-vertical-separator {
    background: linear-gradient(180deg, rgba(56, 189, 248, 0.1) 0%, #38BDF8 50%, rgba(56, 189, 248, 0.1) 100%);
}

@media screen and (max-width: 768px) {
    body.mode-dark .bio-vertical-separator {
        background: linear-gradient(90deg, rgba(56, 189, 248, 0.1) 0%, #38BDF8 50%, rgba(56, 189, 248, 0.1) 100%) !important;
    }
}

/* ==========================================
   CARD ACCENT COLOR CODING (border-left only — no pastel fills)
   ========================================== */

/* Experience */
.academic-card.experience-card { border-left-color: #475569; }
body.mode-dark .academic-card.experience-card { border-left-color: #94A3B8; }

/* Qualifications */
.academic-card.qualification-card { border-left-color: #0284C7; }
body.mode-dark .academic-card.qualification-card { border-left-color: #38BDF8; }

/* Awards */
.academic-card.award-card { border-left-color: #D97706; }
body.mode-dark .academic-card.award-card { border-left-color: #F59E0B; }

/* PhD Scholars */
.academic-card.scholar-phd-card { border-left-color: #0284C7; }
body.mode-dark .academic-card.scholar-phd-card { border-left-color: #0EA5E9; }

/* M.Tech Scholars */
.academic-card.scholar-mtech-card { border-left-color: #1E293B; }
body.mode-dark .academic-card.scholar-mtech-card { border-left-color: #38BDF8; }

/* SCI / Scopus Indexed Publications */
.academic-card.pub-sci-card { border-left-color: #059669; }
body.mode-dark .academic-card.pub-sci-card { border-left-color: #10B981; }

/* Peer-Reviewed / Other Publications */
.academic-card.pub-other-card { border-left-color: #475569; }
body.mode-dark .academic-card.pub-other-card { border-left-color: #94A3B8; }

.academic-card.pub-card {
    margin-bottom: var(--space-sm);
}

/* ==========================================
   RERUN / PAGE-LOAD LOADING INDICATOR
   Full-page dim overlay with a centered rotating gear, shown for any kind
   of rerun (widget interaction, page/tab navigation, fragment updates,
   form submits, etc.) — driven purely by Streamlit's own [data-stale]
   attribute, so no per-element dim/flicker is needed anymore.
   ========================================== */
[data-testid="stElementContainer"][data-stale="true"] {
    opacity: 1 !important;
    transition: none !important;
}

/* Replaced by the full-page overlay below */
[data-testid="stStatusWidget"] {
    display: none !important;
}

/* Dim background, shown whenever anything on the page is stale/refreshing */
body:has([data-testid="stElementContainer"][data-stale="true"])::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 9998;
}

/* Centered rotating gear on top of the dim overlay */
body:has([data-testid="stElementContainer"][data-stale="true"])::after {
    content: "⚙️";
    position: fixed;
    top: 50%;
    left: 50%;
    font-size: 4rem;
    line-height: 1;
    z-index: 9999;
    animation: gear-spin-centered 1.1s linear infinite;
}

@keyframes gear-spin-centered {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ==========================================
   PAGINATION CONTRAST FIX (dark mode)
   ========================================== */
body.mode-dark .stButton > button,
body.mode-dark .stButton > button * {
    color: #F8FAFC !important;
}

body.mode-dark .stButton > button:not(:disabled):hover {
    background-color: #2563EB !important;
    border-color: #38BDF8 !important;
    color: #FFFFFF !important;
}

body.mode-dark .stButton > button:not(:disabled):hover * {
    color: #FFFFFF !important;
}

body.mode-dark .stButton > button:disabled {
    background-color: #1E293B !important;
    border-color: #334155 !important;
    opacity: 0.5;
    cursor: not-allowed;
}

body.mode-dark .stButton > button:disabled * {
    color: #64748B !important;
}
