.auth-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    background: transparent;
}

.auth-shell::after {
    content: "SAF+";
    position: absolute;
    top: clamp(22px, 4vw, 52px);
    left: clamp(22px, 4vw, 52px);
    z-index: 4;
    display: grid;
    width: 58px;
    height: 58px;
    place-items: center;
    border: 1px solid var(--saf-color-glass-border);
    border-radius: 20px;
    background: var(--saf-color-glass);
    color: var(--md-sys-color-primary);
    box-shadow: var(--elevation-2);
    font-weight: var(--font-weight-bold);
    letter-spacing: -0.04em;
    backdrop-filter: blur(18px) saturate(1.2);
    -webkit-backdrop-filter: blur(18px) saturate(1.2);
    pointer-events: none;
}

.content-panel {
    flex: 1;
    display: grid;
    width: 100%;
    min-width: 0;
    align-items: center;
    justify-items: center;
    padding: clamp(var(--space-5), 4vw, 64px) clamp(var(--space-5), 4vw, 64px) var(--space-5);
    position: relative;
    z-index: 1;
}

.content-panel::before {
    content: "";
    position: absolute;
    width: min(630px, 72vw);
    height: min(500px, 58vh);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 34px;
    background: var(--saf-color-background-panel);
    opacity: 0.72;
    transform: translate(68px, 18px) rotate(16deg);
    box-shadow: var(--elevation-2);
    pointer-events: none;
}

.flow-card,
.login-card,
.state-box {
    width: min(610px, 100%);
    margin: 0 auto;
    z-index: 1;
}

.selection-flow-card {
    width: min(calc(100vw - 96px), 1680px);
    max-width: 100%;
}

.selection-flow-card-compact {
    width: min(680px, calc(100vw - 32px));
}

.selection-flow-card-medium {
    width: min(760px, calc(100vw - 48px));
}

.selection-flow-card-large {
    width: min(1240px, calc(100vw - 72px));
}

.selection-flow-card-wide {
    width: min(1680px, calc(100vw - 96px));
}

.app-shell {
    min-height: 100vh;
    background: var(--md-sys-color-background);
    display: flex;
    flex-direction: column;
}

.dashboard-shell {
    display: grid;
    grid-template-columns: 348px minmax(0, 1fr);
    align-items: stretch;
    transition: grid-template-columns var(--motion-normal) var(--easing-standard);
}

.dashboard-shell.drawer-collapsed {
    grid-template-columns: 96px minmax(0, 1fr);
}

.workspace-shell {
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    min-height: 74px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 0 clamp(var(--space-4), 4vw, var(--space-8));
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    background: var(--saf-color-topbar);
    box-shadow: var(--elevation-1);
    backdrop-filter: blur(22px) saturate(1.25);
    -webkit-backdrop-filter: blur(22px) saturate(1.25);
}

.drawer-toggle {
    display: none;
    min-height: 40px;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 16px;
    padding: 0 var(--space-3);
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
    font-weight: var(--font-weight-bold);
}

