
/* =========================================
   ATHERIOT RESPONSIVE HEADER
========================================= */

.app-header {
    --header-h: clamp(52px, 10vw, 66px);
    --control-h: clamp(32px, 7vw, 44px);
    --gap: clamp(6px, 1.5vw, 14px);
    --pad: clamp(10px, 2.5vw, 18px);
    --gutter: 20px;
    --dur: 180ms;

    --accent-2: color-mix(
        in srgb,
        var(--primary) 60%,
        var(--success)
    );
}

/* =========================================
   HEADER SHELL
========================================= */

header.app-header {
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + 8px);
    z-index: 100;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: var(--gap);

    width: min(
        calc(100% - var(--gutter) * 2),
        var(--content-width, 1200px)
    );

    min-height: var(--header-h);
    margin: 12px auto 0;
    padding: 0 var(--pad);

    box-sizing: border-box;

    color: var(--text);

    background: color-mix(
        in srgb,
        var(--surface) 78%,
        transparent
    );

    -webkit-backdrop-filter:
        saturate(160%) blur(16px);

    backdrop-filter:
        saturate(160%) blur(16px);

    border: 1px solid var(--border);
    border-radius: var(--radius, 14px);
    box-shadow: var(--shadow);
}

/* =========================================
   LEFT AND RIGHT GROUPS
========================================= */

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: var(--gap);
    min-width: 0;
}

.header-left {
    flex: 0 0 auto;
    justify-content: flex-start;
}

.header-right {
    flex: 0 1 auto;
    justify-content: flex-end;
    margin-left: auto;
}

/* =========================================
   NINE DOTS BUTTON
========================================= */

.services-wrapper {
    position: relative;
    flex-shrink: 0;
}

.nine-dots {
    display: grid;
    grid-template-columns: repeat(3, 4px);
    grid-template-rows: repeat(3, 4px);
    place-content: center;
    gap: 3px;

    width: var(--control-h);
    height: var(--control-h);
    padding: 0;

    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius, 12px);

    cursor: pointer;

    transition:
        background var(--dur),
        transform var(--dur);
}

.nine-dots span {
    display: block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--heading);
}

.nine-dots:hover {
    background: var(--nav-hover);
}

.nine-dots:active {
    transform: scale(0.94);
}

/* =========================================
   BRAND LOGO
========================================= */

.brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;
    height: var(--control-h);

    text-decoration: none;
    border-radius: var(--radius, 12px);
}

.brand img {
    display: block;
    width: auto;
    height: clamp(24px, 6vw, 36px);
    max-width: 110px;
    object-fit: contain;
}

/* =========================================
   TOTAL EXPENSE
========================================= */

.header-expense {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;

    flex: 0 1 auto;
    min-width: 0;
    min-height: var(--control-h);

    padding: 4px clamp(8px, 2vw, 16px);

    box-sizing: border-box;
    overflow: hidden;

    border: 1px solid color-mix(
        in srgb,
        var(--primary) 30%,
        var(--border)
    );

    border-radius: var(--radius, 12px);

    background: linear-gradient(
        120deg,
        color-mix(
            in srgb,
            var(--primary) 16%,
            transparent
        ),
        color-mix(
            in srgb,
            var(--accent-2) 12%,
            transparent
        )
    ), var(--surface);

    box-shadow:
        inset 3px 0 0 var(--success),
        var(--shadow);
}

