.common-topbar-theme-root,
:root {
    --color-bg: #f7f8fa;
    --color-surface: #ffffff;
    --color-surface-alt: #f0f2f5;
    --color-text: #1f2937;
    --color-text-light: #6b7280;
    --color-border: #e5e7eb;

    --topbar-height: 48px;
    --topbar-bottom-offset: 0px;
    --topbar-bg: rgba(255,255,255,0.92);
    --topbar-border: rgba(229,231,235,0.9);
    --topbar-brand-bg: #ffffff;
    --topbar-action-bg: #f3f4f6;
    --topbar-action-bg-hover: #e5e7eb;
    --topbar-action-text: #111827;
    --topbar-avatar-bg: #111827;
    --topbar-avatar-text: #ffffff;
    --topbar-menu-bg: rgba(17,24,39,0.96);
    --topbar-menu-border: rgba(255,255,255,0.08);
    --topbar-menu-item-bg: rgba(255,255,255,0.06);
    --topbar-menu-item-bg-hover: rgba(255,255,255,0.18);
    --topbar-menu-text: #f9fafb;
    --topbar-menu-text-muted: rgba(255,255,255,0.78);
    --topbar-input-bg: rgba(255,255,255,0.96);
    --topbar-input-border: #d1d5db;
    --topbar-input-text: #111827;
    --topbar-panel-bg: #ffffff;
    --topbar-panel-border: #e5e7eb;
    --topbar-panel-muted: #6b7280;
}

:root[data-theme="dark"] {
    --color-bg: #0f1720;
    --color-surface: #16202b;
    --color-surface-alt: #101923;
    --color-text: #e5edf7;
    --color-text-light: #9fb0c3;
    --color-border: #283548;

    --topbar-bg: rgba(11,18,32,0.92);
    --topbar-border: rgba(159,176,195,0.18);
    --topbar-brand-bg: #111827;
    --topbar-action-bg: #1b2632;
    --topbar-action-bg-hover: #253346;
    --topbar-action-text: #e5edf7;
    --topbar-avatar-bg: #7c9cff;
    --topbar-avatar-text: #0f1720;
    --topbar-menu-bg: rgba(15,23,32,0.98);
    --topbar-menu-border: rgba(159,176,195,0.18);
    --topbar-menu-item-bg: rgba(159,176,195,0.1);
    --topbar-menu-item-bg-hover: rgba(124,156,255,0.18);
    --topbar-menu-text: #f8fafc;
    --topbar-menu-text-muted: rgba(229,237,247,0.76);
    --topbar-input-bg: #16202b;
    --topbar-input-border: #32455c;
    --topbar-input-text: #e5edf7;
    --topbar-panel-bg: #16202b;
    --topbar-panel-border: #283548;
    --topbar-panel-muted: #9fb0c3;
}

.common-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: var(--topbar-height, 56px);
    min-height: var(--topbar-height, 56px);
    background: rgba(255,255,255,0.92);
    border-bottom: 1px solid rgba(229,231,235,0.9);
    backdrop-filter: blur(8px);
    position: relative;
    z-index: 30;
    overflow: visible;
}

.common-topbar__left {
    display: flex;
    align-items: center;
    align-self: stretch;
    min-width: 0;
}

