/**
 * Desktop app shell — sidebar, titlebar, statusbar.
 * Desktop-only. Works with theme-tokens (light/dark/user).
 */

body.page-links-dashboard,
body.page-planner,
body.page-stats {
    height: 100vh;
    overflow: hidden;
}

.desktop-app {
    --shell-toolbar-padding-top: 18px;
    --shell-toolbar-padding-bottom: 10px;
    display: grid;
    grid-template-rows: var(--desktop-titlebar-height, 52px) minmax(0, 1fr);
    height: 100vh;
    width: 100%;
    background-color: var(--shell-canvas-color, var(--surface-page));
    background-image: var(--shell-canvas-bg, var(--app-bg));
    background-attachment: fixed;
    background-size: cover;
    background-repeat: no-repeat;
    color: var(--text-primary);
}

.desktop-frame {
    display: grid;
    grid-template-columns: var(--desktop-sidebar-width, 260px) minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
    background: transparent;
}

.desktop-workspace {
    display: grid;
    grid-template-rows: minmax(0, 1fr) var(--desktop-statusbar-height, 28px);
    min-width: 0;
    min-height: 0;
    height: 100%;
    background: transparent;
}

.desktop-workspace > .desktop-main {
    min-height: 0;
    height: 100%;
}

/* Titlebar */
.desktop-titlebar {
    position: static !important;
    min-height: var(--desktop-titlebar-height, 52px) !important;
    height: var(--desktop-titlebar-height, 52px);
    display: flex !important;
    align-items: center;
    gap: 12px;
    padding: 0 14px !important;
    grid-template-columns: none !important;
    box-shadow: var(--shell-topbar-shadow, none) !important;
    border-bottom: 1px solid var(--shell-divider, var(--border-subtle));
    background: var(--shell-topbar-bg, var(--surface-topbar));
    backdrop-filter: blur(var(--shell-topbar-blur, 12px)) saturate(var(--shell-topbar-saturate, 130%));
    -webkit-backdrop-filter: blur(var(--shell-topbar-blur, 12px)) saturate(var(--shell-topbar-saturate, 130%));
}

