/* The toolbar wraps below the brand as a whole when both do not fit on one row. */
header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px 32px;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

h1 {
    flex-shrink: 0;
    font-size: 1.8rem;
    line-height: 1.2;
    color: #2c3e50;
    white-space: nowrap;
}

h1 span {
    display: block;
    margin-top: 2px;
    font-size: 0.85rem;
    color: #7f8c8d;
    font-weight: normal;
}

.header-actions {
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 12px 24px;
}

.header-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

/* Page actions stay left, account actions are pushed right. */
.header-group:first-child:not(:last-child) {
    margin-right: auto;
}

/* Flex display on groups and buttons would otherwise override the hidden attribute. */
.header-actions [hidden] {
    display: none !important;
}

.hdr-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid #d0d5da;
    border-radius: 6px;
    background: #fff;
    color: #2c3e50;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.hdr-btn:hover:not(:disabled) {
    background: #f4f6f8;
    border-color: #b8c0c8;
}

.hdr-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.35);
}

.hdr-btn:disabled {
    color: #95a5a6;
    cursor: not-allowed;
    opacity: 0.7;
}

.hdr-btn--primary {
    background: #3498db;
    border-color: #3498db;
    color: #fff;
}

.hdr-btn--primary:hover:not(:disabled) {
    background: #2980b9;
    border-color: #2980b9;
}

.hdr-btn--danger {
    color: #c0392b;
}

.hdr-btn--danger:hover:not(:disabled) {
    background: #fdecea;
    border-color: #e74c3c;
}

.hdr-btn--telegram {
    color: #0088cc;
}

.hdr-btn--telegram:hover:not(:disabled) {
    background: #e8f4fb;
    border-color: #0088cc;
}

.hdr-btn--telegram.is-linked {
    color: #27ae60;
}

.hdr-btn--telegram.is-linked:hover:not(:disabled) {
    background: #eafaf1;
    border-color: #27ae60;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 200px;
    height: 36px;
    padding: 0 12px 0 4px;
    border-radius: 18px;
    background: #eef1f4;
    color: #2c3e50;
    font-size: 0.875rem;
    font-weight: 500;
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #2c3e50;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
}

.user-chip #user-display {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    header {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
        text-align: center;
    }

    h1 {
        font-size: 2rem;
        white-space: normal;
    }

    h1 span {
        font-size: 1rem;
        margin-top: 5px;
    }

    .header-actions {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .header-group {
        justify-content: center;
    }

    .header-group:first-child:not(:last-child) {
        margin-right: 0;
    }

    .hdr-btn {
        height: 44px;
        padding: 0 12px;
        font-size: 0.95rem;
    }

    .user-chip {
        height: 44px;
        border-radius: 22px;
        padding-left: 6px;
        font-size: 0.95rem;
    }

    .user-avatar {
        width: 32px;
        height: 32px;
    }
}