.common-topbar__brand-link {
    display: inline-flex;
    align-items: center;
    align-self: stretch;
    gap: 12px;
    height: 100%;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.common-topbar__brand {
    width: var(--topbar-height, 56px);
    height: var(--topbar-height, 56px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    background: #fff;
}

.common-topbar__brand-logo {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.common-topbar__brand-name {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    white-space: nowrap;
}

.common-topbar__search-input {
    flex: 1;
    min-width: 0;
    padding: 11px 14px;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    background: #fff;
    font-size: 14px;
}

.common-topbar__search-button,
.common-topbar__action,
.common-topbar__menu-item,
.common-topbar-modal__close {
    border: 0;
    margin: 0;
    background: #f3f4f6;
    color: #111827;
    border-radius: 0;
    padding: 10px 14px;
    font-size: 14px;
    cursor: pointer;
}

.common-topbar__search-button:hover,
.common-topbar__action:hover,
.common-topbar__menu-item:hover,
.common-topbar-modal__close:hover {
    background: #e5e7eb;
}

.common-topbar__visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.common-topbar__actions {
    display: flex;
    align-items: center;
    align-self: stretch;
    gap: 0;
    margin-left: auto;
    height: 100%;
}

.common-topbar__menu-wrap {
    position: static;
    display: flex;
    align-items: stretch;
    height: 100%;
}

.common-topbar__menu-wrap + .common-topbar__menu-wrap {
    border-left: 1px solid rgba(229,231,235,0.9);
}

.common-topbar__action--square {
    min-width: 86px;
    height: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 16px;
    background: transparent;
}

.common-topbar__action-label {
    white-space: nowrap;
}

.common-topbar__action-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    line-height: 1;
    flex: 0 0 22px;
}

.common-topbar__icon-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.common-topbar__profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.common-topbar__avatar {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #111827;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
}

.common-topbar__menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    width: auto;
    max-width: 100%;
    min-width: 0;
    max-height: calc(100dvh - var(--topbar-height, 56px) - var(--topbar-bottom-offset, 0px));
    display: none;
    flex-direction: column;
    gap: 6px;
    padding: 14px;
    background: rgba(17,24,39,0.96);
    border-top: 1px solid rgba(255,255,255,0.08);
    border-radius: 0;
    box-shadow: 0 18px 36px rgba(17,24,39,0.22);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
}

.common-topbar__menu--panel {
    width: auto;
}

.common-topbar__menu[data-topbar-menu="profile"] {
    left: auto;
    right: 0;
    width: min(860px, calc(100vw - 24px));
    padding: 18px;
    overflow-y: auto;
}

.common-topbar__menu.is-open {
    display: flex;
}

.common-topbar__menu-item {
    text-align: left;
    background: rgba(255,255,255,0.06);
    color: #f9fafb;
    border-radius: 0;
}

.common-topbar__menu--help {
    gap: 12px;
}

.common-topbar__help-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.common-topbar__help-title {
    font-weight: 700;
    font-size: 15px;
}

.common-topbar__help-description {
    font-size: 13px;
    line-height: 1.45;
    color: rgba(255,255,255,0.78);
}

.common-topbar__menu-item--danger {
    color: #fecaca;
}

.common-topbar__search-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.common-topbar__search-panel-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.7);
}

.common-topbar__search-panel-row {
    display: flex;
    gap: 8px;
}

.common-topbar__search-panel-hint {
    font-size: 12px;
    color: rgba(255,255,255,0.72);
}

.common-topbar__search-scopes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.common-topbar__search-scope-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.common-topbar__search-scope {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--topbar-menu-text, #f9fafb);
    font-size: 13px;
    line-height: 1.2;
    cursor: pointer;
}

.common-topbar__search-scope:hover {
    background: rgba(255,255,255,0.14);
}

.common-topbar__search-scope-input {
    margin: 0;
    accent-color: #ffffff;
}

.common-topbar__search-scope-label {
    white-space: nowrap;
}

.common-topbar__search-input {
    background: rgba(255,255,255,0.96);
}

.common-topbar__search-button {
    background: rgba(255,255,255,0.12);
    color: #fff;
}

.common-topbar__search-button:hover,
.common-topbar__menu-item:hover {
    background: rgba(255,255,255,0.18);
}

.common-topbar-profile-panel {
    display: grid;
    grid-template-columns: minmax(180px, 220px) minmax(220px, 1fr) minmax(180px, 220px);
    gap: 18px;
    align-items: stretch;
}

.common-topbar-profile-panel__section {
    min-width: 0;
}

.common-topbar-profile-card,
.common-topbar-profile-details,
.common-topbar-profile-actions {
    height: 100%;
    --generic-section-padding-block: 16px;
    --generic-section-padding-inline: 16px;
    --generic-section-border: var(--topbar-menu-border, rgba(255,255,255,0.08));
    --generic-section-background: var(--topbar-menu-item-bg, rgba(255,255,255,0.06));
    --generic-section-radius: 0px;
}

.common-topbar-profile-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}

.common-topbar-profile-card__photo,
.common-topbar-profile-card__placeholder {
    width: 96px;
    height: 96px;
    border-radius: 999px;
    object-fit: cover;
}

.common-topbar-profile-card__placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary, #2563eb);
    color: var(--color-text-inverse, #ffffff);
    font-size: 34px;
    font-weight: 700;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}

