/**
 * Daily Dictation - Public Header
 * Path: public/assets/css/layout/header.css
 *
 * Goals:
 * - Server-rendered, crawlable navigation
 * - Clear desktop and mobile interaction
 * - Accessible focus states
 * - Stable layout with minimal CLS
 * - No CSS imports and no inline styles
 */

/* ==========================================================================
   Header tokens
   ========================================================================== */

.site-header {
    --header-ink: #12213f;
    --header-muted: #64748b;
    --header-line: #dce6f5;
    --header-surface: #ffffff;
    --header-surface-soft: #f7faff;
    --header-brand: #2563eb;
    --header-brand-dark: #1748c7;
    --header-nav: #123b82;
    --header-nav-hover: rgba(255, 255, 255, 0.12);
    --header-focus: rgba(37, 99, 235, 0.22);
    --header-shadow: 0 12px 32px rgba(20, 48, 96, 0.12);

    position: sticky;
    top: 0;
    z-index: 1030;
    width: 100%;
    background: var(--header-surface);
    border-top: 4px solid var(--header-brand);
    border-bottom: 1px solid var(--header-line);
    box-shadow: var(--header-shadow);
}

.site-header *,
.site-header *::before,
.site-header *::after {
    box-sizing: border-box;
}

/* ==========================================================================
   Top area
   ========================================================================== */

.site-header__top {
    background: linear-gradient(
        135deg,
        #f8fbff 0%,
        #eef5ff 58%,
        #f8fbff 100%
    );
}

.site-header__top-inner {
    min-height: 84px;
    display: grid;
    grid-template-columns: auto minmax(280px, 540px) auto;
    align-items: center;
    gap: 1.5rem;
}

/* ==========================================================================
   Brand
   ========================================================================== */

.site-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.8rem;
    min-width: max-content;
    color: var(--header-ink);
    text-decoration: none;
}

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

.site-brand:focus-visible {
    outline: 3px solid var(--header-focus);
    outline-offset: 4px;
    border-radius: 10px;
}

.site-brand__mark {
    width: 68px;
    height: 68px;
    flex: 0 0 54px;
    object-fit: contain;
    filter: drop-shadow(0 8px 12px rgba(37, 99, 235, 0.18));
}

.site-brand__text {
    display: flex;
    flex-direction: column;
    line-height: 1;
}

.site-brand__text strong {
    color: #173b87;
    font-size: 1.5rem;
    letter-spacing: 0.1em;
    white-space: nowrap;
}

.site-brand__text small {
    margin-top: 0.42rem;
    color: var(--header-muted);
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

/* ==========================================================================
   Search
   ========================================================================== */

.site-search {
    height: 48px;
    display: flex;
    align-items: center;
    overflow: hidden;
    border: 2px solid #cbd9ee;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 8px 22px rgba(23, 58, 116, 0.08);
    transition:
        border-color 0.18s ease,
        box-shadow 0.18s ease;
}

.site-search:focus-within {
    border-color: #6c98f2;
    box-shadow:
        0 0 0 4px rgba(37, 99, 235, 0.12),
        0 10px 25px rgba(23, 58, 116, 0.1);
}

.site-search__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding-left: 1rem;
    color: #71809a;
}

.site-search__input {
    min-width: 0;
    flex: 1;
    height: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    padding: 0 0.8rem;
    color: var(--header-ink);
}

.site-search__input::placeholder {
    color: #8a97aa;
}

.site-search__button {
    align-self: stretch;
    border: 0;
    padding: 0 1.25rem;
    background: linear-gradient(135deg, #2f6fed, #1f56cf);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
}

.site-search__button:hover {
    background: var(--header-brand-dark);
}

.site-search__button:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.8);
    outline-offset: -4px;
}

.site-header__search-panel {
    display: none;
    padding: 0 0 0.8rem;
    background: var(--header-surface-soft);
}

.site-header__search-panel.is-open {
    display: block;
}

.site-search--mobile {
    width: 100%;
}

/* ==========================================================================
   Header actions
   ========================================================================== */

