/* ===========================
   CSS Variables & Reset
   =========================== */
:root {
    --bg-primary: #0c1521;
    --bg-secondary: #111d2e;
    --bg-card: #14202f;
    --bg-card-hover: #182637;
    --bg-search: #14202f;
    --border-color: #1e3048;
    --border-color-light: #243a54;
    --text-primary: #e8edf3;
    --text-secondary: #8899aa;
    --text-muted: #56687a;
    --accent-blue: #3b82f6;
    --accent-blue-glow: rgba(59, 130, 246, 0.15);
    --accent-green: #22c55e;
    --accent-amber: #f59e0b;
    --accent-slate: #64748b;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.15);
    --shadow-card-hover: 0 4px 16px rgba(0, 0, 0, 0.35), 0 2px 4px rgba(0, 0, 0, 0.2);
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;

    /* Responsive spacing tokens */
    --container-padding: clamp(0.75rem, 3vw, 2rem);
    --container-max-width: min(640px, 100% - 2rem);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    /* Prevent horizontal overflow on any screen */
    overflow-x: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    /* Dynamic viewport height for mobile browsers */
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: var(--container-padding);
    padding-bottom: calc(var(--container-padding) + 1rem);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    /* Safe area for notched devices */
    padding-left: max(var(--container-padding), env(safe-area-inset-left));
    padding-right: max(var(--container-padding), env(safe-area-inset-right));
    padding-bottom: max(calc(var(--container-padding) + 1rem), env(safe-area-inset-bottom));
}

/* Subtle animated background */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 20%, rgba(59, 130, 246, 0.04) 0%, transparent 50%),
        radial-gradient(circle at 70% 80%, rgba(34, 197, 94, 0.03) 0%, transparent 50%);
    z-index: -1;
    animation: bgShift 20s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes bgShift {
    0% {
        transform: translate(0, 0);
    }

    100% {
        transform: translate(-5%, -3%);
    }
}

/* ===========================
   Portal Container
   =========================== */
.portal-container {
    width: 100%;
    max-width: var(--container-max-width);
    animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===========================
   Header
   =========================== */
.portal-header {
    text-align: center;
    padding: clamp(1rem, 4vw, 2rem) 0 clamp(0.75rem, 3vw, 1.5rem);
}

.portal-title {
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #ffffff 0%, #c8d6e5 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    word-break: break-word;
}

.portal-subtitle {
    font-size: clamp(0.8rem, 2.5vw, 0.95rem);
    font-weight: 400;
    color: var(--text-secondary);
    line-height: 1.5;
    padding: 0 0.5rem;
}

/* ===========================
   Search Bar
   =========================== */
.search-wrapper {
    margin-bottom: clamp(1.25rem, 4vw, 2rem);
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-search);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: clamp(0.65rem, 2vw, 0.875rem) clamp(0.875rem, 2.5vw, 1.25rem);
    transition: all var(--transition-normal);
    cursor: text;
}

.search-bar:focus-within {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--accent-blue-glow);
    background: var(--bg-card-hover);
}

.search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: color var(--transition-fast);
    width: 20px;
    height: 20px;
}

.search-bar:focus-within .search-icon {
    color: var(--accent-blue);
}

.search-bar input {
    flex: 1;
    min-width: 0;
    /* Prevent flex child from overflowing */
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: clamp(0.8rem, 2.5vw, 0.9rem);
    font-family: inherit;
    font-weight: 400;
    /* Prevent zoom on iOS when focusing input */
    -webkit-text-size-adjust: 100%;
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

/* ===========================
   Menu Sections
   =========================== */
.menu-sections {
    display: flex;
    flex-direction: column;
    gap: clamp(1.25rem, 4vw, 1.75rem);
}

.menu-section {
    animation: fadeInUp 0.5s ease-out both;
}

.menu-section:nth-child(1) {
    animation-delay: 0.1s;
}

.menu-section:nth-child(2) {
    animation-delay: 0.2s;
}

.menu-section:nth-child(3) {
    animation-delay: 0.3s;
}

.menu-section.hidden {
    display: none;
}

/* Section Header */
.section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-left: 0.25rem;
}

.section-icon {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    opacity: 0.85;
}

.section-title {
    font-size: clamp(0.65rem, 2vw, 0.75rem);
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* Menu Card Group */
.menu-card-group {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-card);
    box-shadow: var(--shadow-card);
}

/* Menu Card */
.menu-card {
    display: flex;
    align-items: center;
    gap: clamp(0.625rem, 2.5vw, 1rem);
    padding: clamp(0.75rem, 2.5vw, 1rem) clamp(0.875rem, 2.5vw, 1.25rem);
    text-decoration: none;
    color: var(--text-primary);
    transition: all var(--transition-fast);
    position: relative;
    /* Ensure touch targets are large enough */
    min-height: 48px;
}

.menu-card:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.menu-card:hover {
    background: var(--bg-card-hover);
}

.menu-card:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: -2px;
    background: var(--bg-card-hover);
}

.menu-card:active {
    transform: scale(0.995);
}

.menu-card.hidden {
    display: none;
}

/* Remove border-bottom if next sibling is hidden */
.menu-card:has(+ .menu-card.hidden):not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