.common-topbar-profile-card__identity {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.common-topbar-profile-card__identity strong {
    font-size: 16px;
    color: var(--topbar-menu-text, #f9fafb);
}

.common-topbar-profile-card__identity span {
    color: var(--topbar-panel-muted, rgba(255,255,255,0.78));
    font-size: 13px;
    word-break: break-word;
}

.common-topbar-profile-details {
    display: grid;
    gap: 10px;
    align-content: start;
}

.common-topbar-profile-details__row {
    display: grid;
    gap: 4px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--topbar-panel-border, rgba(255,255,255,0.08));
}

.common-topbar-profile-details__row:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.common-topbar-profile-details__label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--topbar-panel-muted, rgba(255,255,255,0.78));
}

.common-topbar-profile-details__value {
    color: var(--topbar-menu-text, #f9fafb);
    word-break: break-word;
}

.common-topbar-profile-actions {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
}

.common-topbar-profile-actions__button {
    width: 100%;
    justify-content: center;
    text-align: center;
    padding: 12px 14px;
}

.common-topbar-modal[hidden] {
    display: none;
}

.common-topbar-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
}

.common-topbar-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17,24,39,0.42);
}

.common-topbar-modal__panel {
    position: relative;
    z-index: 1;
    width: min(920px, calc(100vw - 32px));
    max-height: calc(100dvh - 40px);
    margin: 20px auto;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(17,24,39,0.25);
    overflow: hidden;
}

.common-topbar-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
    border-bottom: 1px solid #e5e7eb;
}

.common-topbar-modal__header h3 {
    margin: 0;
    font-size: 18px;
}

.common-topbar-modal__close,
.common-topbar-drawer__close {
    border-radius: 999px;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 28px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.common-topbar-modal__body {
    padding: 18px;
    overflow: auto;
}

.common-topbar-modal__iframe {
    width: 100%;
    min-height: 70vh;
    border: 0;
}

.common-topbar-drawer[hidden] {
    display: none;
}

.common-topbar-drawer {
    position: fixed;
    inset: 0;
    z-index: 1250;
}

.common-topbar-drawer__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17,24,39,0.42);
}

.common-topbar-drawer__panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(1440px, 100vw);
    max-width: 100vw;
    display: flex;
    flex-direction: column;
    background: #fff;
    box-shadow: -18px 0 36px rgba(17,24,39,0.22);
}

.common-topbar-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
    border-bottom: 1px solid #e5e7eb;
}

.common-topbar-drawer__header h3 {
    margin: 0;
    font-size: 18px;
}

.common-topbar-drawer__close {
    border: 0;
    margin: 0;
    background: #f3f4f6;
    color: #111827;
    cursor: pointer;
}

.common-topbar-drawer__close:hover {
    background: #e5e7eb;
}

.common-topbar-drawer__body {
    flex: 1;
    min-height: 0;
    background: #fff;
}