.topbar-brand,
.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.topbar-context {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.topbar-context-divider {
    width: 1px;
    height: 32px;
    background: var(--md-sys-color-outline-variant);
}

.topbar-module {
    display: grid;
    min-width: 0;
    gap: 1px;
}

.topbar-module strong {
    color: var(--md-sys-color-on-surface);
    font-size: 0.94rem;
    font-weight: var(--font-weight-semibold);
    line-height: 1.1;
}

.topbar-module small {
    max-width: min(42vw, 520px);
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.72rem;
    font-weight: var(--font-weight-medium);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-inline {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    color: var(--md-sys-color-on-surface);
    font-weight: var(--font-weight-bold);
    letter-spacing: -0.02em;
}

.brand-inline::before {
    content: "SAF+";
    display: inline-grid;
    width: 48px;
    height: 40px;
    place-items: center;
    border-radius: 16px;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    box-shadow: var(--elevation-1);
    font-size: 0.76rem;
    letter-spacing: -0.03em;
}

.tenant-inline,
.access-pill {
    display: inline-flex;
    min-height: 64px;
    align-items: center;
    gap: 10px;
    max-width: 42vw;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.82rem;
    font-weight: var(--font-weight-semibold);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tenant-logo {
    width: 60px;
    height: 60px;
    max-width: 60px;
    max-height: 60px;
    flex: 0 0 60px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 999px;
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-primary);
    font-size: 0.72rem;
    font-weight: var(--font-weight-bold);
    line-height: 1;
}

.tenant-logo.loaded {
    background: var(--md-sys-color-surface);
}

.tenant-logo img {
    width: 100%;
    height: 100%;
    max-width: 60px;
    max-height: 60px;
    display: block;
    object-fit: cover;
}

.tenant-inline > span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.access-pill {
    padding: 0 var(--space-3);
    min-height: 34px;
    border: 1px solid transparent;
    border-radius: var(--shape-pill);
    color: var(--md-sys-color-success);
    background: var(--saf-color-success-container);
    border-color: transparent;
}

.main-content {
    flex: 1;
    padding: clamp(var(--space-5), 4vw, var(--space-12));
}

.workspace-shell:has(.invoice-workspace) {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}

.workspace-shell:has(.invoice-workspace) .main-content {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    overflow: hidden;
    padding: clamp(8px, 1.4vw, 16px);
}

.workspace-shell:has(.invoice-workspace) .app-footer {
    display: none;
}

@media (max-width: 760px), (max-height: 640px) {
    .workspace-shell:has(.invoice-workspace) {
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }

    .workspace-shell:has(.invoice-workspace) .main-content {
        overflow: auto;
        align-items: flex-start;
    }
}

.app-drawer {
    position: sticky;
    top: 0;
    z-index: 8;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    border-right: 1px solid var(--md-sys-color-outline-variant);
    background: var(--saf-color-topbar);
    padding: var(--space-5);
    box-shadow: var(--elevation-1);
    overflow-y: auto;
    overflow-x: hidden;
    backdrop-filter: blur(22px) saturate(1.2);
    -webkit-backdrop-filter: blur(22px) saturate(1.2);
    transition:
        padding var(--motion-normal) var(--easing-standard),
        gap var(--motion-normal) var(--easing-standard);
}

.app-drawer.collapsed {
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-5) var(--space-3);
}

.drawer-header,
.drawer-home,
.drawer-footer-note {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.drawer-header {
    justify-content: space-between;
    width: 100%;
}

.drawer-home strong,
.drawer-home small {
    display: block;
}

.drawer-home strong {
    color: var(--md-sys-color-on-surface);
    letter-spacing: -0.02em;
}

.drawer-home small {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.82rem;
}

.drawer-home-text {
    min-width: 0;
}

.drawer-logo {
    display: grid;
    width: 54px;
    height: 46px;
    place-items: center;
    border-radius: 18px;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    box-shadow: var(--elevation-1);
    font-weight: var(--font-weight-bold);
    font-size: 0.78rem;
    letter-spacing: -0.03em;
    flex: 0 0 auto;
}

.drawer-close {
    display: none;
    width: 38px;
    height: 38px;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 16px;
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
    font-weight: var(--font-weight-bold);
}

.drawer-collapse {
    display: inline-flex;
    min-width: 74px;
    height: 40px;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 16px;
    background: var(--saf-color-topbar);
    color: var(--md-sys-color-on-surface);
    box-shadow: var(--elevation-1);
    cursor: pointer;
    font-weight: var(--font-weight-bold);
    font-size: 0.78rem;
    transition:
        transform var(--motion-fast) var(--easing-standard),
        background-color var(--motion-fast) var(--easing-standard);
}

.drawer-collapse:hover {
    background: var(--saf-color-card-hover);
}

.drawer-lock-icon {
    font-size: 1rem;
    line-height: 1;
}

.drawer-lock-text {
    font-size: 0.72rem;
}

.drawer-context {
    display: grid;
    gap: var(--space-1);
    padding: var(--space-4);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 22px;
    background: var(--md-sys-color-surface);
}

.drawer-context.profile-card {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-3);
}

.profile-avatar {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 999px;
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-primary);
    font-size: 0.86rem;
    font-weight: var(--font-weight-bold);
    cursor: pointer;
}