@media (prefers-reduced-motion: reduce) {
    .desktop-titlebar {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

.desktop-titlebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex-shrink: 0;
}

.desktop-titlebar-logo {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover, #65c7ff));
    color: #fff;
    font-size: 14px;
    font-weight: 800;
}

.desktop-titlebar-brand strong {
    font-size: 14px;
    font-weight: 800;
}

.desktop-titlebar-context {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    padding-left: 10px;
    border-left: 1px solid var(--border-subtle);
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.desktop-titlebar-search {
    flex: 1;
    display: flex;
    justify-content: center;
    min-width: 0;
    max-width: 620px;
    margin: 0 auto;
}

.desktop-titlebar-search .search-bar,
.desktop-command-trigger {
    width: 100%;
    height: 34px;
    border: 1px solid var(--border-subtle);
    background: var(--surface-control, var(--surface-subtle));
    border-radius: 9px;
    color: var(--text-primary);
    padding: 0 14px;
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

.desktop-titlebar-search .search-bar:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.desktop-titlebar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    margin-left: auto;
}

.desktop-titlebar-theme.theme-mode-switch {
    position: relative;
    flex-shrink: 0;
    height: 34px;
    min-height: 34px;
    width: auto;
    min-width: 168px;
    display: inline-grid;
    grid-template-columns: repeat(3, minmax(46px, 1fr));
    padding: 3px;
    border-radius: 9px;
}

.desktop-titlebar-theme .theme-mode-thumb {
    top: 3px;
    left: 3px;
    width: calc((100% - 6px) / 3);
    height: calc(100% - 6px);
    border-radius: 6px;
}

.desktop-titlebar-theme button {
    height: 28px;
    min-width: 0;
    padding: 0 4px;
    font-size: 11px;
    font-weight: 750;
}

.desktop-titlebar-theme .theme-user-menu {
    top: calc(100% + 8px);
    right: 0;
    left: auto;
}

.desktop-titlebar-btn {
    height: 34px;
    border: 1px solid var(--border-subtle);
    background: var(--surface-control, var(--surface-subtle));
    color: var(--text-primary);
    border-radius: 8px;
    padding: 0 13px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}

.desktop-titlebar-btn:hover {
    background: var(--surface-control-hover, var(--hover-bg));
}

.desktop-titlebar-date {
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 12px !important;
    font-size: 12px !important;
}

/* Sidebar */
.app-sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 16px 12px;
    background: var(--shell-region-bg, transparent);
    border-right: 1px solid var(--shell-divider, var(--border-subtle));
    overflow: hidden;
}

.app-sidebar-section {
    margin-bottom: 18px;
    min-height: 0;
}

.app-sidebar-section:first-child {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.app-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.app-sidebar-label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.app-sidebar-add {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

.app-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    min-height: 0;
}

.app-sidebar-item {
    min-height: 38px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    border-radius: 8px;
    color: var(--text-primary);
    text-decoration: none;
    border: 0;
    background: transparent;
    font: inherit;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.app-sidebar-item:hover {
    background: var(--surface-control-hover, var(--hover-bg));
}

.app-sidebar-item.active,
.page-switcher-pill.active.app-sidebar-item {
    background: linear-gradient(90deg, var(--accent), var(--accent-hover, #56b5ff));
    color: #fff;
}

.app-sidebar-item.active .app-sidebar-count {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
}

.app-sidebar-icon {
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.app-sidebar-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    font-weight: 650;
}

.app-sidebar-count {
    font-size: 11px;
    background: var(--surface-control, #2a3040);
    color: var(--text-muted);
    padding: 2px 7px;
    border-radius: 99px;
    flex-shrink: 0;
}

.app-sidebar-count.is-overdue {
    background: var(--surface-danger);
    color: var(--text-danger);
    font-weight: 700;
}

.app-sidebar-item.active .app-sidebar-count.is-overdue {
    background: rgba(255, 255, 255, 0.28);
    color: #fff;
}

.app-sidebar-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--shell-divider, var(--border-subtle));
    flex-shrink: 0;
}

.app-sidebar-user-menu {
    position: relative;
    width: 100%;
}

.app-sidebar-user-menu .user-dropdown-btn {
    width: 100%;
    min-height: 42px;
    padding: 6px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm, 8px);
    background: var(--surface-control, var(--surface-subtle));
    justify-content: flex-start;
    gap: 10px;
}

.app-sidebar-user-menu .user-dropdown-btn:hover {
    background: var(--surface-control-hover, var(--hover-bg));
}

.app-sidebar-user-menu .user-info {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.app-sidebar-user-menu .user-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 650;
    color: var(--text-primary);
}

.app-sidebar-user-menu .dropdown-arrow {
    margin-left: auto;
    flex-shrink: 0;
}

.app-sidebar-user-menu .user-dropdown-menu {
    top: auto;
    bottom: calc(100% + 8px);
    right: 0;
    left: 0;
    min-width: 0;
    width: 100%;
    transform: translateY(8px);
}

.app-sidebar-user-menu .user-dropdown-menu.active {
    transform: translateY(0);
}

/* Main workspace */
.desktop-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.desktop-main-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px 10px;
    flex-shrink: 0;
}

.desktop-main-heading h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.15;
}

.desktop-main-heading p {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

.desktop-main-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 0 24px 24px;
}

.desktop-view-surface {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    width: 100%;
    overflow: hidden;
}

/* Homogeneous shell canvas — one gradient, transparent regions, dividers only */
.desktop-frame,
.desktop-workspace,
.desktop-main,
.desktop-main-scroll,
.desktop-view-surface,
.dashboard-main,
.dashboard-body,
.dashboard-grid-col,
.dashboard-todo-col,
.dashboard-planner,
.dashboard-module-card,
.planner-desktop-main,
.stats-desktop-main {
    background: var(--shell-region-bg, transparent);
}

.dashboard-body .desktop-main-toolbar {
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 12px;
}

.dashboard-body .desktop-main-heading {
    flex: 1 1 auto;
    min-width: 0;
}

.dashboard-body .desktop-titlebar-btn {
    flex-shrink: 0;
    align-self: flex-start;
    white-space: nowrap;
}

/* Dashboard: links column + todo sidebar */
.dashboard-body {
    --dashboard-toolbar-padding-top: var(--shell-toolbar-padding-top, 18px);
    --dashboard-toolbar-padding-bottom: var(--shell-toolbar-padding-bottom, 10px);
    --dashboard-content-start-gap: 4px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--dashboard-sidebar-width, clamp(280px, 22vw, 360px));
    grid-template-rows: minmax(0, 1fr);
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    align-items: stretch;
}

