/* Site-aligned chrome: Inter, sky blue, white header, rounded frames */

.icon {
    display: inline-flex;
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
}

.icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* ===== HEADER — like site navbar ===== */
.main-header {
    background: rgba(255, 255, 255, 0.96);
    color: var(--secondary-color);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
    border-bottom: 1px solid var(--border-color);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    color: var(--primary-dark);
    flex-shrink: 0;
    min-width: 0;
}

.header-brand img {
    height: 56px;
    width: 56px;
    object-fit: contain;
    filter: none;
}

.header-brand img[src=""],
.header-brand img:not([src]) {
    display: none;
}

.header-brand-name {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: 1.45rem;
    letter-spacing: 0.3px;
    line-height: 1.1;
    white-space: nowrap;
}

.header-brand:hover {
    color: var(--primary-color);
}

.header-content h1 {
    color: var(--secondary-color);
    font-weight: 700;
    font-size: 1.05rem;
}

.header-content .subtitle {
    color: var(--text-light);
    opacity: 1;
}

.header-content .subtitle #headerVersion {
    color: var(--primary-dark);
}

.header-back-btn {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    border: none;
    border-radius: var(--radius-full);
    color: #fff;
    font-weight: 600;
    padding: 0.45rem 1rem;
    box-shadow: 0 4px 12px rgba(60, 180, 229, 0.28);
}

.header-back-btn:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
    border-color: transparent;
    color: #fff;
}

.header-search {
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
}

.header-search:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(60, 180, 229, 0.18);
}

.header-search input {
    color: var(--text-color);
}

.header-search input::placeholder {
    color: var(--text-light);
}

.header-search button {
    color: var(--primary-color);
}

.mobile-menu-btn,
.mobile-library-btn {
    background: var(--primary-lighter);
    color: var(--secondary-color);
    border-radius: var(--radius-md);
}

.mobile-menu-btn:hover,
.mobile-library-btn:hover {
    background: #d7eef8;
    color: var(--primary-dark);
}

/* ===== SIDEBAR / LIBRARY HEADERS ===== */
.nav-header,
.library-header,
.search-modal-header {
    background: var(--bg-light);
    color: var(--secondary-color);
    border-bottom: 2px solid var(--primary-color);
}

.nav-header h2,
.library-header h3,
.search-modal-header h3 {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--secondary-color);
    font-weight: 700;
}

.nav-close-btn,
.library-close-btn,
.nav-collapse-btn,
.library-collapse-btn,
.search-modal-close {
    color: var(--secondary-color);
}

.nav-close-btn:hover,
.library-close-btn:hover,
.nav-collapse-btn:hover,
.library-collapse-btn:hover,
.search-modal-close:hover {
    background: var(--primary-lighter);
    color: var(--primary-dark);
}

.sidebar-nav,
.library-sidebar {
    scrollbar-color: var(--primary-color) transparent;
    background: var(--bg-color);
}

/* ===== NAV ITEMS ===== */
.nav-item.welcome-item > a {
    background-color: var(--primary-lighter);
    border-left-color: var(--primary-color);
    color: var(--secondary-color);
}

.nav-item.module-item > a {
    border-left-color: var(--primary-color);
    color: var(--secondary-color);
}

.nav-item.module-item.expanded > a {
    border-left-color: var(--primary-dark);
    background-color: var(--primary-lighter);
}

.nav-item.active > a,
.nav-item.topic-item.completed.active > a,
.nav-item.section-topic-item.completed.active > a,
.nav-item.topic-item.pending.active > a,
.nav-item.section-topic-item.pending.active > a {
    background-color: var(--primary-lighter) !important;
    color: var(--secondary-color) !important;
    border-left-color: var(--primary-color);
}

.nav-item.active > a .nav-icon {
    color: var(--primary-dark);
}

.nav-item.topic-item.completed.active > a,
.nav-item.section-topic-item.completed.active > a {
    font-weight: 600 !important;
}

.category-title:hover {
    background-color: var(--primary-lighter);
}

.library-category {
    border-radius: var(--radius-lg);
}

.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.85rem;
}

