// =============================================================================
// Decent DS - Application shell layout (sidebar + topbar + content)
// =============================================================================
@use 'tokens' as t;

.dc-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: t.$sidebar-width 1fr;
    grid-template-rows: t.$topbar-height 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar content";
    background: var(--dc-bg-canvas);

    &.is-collapsed {
        grid-template-columns: t.$sidebar-collapsed-width 1fr;
    }
}

@media (max-width: 991.98px) {
    .dc-shell {
        grid-template-columns: 1fr;
        grid-template-rows: t.$mobile-topbar-height 1fr;
        grid-template-areas:
            "topbar"
            "content";
    }
}

// -----------------------------------------------------------------------------
// Sidebar
// -----------------------------------------------------------------------------
.dc-sidebar {
    grid-area: sidebar;
    background: var(--dc-bg-surface);
    border-right: 1px solid var(--dc-border-subtle);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    transition: transform t.$motion-base t.$ease-out;
    z-index: 40;
}

@media (max-width: 991.98px) {
    .dc-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(84vw, 320px);
        transform: translateX(-100%);
        box-shadow: var(--dc-shadow-lg);
    }
    .dc-shell.is-mobile-open .dc-sidebar {
        transform: translateX(0);
    }
}

.dc-sidebar__brand {
    display: flex;
    align-items: center;
    gap: t.$space-2;
    padding: t.$space-4 t.$space-5;
    border-bottom: 1px solid var(--dc-border-subtle);
    min-height: t.$topbar-height;
}
.dc-sidebar__brand-mark {
    width: 32px; height: 32px;
    border-radius: t.$radius-md;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--dc-brand-primary), var(--dc-brand-secondary));
    color: #fff;
    font-weight: 700;
    font-size: 0.9375rem;
    letter-spacing: -.02em;
    box-shadow: var(--dc-shadow-sm);
}
.dc-sidebar__brand-name {
    font-weight: 600;
    letter-spacing: -.01em;
    color: var(--dc-text-primary);
    white-space: nowrap;
}
.dc-shell.is-collapsed .dc-sidebar__brand-name { display: none; }

.dc-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: t.$space-3;
    scrollbar-width: thin;
}
.dc-sidebar__section-label {
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: t.$fs-12;
    color: var(--dc-text-muted);
    padding: t.$space-3 t.$space-3 t.$space-2;
}
.dc-shell.is-collapsed .dc-sidebar__section-label { display: none; }

.dc-nav-item {
    display: flex;
    align-items: center;
    gap: t.$space-3;
    padding: t.$space-2 t.$space-3;
    border-radius: t.$radius-md;
    color: var(--dc-text-secondary);
    font-weight: 500;
    text-decoration: none;
    transition: background-color t.$motion-fast t.$ease-out, color t.$motion-fast t.$ease-out;
    white-space: nowrap;
}
.dc-nav-item:hover {
    background: var(--dc-bg-hover);
    color: var(--dc-text-primary);
    text-decoration: none;
}
.dc-nav-item.active {
    background: var(--dc-brand-primary-soft);
    color: var(--dc-brand-primary);
}
.dc-nav-item__icon {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.dc-shell.is-collapsed .dc-nav-item__label { display: none; }
.dc-shell.is-collapsed .dc-nav-item {
    justify-content: center;
    padding: t.$space-2;
}

.dc-sidebar__footer {
    padding: t.$space-3;
    border-top: 1px solid var(--dc-border-subtle);
    font-size: t.$fs-12;
    color: var(--dc-text-muted);
}
.dc-shell.is-collapsed .dc-sidebar__footer-copy { display: none; }

// -----------------------------------------------------------------------------
// Top bar
// -----------------------------------------------------------------------------
.dc-topbar {
    grid-area: topbar;
    background: var(--dc-bg-surface);
    border-bottom: 1px solid var(--dc-border-subtle);
    display: flex;
    align-items: center;
    gap: t.$space-3;
    padding: 0 t.$space-4;
    position: sticky;
    top: 0;
    z-index: 30;
}
.dc-topbar__spacer { flex: 1; }

.dc-topbar__action {
    display: inline-flex;
    align-items: center;
    gap: t.$space-2;
    padding: t.$space-2 t.$space-3;
    border-radius: t.$radius-md;
    color: var(--dc-text-secondary);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color t.$motion-fast t.$ease-out;
}
.dc-topbar__action:hover {
    background: var(--dc-bg-hover);
    color: var(--dc-text-primary);
}
.dc-topbar__search {
    flex: 0 1 380px;
    max-width: 100%;
    position: relative;
}
.dc-topbar__search input {
    width: 100%;
    padding: t.$space-2 t.$space-3 t.$space-2 t.$space-8;
    border-radius: t.$radius-md;
    border: 1px solid var(--dc-border-default);
    background: var(--dc-bg-inset);
    color: var(--dc-text-primary);
    font-size: t.$fs-14;
    transition: border-color t.$motion-fast t.$ease-out, box-shadow t.$motion-fast t.$ease-out;
}
.dc-topbar__search input:focus {
    outline: none;
    border-color: var(--dc-brand-primary);
    box-shadow: var(--dc-focus-ring);
}
.dc-topbar__search-icon {
    position: absolute;
    left: t.$space-3;
    top: 50%;
    transform: translateY(-50%);
    color: var(--dc-text-muted);
    pointer-events: none;
}

@media (max-width: 767.98px) {
    .dc-topbar__search { display: none; }
}

// -----------------------------------------------------------------------------
// Content
// -----------------------------------------------------------------------------
.dc-content {
    grid-area: content;
    padding: t.$space-6;
    max-width: 100%;
    overflow-x: hidden;
}
.dc-content__inner {
    max-width: t.$content-max-width;
    margin: 0 auto;
}
@media (max-width: 575.98px) {
    .dc-content { padding: t.$space-4; }
}

.dc-page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: t.$space-4;
    margin-bottom: t.$space-6;
    flex-wrap: wrap;
}
.dc-page-title { margin: 0; }
.dc-page-subtitle { color: var(--dc-text-muted); margin-top: t.$space-1; }

// -----------------------------------------------------------------------------
// Backdrop for mobile sidebar
// -----------------------------------------------------------------------------
.dc-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .38);
    z-index: 35;
}
.dc-shell.is-mobile-open .dc-backdrop {
    display: block;
}