.dashboard-grid-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    padding: 0 24px 24px;
    background: transparent;
}

.dashboard-main .desktop-main-toolbar {
    padding: var(--dashboard-toolbar-padding-top) 0 var(--dashboard-toolbar-padding-bottom);
}

.dashboard-main .desktop-main-heading h2 {
    margin: 0;
    font-size: 24px;
    line-height: 1.15;
}

.dashboard-planner-lead {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

.dashboard-todo-col {
    height: 100%;
    min-height: 0;
    align-self: stretch;
    overflow: hidden;
    padding: 0 20px 24px 22px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--shell-divider, var(--border-subtle));
}

.dashboard-launcher-surface,
.dashboard-launcher-mother {
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
}

.dashboard-launcher-mother {
    container-type: inline-size;
    container-name: shortcut-grid;
    display: grid;
    place-items: center;
    overflow: hidden;
}

.dashboard-launcher-mother .dashboard-module-card {
    width: max-content;
    height: max-content;
    max-width: 100%;
    max-height: 100%;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
}

.dashboard-launcher-mother .shortcuts-grid {
    width: max-content;
    height: max-content;
    max-width: 100%;
    max-height: 100%;
    flex: 0 0 auto;
    margin: 0;
    align-content: start;
    justify-content: start;
}

.dashboard-planner {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dashboard-planner-head {
    flex-shrink: 0;
    margin: 0;
    padding: var(--dashboard-toolbar-padding-top) 0 var(--dashboard-toolbar-padding-bottom);
}

.dashboard-planner-summary-cards {
    flex-shrink: 0;
    margin-top: var(--dashboard-content-start-gap, 4px);
}

.dashboard-planner-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

/* Statusbar */
.desktop-statusbar {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 14px;
    height: var(--desktop-statusbar-height, 28px);
    background: transparent;
    border-top: 1px solid var(--shell-divider, var(--border-subtle));
    color: var(--text-muted);
    font-size: 12px;
}

.desktop-status-hint {
    margin-left: auto;
}

/* Planner inside desktop shell */
.planner-desktop-main .planner-page-main-embedded {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr) minmax(240px, 0.7fr);
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
    gap: var(--app-shell-gap, 24px);
    width: min(100%, 1600px);
    max-width: 100%;
    margin: 0;
    padding: 0;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    flex: 0 1 1600px;
}

.planner-board-surface,
.planner-board-mother {
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
}

.planner-board-mother {
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    overflow: hidden;
    padding: 0 24px 24px;
}

.planner-desktop-main .planner-page-list-panel {
    grid-column: 1;
}

.planner-desktop-main .planner-page-detail {
    grid-column: 2;
}

.planner-desktop-main .planner-page-timeline {
    grid-column: 3;
}

.planner-desktop-main .planner-page-list-panel,
.planner-desktop-main .planner-page-detail,
.planner-desktop-main .planner-page-timeline {
    min-height: 0;
    height: auto;
    max-height: none;
    align-self: stretch;
}

.planner-desktop-main {
    overflow: hidden;
}

.planner-desktop-main .desktop-main-toolbar {
    padding: var(--shell-toolbar-padding-top, 18px) 24px var(--shell-toolbar-padding-bottom, 10px);
}

.page-planner .planner-desktop-main .planner-page-detail,
.page-planner .planner-desktop-main .planner-page-timeline {
    border-left: 1px solid var(--shell-divider, var(--border-subtle));
}

.stats-desktop-main .desktop-main-toolbar {
    padding: var(--shell-toolbar-padding-top, 18px) 24px var(--shell-toolbar-padding-bottom, 10px);
}

.stats-board-surface {
    display: flex;
    min-height: 0;
}

.stats-board-mother {
    flex: 1 1 auto;
    min-height: 0;
}

.stats-desktop-main .stats-page-content {
    max-width: var(--app-content-width);
    margin: 0 auto;
}

/* Command palette position under new titlebar */
.command-palette-modal {
    padding-top: calc(var(--desktop-titlebar-height, 52px) + 24px) !important;
}

/* Hide legacy shell pieces inside desktop app */
.desktop-app .dashboard-shell,
.desktop-app .container.dashboard-container,
.desktop-app .app-topbar-spacer {
    display: contents;
}

.page-planner .planner-page-shell,
.page-stats .container.stats-page-container {
    display: contents;
}