.site-header__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.65rem;
    white-space: nowrap;
}

.site-login,
.site-register {
    min-height: 43px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    padding: 0 1rem;
    font-weight: 800;
    text-decoration: none;
    transition:
        color 0.16s ease,
        background-color 0.16s ease,
        border-color 0.16s ease,
        transform 0.16s ease;
}

.site-login {
    border: 1px solid #cdd8ea;
    background: #fff;
    color: var(--header-ink);
}

.site-login:hover {
    border-color: #86a9ee;
    color: var(--header-brand);
}

.site-register {
    border: 1px solid var(--header-brand);
    background: linear-gradient(135deg, #3477f3, #1d55ce);
    color: #fff;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
}

.site-register:hover {
    color: #fff;
    transform: translateY(-1px);
}

.site-login:focus-visible,
.site-register:focus-visible,
.site-search-toggle:focus-visible,
.site-menu-toggle:focus-visible,
.site-account__trigger:focus-visible {
    outline: 3px solid var(--header-focus);
    outline-offset: 3px;
}

.site-search-toggle,
.site-menu-toggle {
    display: none;
    width: 43px;
    height: 43px;
    align-items: center;
    justify-content: center;
    border: 1px solid #cdd8ea;
    border-radius: 11px;
    background: #fff;
    color: var(--header-ink);
    cursor: pointer;
}

.site-menu-toggle {
    flex-direction: column;
    gap: 4px;
}

.site-menu-toggle span {
    width: 19px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}

/* ==========================================================================
   Account menu
   ========================================================================== */

.site-account {
    position: relative;
}

.site-account__trigger {
    min-height: 43px;
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    border: 1px solid #cdd8ea;
    border-radius: 11px;
    background: #fff;
    padding: 0.25rem 0.75rem;
    color: var(--header-ink);
    font-weight: 700;
    cursor: pointer;
}

.site-account__avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 50%;
    object-fit: cover;
}

.site-account__avatar--fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #dbe8ff;
    color: #1748c7;
    font-weight: 800;
}

.site-account__caret {
    font-size: 0.75rem;
    transition: transform 0.16s ease;
}

.site-account.is-open .site-account__caret {
    transform: rotate(180deg);
}

.site-account__menu {
    position: absolute;
    top: calc(100% + 0.55rem);
    right: 0;
    z-index: 1100;
    display: none;
    min-width: 210px;
    padding: 0.45rem;
    border: 1px solid var(--header-line);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 18px 42px rgba(12, 29, 58, 0.2);
}

.site-account.is-open .site-account__menu,
.site-account__menu.is-open {
    display: block;
}

.site-account__menu a {
    display: flex;
    align-items: center;
    min-height: 42px;
    border-radius: 8px;
    padding: 0.65rem 0.8rem;
    color: var(--header-ink);
    font-weight: 700;
    text-decoration: none;
}

.site-account__menu a:hover,
.site-account__menu a:focus-visible {
    background: #edf4ff;
    color: var(--header-brand-dark);
    outline: none;
}

/* ==========================================================================
   Primary navigation
   ========================================================================== */

.site-nav {
    border-top: 1px solid #dfe8f5;
    background: var(--header-nav);
}

.site-nav__collapse {
    display: block;
}

.site-nav__list {
    min-height: 54px;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 0.15rem;
    list-style: none;
}

.site-nav__item {
    position: relative;
    display: flex;
    align-items: stretch;
}

.site-nav__item > a,
.site-nav__dropdown-trigger {
    min-height: 54px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border: 0;
    padding: 0 0.9rem;
    background: transparent;
    color: rgba(255, 255, 255, 0.92);
    font-size: 0.94rem;
    font-weight: 750;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition:
        color 0.16s ease,
        background-color 0.16s ease;
}

.site-nav__item > a:hover,
.site-nav__dropdown-trigger:hover,
.site-nav__item > a:focus-visible,
.site-nav__dropdown-trigger:focus-visible {
    background: var(--header-nav-hover);
    color: #fff;
    outline: none;
}