.header-expense span,
.header-expense strong {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-expense span {
    font-size: clamp(0.55rem, 1.7vw, 0.72rem);
    font-weight: 500;
    line-height: 1.3;
    color: var(--muted);
}

.header-expense strong {
    font-size: clamp(0.75rem, 2.6vw, 1.05rem);
    font-weight: 700;
    line-height: 1.3;
    color: var(--heading);
    font-variant-numeric: tabular-nums;
}

/* =========================================
   ACCOUNT BUTTON
========================================= */

.header-account {
    display: grid;
    place-items: center;

    flex: 0 0 var(--control-h);

    width: var(--control-h);
    height: var(--control-h);
    padding: 0;

    color: var(--surface);
    background: linear-gradient(
        135deg,
        var(--primary),
        var(--accent-2)
    );

    border: none;
    border-radius: 50%;
    box-shadow: var(--shadow);

    cursor: pointer;

    transition: transform var(--dur);
}

.header-account i {
    font-size: clamp(13px, 3vw, 18px);
}

.header-account:hover {
    transform: translateY(-1px);
}

.header-account:active {
    transform: scale(0.94);
}

/* =========================================
   KEYBOARD ACCESSIBILITY
========================================= */

.nine-dots:focus-visible,
.brand:focus-visible,
.header-account:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

/* =========================================
   SERVICES POPUP POSITION
========================================= */

.services-popup {
    position: absolute;
    top: calc(100% + 12px);
    left: 0;
    z-index: 200;

    width: min(320px, calc(100vw - 24px));
    max-height: min(70vh, 520px);
    overflow-y: auto;

    box-sizing: border-box;

    background: var(--surface);
    color: var(--text);

    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.services-popup[hidden] {
    display: none !important;
}

/* =========================================
   TABLET
========================================= */

@media (max-width: 768px) {
    .app-header {
        --gutter: 14px;
        --pad: 12px;
        --gap: 8px;
    }
}

/* =========================================
   MOBILE
========================================= */

@media (max-width: 480px) {
    .app-header {
        --gutter: 12px;
        --pad: 10px;
        --gap: 6px;
        --control-h: 34px;
        --header-h: 54px;
    }

    .brand img {
        height: 28px;
        max-width: 70px;
    }

    .header-expense {
        padding: 4px 8px;
    }

    .header-expense span {
        font-size: 0.58rem;
    }

    .header-expense strong {
        font-size: 0.78rem;
    }
}

/* =========================================
   SMALL MOBILE
========================================= */

@media (max-width: 320px) {
    .app-header {
        --gutter: 8px;
        --pad: 6px;
        --gap: 4px;
        --control-h: 30px;
    }

    .brand img {
        height: 24px;
        max-width: 45px;
    }

    .header-expense {
        padding: 3px 5px;
    }

    .header-expense span {
        font-size: 0.5rem;
    }

    .header-expense strong {
        font-size: 0.68rem;
    }
}

/* =========================================
   VERY NARROW SCREENS
========================================= */

@media (max-width: 220px) {
    header.app-header {
        flex-wrap: wrap;
        height: auto;
        padding-block: 6px;
        row-gap: 6px;
    }

    .header-left,
    .header-right {
        width: 100%;
        justify-content: space-between;
    }

    .header-right {
        margin-left: 0;
    }
}

/* =========================================
   REDUCED MOTION
========================================= */

@media (prefers-reduced-motion: reduce) {
    .app-header *,
    .app-header *::before,
    .app-header *::after {
        transition: none !important;
        animation: none !important;
    }
}

/* =========================================
   HIGH CONTRAST
========================================= */

@media (prefers-contrast: more) {
    header.app-header,
    .header-expense {
        border-color: var(--text);
    }
}

/* =========================================
   FORCED COLORS
========================================= */

@media (forced-colors: active) {
    header.app-header,
    .header-expense,
    .header-account {
        border: 1px solid CanvasText;
        box-shadow: none;
    }
}





/* =========================================
   LOGO + NINE DOTS SPACING
========================================= */

.header-left {
    display: flex;
    align-items: center;
    justify-content: flex-start;

    gap: clamp(12px, 2.5vw, 24px);

    flex-shrink: 0;
    min-width: 0;
}

/* Logo */
.header-left .brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;
}

/* Nine dots */
.header-left .services-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* Tablet */
@media (max-width: 768px) {
    .header-left {
        gap: 16px;
    }
}

/* Mobile */
@media (max-width: 480px) {
    .header-left {
        gap: 12px;
    }
}

/* Small mobile */
@media (max-width: 320px) {
    .header-left {
        gap: 8px;
    }
}

/* =========================================
   RIGHT SIDE SPACING
========================================= */

.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;

    gap: clamp(12px, 2.5vw, 24px);

    margin-left: auto;
    min-width: 0;
}

/* Tablet */
@media (max-width: 768px) {
    .header-right {
        gap: 16px;
    }
}

/* Mobile */
@media (max-width: 480px) {
    .header-right {
        gap: 12px;
    }
}

/* Small Mobile */
@media (max-width: 320px) {
    .header-right {
        gap: 8px;
    }
}
