html:has(.app-shell),
body:has(.app-shell) {
    height: 100%;
}

body:has(.app-shell) {
    overflow: hidden;
}

.app-shell {
    height: 100%;
    max-height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem 1.5rem;
    padding: 16px 24px;
    min-height: 0;
    border-bottom: 1px solid #e5e7eb;
    background: #ffffff;
    position: relative;
    z-index: 20;
    flex-shrink: 0;
}

.app-header-brand {
    display: flex;
    align-items: center;
    min-width: 0;
    line-height: 1.25;
}

.app-header-brand-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
    flex-shrink: 0;
}

.app-header-logo {
    display: block;
    height: 50px;
    width: auto;
    max-width: 210px;
    object-fit: contain;
    flex-shrink: 0;
}

.app-header-title {
    font-size: 1rem;
    font-weight: 700;
    color: #111827;
    line-height: 1.25;
}

.app-header .dev-label {
    flex-shrink: 0;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1.35;
    padding: 2px 8px;
    letter-spacing: 0.02em;
}

.app-header-organisation {
    display: block;
    font-size: 0.8125rem;
    font-weight: 400;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 16rem;
    text-align: right;
}

.app-header-workspace {
    display: flex;
    align-items: baseline;
    justify-content: flex-end;
    gap: 0.35rem;
    max-width: 20rem;
    min-width: 0;
    font-size: 0.8125rem;
    font-weight: 400;
    line-height: 1.35;
    text-align: right;
}

.app-header-company,
.app-header-business-unit {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.app-header-company {
    font-weight: 500;
    max-width: 55%;
}

.app-header-business-unit {
    max-width: 45%;
}

.app-header-workspace-sep {
    flex-shrink: 0;
}

.app-header-account {
    display: flex;
    align-items: center;
    gap: 16px 20px;
    flex-shrink: 0;
    min-width: 0;
}

.app-header-user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
    text-align: right;
    min-width: 0;
}

.app-header-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: #111827;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 16rem;
}

.app-header-user-email {
    font-size: 0.8125rem;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 16rem;
}

.app-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.app-header-logout-form {
    display: inline;
    margin: 0;
}

.app-header-settings-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.app-header-settings-icon {
    flex-shrink: 0;
}

@media (max-width: 640px) {
    .app-header-settings-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    min-height: auto;
    font-size: 0.85rem;
    border-radius: 8px;
    gap: 0.35rem;
}

.btn-sm.btn-icon > img,
.btn-sm.btn-icon > img {
    width: 16px;
    height: 16px;
}

.app-body {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
}

.app-body--no-sidebar {
    grid-template-columns: minmax(0, 1fr);
}

.app-sidebar {
    border-right: 1px solid #e5e7eb;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    min-height: 0;
    align-self: stretch;
    overflow: hidden;
    flex-shrink: 0;
    transition: width 0.25s ease;
    width: 100%;
}

@media (min-width: 901px) {
    body.sidebar-context-open .app-body {
        grid-template-columns: 450px minmax(0, 1fr);
    }
}

.app-main {
    padding: 1rem 1.25rem 1.5rem;
    display: grid;
    gap: 1rem;
    align-content: start;
    width: 100%;
    min-width: 0;
    min-height: 0;
    max-width: none;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.empty-state {
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 0.9rem;
    background: #f9fafb;
}

.dev-diagnostics {
    margin: 0 1rem 1rem 1rem;
    padding: 1rem;
    border: 1px dashed #cbd5e1;
    background: #f8fafc;
    border-radius: 8px;
}

.page-header {
    display: grid;
    gap: 0.35rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px 16px;
    }

    .app-header-organisation {
        max-width: none;
    }

    .app-header-workspace {
        max-width: none;
        justify-content: flex-start;
    }

    .app-header-account {
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 12px;
    }

    .app-header-user {
        align-items: flex-start;
        text-align: left;
        flex: 1 1 12rem;
    }

    .app-header-user-name,
    .app-header-user-email {
        max-width: none;
    }

    .app-header-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }
}

@media (max-width: 900px) {
    .app-body {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .app-sidebar {
        border-right: 0;
        border-bottom: 1px solid #e5e7eb;
        max-height: 55vh;
        overflow-y: auto;
    }

    body.sidebar-context-open .app-body {
        grid-template-columns: 1fr;
    }
}

@media print {
    html:has(.app-shell),
    body:has(.app-shell) {
        height: auto !important;
        overflow: visible !important;
    }

    .app-shell {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        display: block !important;
    }

    .app-body {
        display: block !important;
        overflow: visible !important;
    }

    .app-sidebar {
        max-height: none !important;
        overflow: visible !important;
    }

    .app-main {
        overflow: visible !important;
    }
}