.profile-card-copy {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.profile-card-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.profile-edit-button {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 12px;
    background: var(--saf-color-topbar);
    color: var(--md-sys-color-primary);
    cursor: pointer;
}

.profile-edit-button:hover,
.profile-edit-button:focus-visible {
    background: var(--saf-color-card-hover);
}

.profile-edit-button .material-symbols-rounded {
    font-size: 18px;
}

.drawer-context span,
.drawer-context small,
.drawer-section-label {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.78rem;
    font-weight: var(--font-weight-semibold);
}

.drawer-context strong {
    color: var(--md-sys-color-on-surface);
    overflow-wrap: anywhere;
}

.drawer-nav {
    display: grid;
    gap: var(--space-2);
}

.drawer-section-label {
    margin: var(--space-2) 0 var(--space-1);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.drawer-footer-note {
    margin-top: auto;
    padding: var(--space-3);
    border-radius: 18px;
    background: var(--saf-color-success-container);
    color: var(--md-sys-color-success);
    font-size: 0.82rem;
    font-weight: var(--font-weight-bold);
}

.app-drawer.collapsed .drawer-home {
    justify-content: center;
    width: 100%;
}

.app-drawer.collapsed .drawer-header {
    flex-direction: column;
    justify-content: center;
    gap: var(--space-3);
}

.app-drawer.collapsed .drawer-collapse {
    display: inline-flex;
    width: 42px;
    min-width: 42px;
    height: 42px;
    padding: 0;
}

.app-drawer.collapsed .drawer-lock-text {
    display: none;
}

.app-drawer.collapsed .drawer-home-text,
.app-drawer.collapsed .drawer-section-label,
.app-drawer.collapsed .drawer-footer-note {
    display: none;
}

.app-drawer.collapsed .drawer-context.profile-card {
    display: flex;
    justify-content: center;
    padding: 0;
    border: 0;
    background: transparent;
}

.app-drawer.collapsed .profile-card-copy,
.app-drawer.collapsed .profile-card-actions {
    display: none;
}

.app-drawer.collapsed .drawer-nav {
    width: 100%;
}

.drawer-overlay {
    display: none;
}

.dashboard {
    width: min(1220px, 100%);
    margin: 0 auto;
}

.module-dashboard-clean {
    width: min(1320px, 100%);
}

.workspace-panel.module-workspace-panel {
    display: grid;
    gap: var(--space-5);
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.module-workspace-summary {
    max-width: 700px;
    margin-bottom: 0;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.92rem;
    font-weight: var(--font-weight-regular);
    line-height: 1.5;
}

.dashboard-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-5);
    align-items: end;
    margin-bottom: var(--space-6);
    padding: clamp(var(--space-6), 4vw, var(--space-10));
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 32px;
    background: var(--md-sys-color-surface);
    box-shadow: var(--elevation-2);
}

.dashboard-heading {
    max-width: 720px;
}

.dashboard-heading p:last-child {
    margin-bottom: 0;
    font-size: 1.05rem;
}

.hero-status {
    min-width: 250px;
    display: grid;
    gap: var(--space-1);
    padding: var(--space-4);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 24px;
    background: var(--saf-color-info-container);
}

.hero-status-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: var(--md-sys-color-success);
    box-shadow: 0 0 0 6px var(--saf-color-success-container);
}

.hero-status strong {
    color: var(--md-sys-color-on-surface);
}

.hero-status small {
    color: var(--md-sys-color-on-surface-variant);
    line-height: 1.45;
}

.selection-grid,
.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: var(--space-4);
}

.selection-flow-card .selection-grid {
    width: 100%;
    margin: 0 auto;
    grid-template-columns: repeat(auto-fit, minmax(260px, 300px));
    align-items: stretch;
    justify-content: center;
}

.selection-search {
    width: min(520px, 100%);
    margin: 0 auto var(--space-6);
}

.selection-search-panel {
    width: min(640px, 100%);
    margin: 0 auto var(--space-6);
    display: grid;
    gap: var(--space-2);
}

.selection-search-label {
    color: var(--md-sys-color-on-surface);
    font-size: var(--font-size-label);
    font-weight: var(--font-weight-bold);
    text-align: center;
}

.selection-search-control {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: var(--space-3);
    min-height: 58px;
    padding: 0 var(--space-4);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 22px;
    background: var(--saf-color-input);
    box-shadow: var(--elevation-1);
}

.selection-search-control span {
    color: var(--md-sys-color-primary);
    font-size: 0.78rem;
    font-weight: var(--font-weight-bold);
}

.selection-search-control input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--md-sys-color-on-surface);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
    gap: var(--space-5);
    align-items: start;
}

.access-entry,
.access-form,
.login-form {
    display: grid;
    gap: var(--space-5);
}

.flow-heading,
.section-heading,
.login-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.login-header {
    justify-content: flex-start;
}

.login-header h1 {
    max-width: 26rem;
    margin-top: var(--space-4);
    font-size: clamp(1.62rem, 3vw, 2.15rem);
    line-height: 1.12;
    font-weight: var(--font-weight-title);
    letter-spacing: -0.01em;
}

.login-header .page-subtitle {
    max-width: 30rem;
    line-height: 1.55;
}