.common-topbar__sticky-actions {
    position: sticky;
    bottom: -18px;
    z-index: 4;
    margin: 18px -18px -18px;
    padding: 14px 18px 18px;
    background: linear-gradient(180deg, rgba(255,255,255,0.82) 0%, rgba(255,255,255,0.96) 18%, #ffffff 100%);
    border-top: 1px solid #e5e7eb;
    backdrop-filter: blur(10px);
}

.common-topbar-drawer__body .common-topbar__sticky-actions {
    bottom: 0;
    margin-bottom: 0;
}

.common-topbar-drawer__iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

.common-help-list {
    display: grid;
    gap: 14px;
}

.common-help-card {
    padding: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    background: #f9fafb;
}

.common-help-card h4 {
    margin: 0 0 8px;
}

.common-help-card p {
    margin: 0;
    line-height: 1.5;
    color: #4b5563;
}

html[data-theme] .common-topbar {
    background: var(--topbar-bg);
    border-bottom-color: var(--topbar-border);
}

html[data-theme] .common-topbar__brand {
    background: var(--topbar-brand-bg);
}

html[data-theme] .common-topbar__menu-wrap + .common-topbar__menu-wrap {
    border-left-color: var(--topbar-border);
}

html[data-theme] .common-topbar__action,
html[data-theme] .common-topbar__search-button,
html[data-theme] .common-topbar__menu-item,
html[data-theme] .common-topbar-modal__close,
html[data-theme] .common-topbar-drawer__close {
    background: var(--topbar-action-bg);
    color: var(--topbar-action-text);
}

html[data-theme] .common-topbar__action--square {
    background: transparent;
    color: var(--topbar-action-text);
}

html[data-theme] .common-topbar__action:hover,
html[data-theme] .common-topbar__search-button:hover,
html[data-theme] .common-topbar-modal__close:hover,
html[data-theme] .common-topbar-drawer__close:hover {
    background: var(--topbar-action-bg-hover);
}

html[data-theme] .common-topbar__avatar {
    background: var(--topbar-avatar-bg);
    color: var(--topbar-avatar-text);
}

html[data-theme="dark"] .common-topbar__icon-image {
    filter: invert(1) brightness(1.25);
}

html[data-theme] .common-topbar__menu {
    background: var(--topbar-menu-bg);
    border-top-color: var(--topbar-menu-border);
}

html[data-theme] .common-topbar__menu[data-topbar-menu="profile"] {
    left: auto;
    right: 0;
    width: min(860px, calc(100vw - 24px));
    padding: 18px;
    max-height: calc(100dvh - var(--topbar-height) - var(--topbar-bottom-offset, 0px));
    overflow-y: auto;
}

html[data-theme] .common-topbar__menu-item {
    background: var(--topbar-menu-item-bg);
    color: var(--topbar-menu-text);
}

html[data-theme] .common-topbar__menu-item:hover {
    background: var(--topbar-menu-item-bg-hover);
}

html[data-theme] .common-topbar__help-description,
html[data-theme] .common-topbar__search-panel-label,
html[data-theme] .common-topbar__search-panel-hint {
    color: var(--topbar-menu-text-muted);
}

html[data-theme] .common-topbar__search-scope {
    background: var(--topbar-menu-item-bg);
    border-color: var(--topbar-menu-border);
    color: var(--topbar-menu-text);
}

html[data-theme] .common-topbar__search-scope:hover {
    background: var(--topbar-menu-item-bg-hover);
}

html[data-theme] .common-topbar__search-input {
    background: var(--topbar-input-bg);
    border-color: var(--topbar-input-border);
    color: var(--topbar-input-text);
}

html[data-theme] .common-topbar-modal__panel,
html[data-theme] .common-topbar-drawer__panel,
html[data-theme] .common-topbar-drawer__body {
    background: var(--topbar-panel-bg);
    color: var(--color-text);
}

html[data-theme] .common-topbar-modal__header,
html[data-theme] .common-topbar-drawer__header {
    border-bottom-color: var(--topbar-panel-border);
}

html[data-theme] .common-topbar__sticky-actions {
    background: linear-gradient(
        180deg,
        color-mix(in srgb, var(--topbar-panel-bg) 72%, transparent) 0%,
        color-mix(in srgb, var(--topbar-panel-bg) 92%, transparent) 18%,
        var(--topbar-panel-bg) 100%
    );
    border-top-color: var(--topbar-panel-border);
}

html[data-theme] .common-help-card {
    background: var(--color-surface-alt);
    border-color: var(--color-border);
}

html[data-theme] .common-help-card p {
    color: var(--color-text-light);
}

@media (max-width: 860px) {
    .common-topbar {
        gap: 8px;
    }

    .common-topbar__brand-link {
        gap: 0;
    }

    .common-topbar__brand-name {
        display: none;
    }

    .common-topbar__action--square {
        min-width: calc(var(--topbar-height, 56px) - 2px);
        padding: 0 10px;
    }

    .common-topbar__action-label {
        display: none;
    }

    .common-topbar__search-panel-row {
        flex-direction: column;
    }

    .common-topbar__menu {
        left: 0;
        right: 0;
        width: auto;
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .common-topbar__help-item {
        gap: 0;
    }

    .common-topbar__help-description {
        display: none;
    }

    .common-topbar__menu[data-topbar-menu="profile"] {
        left: 0;
        right: 0;
        width: auto;
        padding: 12px;
    }

    .common-topbar-profile-panel {
        grid-template-columns: 1fr;
    }

    .common-topbar-profile-actions {
        justify-content: flex-start;
    }

    .common-topbar-drawer__panel {
        width: 100vw;
    }
}

@media (min-width: 861px) {
    .common-topbar__menu--help {
        display: none;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-items: stretch;
    }

    .common-topbar__menu--help.is-open {
        display: grid;
    }

    .common-topbar__help-item {
        min-height: 148px;
        justify-content: flex-start;
        padding: 16px;
    }
}