.site-nav__item > a:focus-visible,
.site-nav__dropdown-trigger:focus-visible {
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.62);
}

.site-nav__item > a.is-active,
.site-nav__dropdown.is-active > .site-nav__dropdown-trigger {
    color: #fff;
    box-shadow: inset 0 -4px 0 #70d6ff;
}

.site-nav__premium {
    color: #ffd166 !important;
}

.site-nav__badge {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    border-radius: 999px;
    padding: 0.1rem 0.45rem;
    background: #fff;
    color: #1748c7;
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1;
}

.site-nav__caret {
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    transition: transform 0.16s ease;
}

.site-nav__dropdown.is-open .site-nav__caret {
    transform: rotate(225deg) translate(-1px, -1px);
}

/* ==========================================================================
   Dropdowns and mega menu
   ========================================================================== */

.site-nav__dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1080;
    display: none;
    min-width: 240px;
    padding: 0.55rem;
    border: 1px solid var(--header-line);
    border-radius: 0 0 13px 13px;
    background: #fff;
    box-shadow: 0 20px 44px rgba(12, 29, 58, 0.22);
}

.site-nav__dropdown:last-child .site-nav__dropdown-menu {
    right: 0;
    left: auto;
}

.site-nav__dropdown.is-open > .site-nav__dropdown-menu,
.site-nav__dropdown-menu.is-open {
    display: block;
}

.site-nav__dropdown-list {
    display: grid;
    gap: 0.2rem;
}

.site-nav__dropdown-link {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
    color: var(--header-ink);
    font-weight: 700;
    text-decoration: none;
}

.site-nav__dropdown-link:hover,
.site-nav__dropdown-link:focus-visible,
.site-nav__dropdown-link.is-active {
    background: #edf4ff;
    color: var(--header-brand-dark);
    outline: none;
}

.site-nav__dropdown-menu--mega {
    width: min(620px, calc(100vw - 2rem));
    padding: 1rem;
}

.site-nav__dropdown-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.site-nav__dropdown-group {
    min-width: 0;
}