.selection-flow-heading h1 {
    max-width: none;
    font-size: clamp(1.45rem, 2vw, 1.95rem);
    line-height: 1.08;
    font-weight: var(--font-weight-title);
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.selection-flow-heading .page-subtitle {
    max-width: 420px;
}

.selection-flow-heading {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
}

.section-heading {
    align-items: center;
    margin-bottom: var(--space-4);
}

.module-heading-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.module-back-button {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-3);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--shape-pill);
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
    font: inherit;
    font-size: var(--font-size-label);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition:
        transform var(--motion-fast) var(--easing-standard),
        border-color var(--motion-fast) var(--easing-standard),
        background-color var(--motion-fast) var(--easing-standard);
}

.module-back-button:hover,
.module-back-button:focus-visible {
    transform: translateY(-1px);
    border-color: var(--md-sys-color-primary);
    background: var(--md-sys-color-primary-container);
}

.module-back-button .material-symbols-rounded {
    color: var(--md-sys-color-primary);
    font-size: 1.05rem;
}

.context-strip {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: var(--space-5) 0 var(--space-6);
    padding: var(--space-3);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 22px;
    background: var(--md-sys-color-surface-variant);
    font-size: var(--font-size-label);
}

.context-strip span,
.context-strip strong {
    display: inline-flex;
    min-height: 34px;
    align-items: center;
    padding: 0 var(--space-3);
    border-radius: var(--shape-pill);
    background: var(--md-sys-color-surface);
    overflow-wrap: anywhere;
}

.context-strip strong {
    color: var(--md-sys-color-on-surface);
}

@media (max-width: 900px) {
    .dashboard-shell {
        display: block;
    }

    .dashboard-shell.drawer-collapsed {
        display: block;
    }

    .app-drawer {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(86vw, 340px);
        align-items: stretch;
        gap: var(--space-5);
        padding: var(--space-5);
        transform: translateX(-104%);
        transition: transform var(--motion-slow) var(--easing-standard);
    }

    .app-drawer.collapsed {
        align-items: stretch;
        gap: var(--space-5);
        padding: var(--space-5);
    }

    .app-drawer.open {
        transform: translateX(0);
    }

    .app-drawer.collapsed .drawer-home-text,
    .app-drawer.collapsed .drawer-context,
    .app-drawer.collapsed .drawer-section-label,
    .app-drawer.collapsed .drawer-footer-note {
        display: block;
    }

    .app-drawer.collapsed .drawer-home {
        justify-content: flex-start;
        width: auto;
    }

    .drawer-close,
    .drawer-toggle {
        display: inline-grid;
        place-items: center;
    }

    .drawer-collapse {
        display: none;
    }

    .drawer-overlay {
        position: fixed;
        inset: 0;
        z-index: 7;
        display: block;
        border: 0;
        background: rgba(13, 22, 34, 0.46);
        cursor: pointer;
    }

    .dashboard-hero,
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .hero-status {
        min-width: 0;
    }
}

@media (max-width: 640px) {
    .auth-shell::after {
        display: none;
    }

    .auth-shell {
        justify-content: flex-start;
    }

    .content-panel,
    .main-content {
        padding: var(--space-4);
    }

    .content-panel {
        align-items: start;
        padding-top: var(--space-8);
    }

    .content-panel::before {
        width: min(92vw, 480px);
        height: min(420px, 58vh);
        border-radius: 30px;
        transform: translate(26px, 18px) rotate(12deg);
        opacity: 0.46;
    }

    .flow-card,
    .login-card,
    .state-box {
        width: 100%;
    }

    .selection-flow-card,
    .selection-flow-card-compact,
    .selection-flow-card-medium,
    .selection-flow-card-large,
    .selection-flow-card-wide {
        width: 100%;
    }

    .topbar {
        position: static;
        min-height: 0;
        align-items: flex-start;
        flex-direction: column;
        padding: var(--space-4);
    }

    .topbar-brand,
    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .tenant-inline {
        max-width: 100%;
    }

    .topbar-context {
        flex: 1;
        width: 100%;
    }

    .topbar-module small {
        display: none;
    }

    .topbar-context-divider {
        height: 28px;
    }

    .access-pill {
        display: none;
    }

    .flow-heading,
    .section-heading,
    .login-header {
        display: grid;
    }

    .module-heading-actions {
        justify-content: flex-start;
    }

    .selection-flow-heading h1 {
        white-space: normal;
    }

    .context-strip {
        border-radius: 20px;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .flow-card,
    .login-card,
    .state-box {
        width: min(610px, 100%);
    }
}