.module-card {
    min-width: 0;
    padding: 0.9rem 1rem;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

/* ===== CONTENT FRAMES ===== */
.content-article {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

.content-article h1,
.welcome-screen h2,
.topic-content h1 {
    color: var(--secondary-color);
    border-bottom: 3px solid var(--primary-color);
}

.content-article h2,
.welcome-screen h3,
.topic-content h2 {
    color: var(--secondary-color);
}

.content-article table th {
    background-color: var(--secondary-color);
}

.content-article blockquote {
    border-left-color: var(--primary-color);
}

.info-box {
    background-color: var(--primary-lighter);
    border-left-color: var(--primary-color);
    border-radius: var(--radius-md);
}

.features {
    border-left-color: var(--primary-color);
    border-radius: var(--radius-lg);
}

.topic-content .exam-box {
    background: #fffaf0;
    border: 1px solid #f3d7a3;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.lesson-figure {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    background: #fff;
}

.lesson-figure .figure-title {
    color: var(--secondary-color);
}

.lesson-figure img {
    border-bottom: 1px solid var(--border-color);
}

.btn-document {
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    box-shadow: 0 4px 12px rgba(60, 180, 229, 0.28);
}

.btn-document:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
}

.breadcrumbs {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.search-modal-content {
    border-radius: var(--radius-xl);
}

.search-result-title {
    color: var(--secondary-color);
}

/* ===== FOOTER ===== */
.textbook-attribution {
    margin-top: 2.5rem;
    padding: 1.25rem 1.4rem;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-left: 4px solid var(--secondary-color, #1a365d);
    border-radius: 0 0.75rem 0.75rem 0;
}

.textbook-attribution h2 {
    margin: 0 0 0.75rem;
    font-size: 1.05rem;
    color: var(--secondary-color, #1a365d);
}

.textbook-attribution h3 {
    margin: 1.1rem 0 0.45rem;
    font-size: 0.95rem;
    color: var(--secondary-color, #1a365d);
}

.textbook-attribution p,
.textbook-attribution li {
    font-size: 0.9rem;
    line-height: 1.6;
    color: #334155;
}

.textbook-attribution ul {
    margin: 0.6rem 0 0;
    padding-left: 1.2rem;
}

.textbook-attribution li + li {
    margin-top: 0.25rem;
}

.main-footer {
    background-color: var(--bg-dark);
    color: #d1d5db;
    min-height: auto;
    padding: 0.85rem 1.5rem;
}

.footer-legal {
    font-size: 0.82rem;
    line-height: 1.45;
    margin: 0 0 0.35rem;
}

.footer-content p,
.footer-content p:first-child,
.footer-version,
.footer-contact,
.footer-description,
.footer-legal {
    color: #d1d5db;
}

.footer-contact a {
    color: var(--primary-color);
}

.footer-contact a:hover {
    color: var(--primary-light);
}

/* ===== MOBILE BOTTOM NAV ===== */
.mobile-bottom-nav {
    border-top: 1px solid var(--border-color);
}

.mobile-nav-item.active {
    color: var(--primary-dark);
    background: var(--primary-lighter);
}

.mobile-nav-item .nav-icon {
    color: inherit;
    width: 1.5rem;
    height: 1.5rem;
    font-size: inherit;
}

.mobile-nav-item .nav-icon svg {
    width: 1.5rem;
    height: 1.5rem;
}

/* ===== PWA install ===== */
.pwa-install-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
    padding: 0.35rem 0.7rem;
    border: none;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    color: #fff;
    font-weight: 600;
    font-size: 0.82rem;
    box-shadow: 0 4px 12px rgba(60, 180, 229, 0.28);
    -webkit-tap-highlight-color: transparent;
}

.pwa-install-btn[hidden] {
    display: none !important;
}

.pwa-install-btn .icon {
    width: 1.15rem;
    height: 1.15rem;
}

.pwa-install-hint {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    z-index: 1400;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: #fff;
    color: var(--secondary-color);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
}

.pwa-install-hint[hidden] {
    display: none !important;
}

.pwa-install-hint p {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.45;
}

.pwa-install-hint button {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 999px;
    background: var(--bg-light);
    color: var(--secondary-color);
    font-size: 1rem;
}

html.is-standalone .pwa-install-btn,
html.is-standalone .pwa-install-hint {
    display: none !important;
}

/* Phone + tablet + short landscape: never use the desktop 3-column grid */
@media (max-width: 1400px), (max-height: 600px) {
    :root {
        --header-height: calc(56px + env(safe-area-inset-top, 0px));
        --sidebar-width: min(92vw, 400px);
        --library-width: min(92vw, 400px);
    }

    .app-container {
        grid-template-columns: 1fr !important;
        grid-template-rows: var(--header-height) 1fr auto !important;
        grid-template-areas:
            "header"
            "main"
            "footer" !important;
    }

    .main-header {
        height: var(--header-height);
        padding-top: env(safe-area-inset-top, 0px);
        padding-left: max(0.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
        gap: 0.4rem;
        overflow: hidden;
    }

    .mobile-menu-btn,
    .mobile-library-btn {
        display: flex !important;
        flex-shrink: 0;
        min-width: 44px;
        min-height: 44px;
        z-index: 1102;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .header-brand-name,
    .header-back-btn,
    .header-content .subtitle,
    .pwa-install-label {
        display: none !important;
    }

    .header-search {
        display: none;
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        z-index: 1250;
        margin: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        background: #fff;
        padding: 0.55rem 0.75rem;
        box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
    }

    html.search-open .header-search {
        display: flex !important;
    }

    .header-brand img {
        height: 36px;
        width: 36px;
    }

    .header-content {
        min-width: 0;
        flex: 1;
        overflow: hidden;
    }

    .header-content h1 {
        font-size: 0.92rem;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .horizontal-submenu {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        min-height: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
        pointer-events: none !important;
    }

    .sidebar-nav,
    .library-sidebar {
        visibility: visible !important;
        z-index: 1200 !important;
        top: var(--header-height) !important;
        width: min(92vw, 400px) !important;
        max-width: 400px !important;
        height: calc(100dvh - var(--header-height) - 64px - env(safe-area-inset-bottom, 0px)) !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    }

    .sidebar-nav,
    .sidebar-nav.collapsed {
        left: 0 !important;
        right: auto !important;
        transform: translateX(-105%) !important;
    }

    .sidebar-nav.open,
    .sidebar-nav.open.collapsed {
        transform: translateX(0) !important;
        left: 0 !important;
    }

    .library-sidebar,
    .library-sidebar.collapsed {
        right: 0 !important;
        left: auto !important;
        transform: translateX(105%) !important;
    }

    .library-sidebar.open,
    .library-sidebar.open.collapsed {
        transform: translateX(0) !important;
        right: 0 !important;
    }

    .nav-item.has-children.expanded > .nav-submenu {
        display: block !important;
    }

    .nav-item > a {
        min-height: 48px;
        transform: none !important;
    }

    .mobile-overlay {
        top: var(--header-height);
        z-index: 1150;
    }

    .mobile-bottom-nav {
        display: block !important;
        bottom: 0 !important;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
        z-index: 1300 !important;
    }

    .main-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding-top: calc(var(--header-height) + 0.75rem) !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .content-wrapper,
    .content-article,
    .topic-content,
    .welcome-page {
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: hidden;
    }

    .content-article h1,
    .content-article h2,
    .welcome-page h1,
    .welcome-page h2,
    .topic-content h1,
    .topic-content h2 {
        overflow-wrap: anywhere;
        word-break: break-word;
        max-width: 100%;
    }

    .content-article img,
    .topic-content img,
    .lesson-figure img {
        max-width: 100%;
        height: auto;
    }

    .content-article table,
    .topic-content table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .images-gallery,
    .modules-grid {
        grid-template-columns: 1fr !important;
    }

    .module-card {
        min-width: 0;
    }

    .main-footer {
        display: none !important;
    }

    html.search-open .main-content {
        padding-top: calc(var(--header-height) + 3.4rem) !important;
    }
}

@media (min-width: 768px) and (max-width: 1400px) {
    .header-content h1 {
        font-size: 1.05rem;
    }

    .pwa-install-label {
        display: inline !important;
    }

    .images-gallery,
    .modules-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}