.site-nav__dropdown-group h3 {
    margin: 0 0 0.45rem;
    padding: 0 0.35rem 0.5rem;
    border-bottom: 1px solid #e7eef8;
    color: #173b87;
    font-size: 0.86rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

/* Desktop progressive enhancement:
   hover opens the menu, while JS click support remains available. */
@media (min-width: 992px) {
    .site-nav__dropdown:hover > .site-nav__dropdown-menu,
    .site-nav__dropdown:focus-within > .site-nav__dropdown-menu {
        display: block;
    }
}

/* ==========================================================================
   Mobile account area
   ========================================================================== */

.site-nav__mobile-account {
    display: none;
}

/* ==========================================================================
   Responsive: medium desktop
   ========================================================================== */

@media (max-width: 1199.98px) {
    .site-header__top-inner {
        grid-template-columns: auto minmax(220px, 1fr) auto;
        gap: 1rem;
    }

    .site-brand__text small {
        display: none;
    }

    .site-nav__item > a,
    .site-nav__dropdown-trigger {
        padding-inline: 0.68rem;
        font-size: 0.89rem;
    }
}

/* ==========================================================================
   Responsive: tablet and mobile navigation
   ========================================================================== */

@media (max-width: 991.98px) {
    .site-header {
        position: sticky;
    }

    .site-header__top-inner {
        min-height: 72px;
        grid-template-columns: auto 1fr auto;
    }

    .site-header__top-inner > .site-search {
        display: none;
    }

    .site-search-toggle,
    .site-menu-toggle {
        display: inline-flex;
    }

    .site-nav__collapse {
        display: none;
    }

    .site-nav__collapse.is-open,
    .site-nav__collapse.show {
        display: block;
    }

    .site-nav__list {
        min-height: 0;
        padding: 0.7rem 0;
        align-items: stretch;
        flex-direction: column;
        gap: 0.15rem;
    }

    .site-nav__item {
        display: block;
    }

    .site-nav__item > a,
    .site-nav__dropdown-trigger {
        width: 100%;
        min-height: 46px;
        justify-content: space-between;
        border-radius: 9px;
        padding: 0.7rem 0.85rem;
        text-align: left;
    }

    .site-nav__item > a.is-active,
    .site-nav__dropdown.is-active > .site-nav__dropdown-trigger {
        box-shadow: none;
        background: rgba(255, 255, 255, 0.13);
    }

    .site-nav__dropdown-menu {
        position: static;
        display: none;
        width: 100%;
        min-width: 0;
        margin: 0.2rem 0 0.35rem;
        padding: 0.5rem;
        border: 0;
        border-radius: 10px;
        box-shadow: none;
    }

    .site-nav__dropdown.is-open > .site-nav__dropdown-menu,
    .site-nav__dropdown-menu.is-open {
        display: block;
    }

    .site-nav__dropdown-menu--mega {
        width: 100%;
    }

    .site-nav__dropdown-grid {
        grid-template-columns: 1fr;
        gap: 0.65rem;
    }

    .site-nav__dropdown-group h3 {
        margin-top: 0.25rem;
    }

    .site-nav__dropdown-link {
        min-height: 44px;
    }

    .site-account {
        display: none;
    }
}

/* ==========================================================================
   Responsive: small mobile
   ========================================================================== */

@media (max-width: 767.98px) {
    .site-header__top-inner {
        min-height: 66px;
        gap: 0.55rem;
    }

    .site-brand__mark {
        width: 44px;
        height: 44px;
        flex-basis: 44px;
    }

    .site-brand__text strong {
        font-size: 1.03rem;
        letter-spacing: 0.06em;
    }

    .site-brand__text small {
        display: none;
    }

    .site-search-toggle,
    .site-menu-toggle {
        width: 40px;
        height: 40px;
    }

    .site-nav__mobile-account {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.65rem;
        padding: 0 0 0.85rem;
    }

    .site-nav__mobile-account > a {
        min-height: 42px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 1px solid rgba(255, 255, 255, 0.28);
        border-radius: 10px;
        padding: 0.55rem;
        color: #fff;
        font-weight: 700;
        text-decoration: none;
        text-align: center;
    }

    .site-nav__mobile-account > a:hover,
    .site-nav__mobile-account > a:focus-visible {
        background: rgba(255, 255, 255, 0.12);
        outline: none;
    }

    .site-nav__mobile-account .site-register {
        border-color: #4f85ef;
        background: #2563eb;
        box-shadow: none;
    }
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .site-header *,
    .site-header *::before,
    .site-header *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
/* ========================================================================== 
   Mobile interaction fixes
   ========================================================================== */

/* Search icon fallback: remains visible even when Bootstrap Icons has not loaded. */
.site-search__icon .bi-search,
.site-search-toggle .bi-search {
    position: relative;
    display: inline-block;
    width: 1.15rem;
    height: 1.15rem;
    flex: 0 0 1.15rem;
    font-size: 0;
    line-height: 1;
}

.site-search__icon .bi-search::before,
.site-search-toggle .bi-search::before {
    content: "";
    position: absolute;
    top: 0.06rem;
    left: 0.06rem;
    width: 0.7rem;
    height: 0.7rem;
    border: 2px solid currentColor;
    border-radius: 50%;
}

.site-search__icon .bi-search::after,
.site-search-toggle .bi-search::after {
    content: "";
    position: absolute;
    top: 0.78rem;
    left: 0.77rem;
    width: 0.43rem;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    transform: rotate(45deg);
    transform-origin: left center;
}

.site-menu-toggle span {
    transition:
        transform 0.18s ease,
        opacity 0.18s ease;
}

.site-menu-toggle.is-open span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}

.site-menu-toggle.is-open span:nth-child(2) {
    opacity: 0;
}

.site-menu-toggle.is-open span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

@media (max-width: 991.98px) {
    .site-nav__collapse.is-open,
    .site-nav__collapse.show {
        display: block;
    }

    .site-nav__dropdown-trigger .site-nav__caret {
        margin-left: auto;
    }
}