/* Icon Badge */
.menu-card-icon {
    width: clamp(36px, 8vw, 42px);
    height: clamp(36px, 8vw, 42px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    transition: transform var(--transition-fast);
}

.menu-card-icon svg {
    width: clamp(18px, 4vw, 22px);
    height: clamp(18px, 4vw, 22px);
}

.menu-card:hover .menu-card-icon {
    transform: scale(1.08);
}

/* Label */
.menu-card-label {
    flex: 1;
    min-width: 0;
    /* Prevent text overflow */
    font-size: clamp(0.825rem, 2.5vw, 0.925rem);
    font-weight: 500;
    line-height: 1.4;
    word-break: break-word;
    overflow-wrap: break-word;
}

/* Arrow */
.menu-arrow {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: all var(--transition-fast);
    opacity: 0.5;
    width: 18px;
    height: 18px;
}

.menu-card:hover .menu-arrow {
    color: var(--accent-blue);
    opacity: 1;
    transform: translateX(3px);
}

/* ===========================
   No Results
   =========================== */
.no-results {
    text-align: center;
    padding: clamp(2rem, 6vw, 3rem) 1rem;
    color: var(--text-muted);
    animation: fadeInUp 0.4s ease-out;
}

.no-results svg {
    margin-bottom: 1rem;
    opacity: 0.4;
    width: clamp(36px, 8vw, 48px);
    height: clamp(36px, 8vw, 48px);
}

.no-results p {
    font-size: clamp(0.8rem, 2.5vw, 0.9rem);
    font-weight: 500;
}

/* ===========================
   Footer
   =========================== */
.portal-footer {
    margin-top: clamp(2rem, 5vw, 3rem);
    text-align: center;
    padding-bottom: 1rem;
    animation: fadeInUp 0.5s ease-out 0.4s both;
}

.footer-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-color-light), transparent);
    margin-bottom: 1.5rem;
}

.footer-brand {
    font-size: clamp(0.6rem, 1.8vw, 0.7rem);
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--accent-blue);
    margin-bottom: 0.375rem;
    text-transform: uppercase;
}

.footer-org {
    font-size: clamp(0.75rem, 2.2vw, 0.85rem);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    padding: 0 0.5rem;
    word-break: break-word;
}

.footer-updated {
    font-size: clamp(0.65rem, 1.8vw, 0.75rem);
    color: var(--text-muted);
    font-weight: 400;
}

/* ===========================
   Responsive: Ultra small (< 320px)
   =========================== */
@media (max-width: 319px) {
    .portal-header {
        padding: 0.75rem 0;
    }

    .menu-card {
        gap: 0.5rem;
        padding: 0.625rem 0.625rem;
    }

    .menu-card-icon {
        width: 32px;
        height: 32px;
    }

    .menu-card-icon svg {
        width: 16px;
        height: 16px;
    }

    .search-bar {
        gap: 0.5rem;
    }

    .menu-arrow {
        width: 14px;
        height: 14px;
    }
}

/* ===========================
   Responsive: Small phones (320px - 480px)
   =========================== */
@media (min-width: 320px) and (max-width: 480px) {
    .menu-card {
        padding: 0.75rem 0.875rem;
    }

    .menu-card-icon {
        width: 36px;
        height: 36px;
    }
}

/* ===========================
   Responsive: Tablets (481px - 768px)
   =========================== */
@media (min-width: 481px) and (max-width: 768px) {
    .portal-container {
        max-width: 580px;
    }
}

/* ===========================
   Responsive: Large tablets / small desktops (769px - 1024px)
   =========================== */
@media (min-width: 769px) and (max-width: 1024px) {
    .portal-container {
        max-width: 640px;
    }
}

/* ===========================
   Responsive: Desktops (1025px+)
   =========================== */
@media (min-width: 1025px) {
    body {
        padding-top: 3rem;
    }

    .portal-container {
        max-width: 640px;
    }
}

/* ===========================
   Responsive: Ultra wide (1440px+)
   =========================== */
@media (min-width: 1440px) {
    body {
        padding-top: 4rem;
    }
}

/* ===========================
   Landscape mode on phones
   =========================== */
@media (max-height: 500px) and (orientation: landscape) {
    .portal-header {
        padding: 0.5rem 0 0.75rem;
    }

    .search-wrapper {
        margin-bottom: 1rem;
    }

    .menu-sections {
        gap: 1rem;
    }

    .portal-footer {
        margin-top: 1.5rem;
    }
}

/* ===========================
   Print styles
   =========================== */
@media print {
    body {
        background: #fff;
        color: #000;
        padding: 1rem;
    }

    body::before {
        display: none;
    }

    .portal-title {
        background: none;
        -webkit-text-fill-color: #000;
        color: #000;
    }

    .portal-subtitle,
    .footer-org,
    .footer-updated,
    .menu-card-label {
        color: #333;
    }

    .search-wrapper {
        display: none;
    }

    .menu-card-group {
        border: 1px solid #ccc;
        box-shadow: none;
    }

    .menu-card {
        border-bottom: 1px solid #eee;
    }

    .section-title {
        color: #333 !important;
    }

    .footer-brand {
        color: #333;
    }

    .footer-divider {
        background: #ccc;
    }
}

/* ===========================
   Accessibility: Reduced motion
   =========================== */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    body::before {
        animation: none;
    }
}

/* ===========================
   Accessibility: High contrast
   =========================== */
@media (prefers-contrast: high) {
    :root {
        --border-color: #4a6a8a;
        --border-color-light: #5a7a9a;
        --text-secondary: #aabbcc;
        --text-muted: #7788aa;
    }

    .menu-card:focus-visible {
        outline-width: 3px;
    }
}

/* ===========================
   Animations
   =========================== */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* Smooth section show/hide transitions */
.menu-section {
    transition: opacity var(--transition-normal), transform var(--transition-normal);
}

.menu-section.fade-out {
    opacity: 0;
    transform: translateY(-8px);
}