/* Workspace application shell */

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.app-sidebar {
    position: sticky;
    z-index: 20;
    top: 0;
    min-width: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--sidebar-border);
    background: var(--sidebar-background);
    color: var(--sidebar-text);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.app-main {
    min-width: 0;
}

.desktop-workspace-header {
    min-height: 4.25rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    color: var(--text);
}

.desktop-workspace-header strong {
    max-width: var(--max-width);
    overflow: hidden;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.05rem;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-authenticated .main-content {
    width: min(calc(100% - 3rem), var(--max-width));
    padding-block: 2.25rem 5rem;
}

.auth-main-content {
    padding-block: 3rem 5rem;
}

.sidebar-header {
    flex: 0 0 auto;
    border-bottom: 1px solid var(--sidebar-border);
    padding: 1rem;
}

.sidebar-user-link {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 2.2rem minmax(0, 1fr);
    align-items: center;
    gap: 0.7rem;
    border: 1px solid transparent;
    border-radius: 0.8rem;
    padding: 0.55rem;
    background: transparent;
    color: var(--sidebar-text);
    text-align: left;
    text-decoration: none;
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.sidebar-user-link:hover,
.sidebar-user-link.is-current {
    border-color: var(--sidebar-border);
    background: var(--sidebar-surface);
}

.sidebar-user-avatar {
    width: 2.2rem;
    height: 2.2rem;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--sidebar-accent);
    color: var(--accent-text);
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.06em;
}

.sidebar-user-copy {
    min-width: 0;
    display: grid;
    gap: 0.1rem;
}

.sidebar-user-copy strong,
.sidebar-user-copy span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-copy strong {
    font-size: 0.9rem;
}

.sidebar-user-copy span {
    color: var(--sidebar-muted);
    font-size: 0.72rem;
}

.sidebar-navigation {
    min-height: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
}

.sidebar-section {
    display: grid;
    gap: 0.3rem;
}

.sidebar-link,
.sidebar-footer-action {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 1.75rem minmax(0, 1fr);
    align-items: center;
    gap: 0.7rem;
    border: 1px solid transparent;
    border-radius: 0.75rem;
    padding: 0.65rem 0.7rem;
    background: transparent;
    color: var(--sidebar-text);
    font-size: 0.88rem;
    font-weight: 650;
    text-align: left;
    text-decoration: none;
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.sidebar-link:hover,
.sidebar-footer-action:hover {
    border-color: var(--sidebar-border);
    background: var(--sidebar-surface);
    color: var(--sidebar-accent);
}

.sidebar-link.is-current {
    border-color: color-mix(in srgb, var(--sidebar-accent) 30%, var(--sidebar-border));
    background: var(--sidebar-surface-active);
    color: var(--sidebar-accent);
}

.sidebar-icon {
    width: 1.35rem;
    height: 1.35rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

.sidebar-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-subnavigation {
    display: grid;
    gap: 0.12rem;
    margin: 0.25rem 0 0 1.55rem;
    border-left: 1px solid var(--sidebar-border);
    padding-left: 0.7rem;
}

.sidebar-subnavigation a {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    border-radius: 0.55rem;
    padding: 0.5rem 0.65rem;
    color: var(--sidebar-muted);
    font-size: 0.76rem;
    font-weight: 620;
    line-height: 1.3;
    text-decoration: none;
}

.sidebar-subnavigation a:hover,
.sidebar-subnavigation a.is-current {
    background: var(--sidebar-surface);
    color: var(--sidebar-accent);
}

.sidebar-action-navigation a > span:first-child {
    width: 1.05rem;
    flex: 0 0 1.05rem;
    font-size: 1rem;
    line-height: 1;
    text-align: center;
}

.sidebar-footer {
    flex: 0 0 auto;
    border-top: 1px solid var(--sidebar-border);
    padding: 0.8rem 1rem 1rem;
    background: var(--sidebar-background);
}

.sidebar-footer form {
    margin: 0;
}

.sidebar-footer-action {
    border: 0;
}

.sidebar-logout-action:hover {
    color: var(--danger);
}

.sidebar-link:focus-visible,
.sidebar-user-link:focus-visible,
.sidebar-footer-action:focus-visible,
.sidebar-subnavigation a:focus-visible {
    outline: 2px solid var(--sidebar-accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .sidebar-link,
    .sidebar-footer-action,
    body {
        transition: none;
    }
}

/* ========================================================================== */

/* Online connectivity status. Offline page theme styles stay isolated in offline.css. */
.offline-status-banner {
    position: fixed;
    z-index: 10000;
    left: 50%;
    bottom: max(18px, env(safe-area-inset-bottom));

    transform: translateX(-50%);

    border: 1px solid #c5ad74;
    border-radius: 999px;
    padding: 9px 14px;

    background: #0c1914;
    color: #f6f1e5;

    box-shadow: 0 4px 18px rgb(0 0 0 / 22%);
    font-size: 0.9rem;
}

/* PWA update lifecycle. The waiting worker only activates after explicit reload. */
.pwa-update-banner {
    position: fixed;
    z-index: 10001;
    left: 50%;
    bottom: max(18px, env(safe-area-inset-bottom));

    display: flex;
    align-items: center;
    gap: 0.8rem;
    transform: translateX(-50%);

    max-width: calc(100vw - 2rem);
    border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border));
    border-radius: 999px;
    padding: 0.45rem 0.5rem 0.45rem 0.85rem;

    background: var(--surface);
    color: var(--text);
    box-shadow: 0 0.55rem 1.7rem rgb(0 0 0 / 20%);
    font-size: 0.9rem;
    white-space: nowrap;
}

.pwa-update-action {
    min-height: 2.2rem;
    margin: 0;
    border: 0;
    border-radius: 999px;
    padding: 0.42rem 0.8rem;

    background: var(--accent);
    color: var(--accent-contrast, #fff);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.pwa-update-action:disabled {
    cursor: wait;
    opacity: 0.72;
}

@media (max-width: 980px) {
    .pwa-update-banner {
        bottom: calc(var(--mobile-bottom-height, 4.75rem) + max(0.8rem, env(safe-area-inset-bottom)));
    }
}

/* Phase 3: one global mobile action control, no regular desktop FAB. */
.desktop-shell-actions {
    display: none;
}

.app-fab-cluster {
    display: none;
}

html[data-shell-mode="mobile"] .app-fab-cluster {
    position: fixed;
    z-index: 68;
    right: max(1rem, env(safe-area-inset-right));
    bottom: calc(
        var(--mobile-bottom-height, 4.75rem)
        + max(0.9rem, env(safe-area-inset-bottom))
    );
    display: grid;
    justify-items: end;
    gap: 0.55rem;
}

.app-fab {
    width: 3.7rem;
    height: 3.7rem;
    display: grid;
    place-items: center;
    margin: 0;
    border: 1px solid color-mix(in srgb, var(--accent) 48%, var(--border));
    border-radius: 50%;
    padding: 0.28rem;
    background: var(--surface);
    color: var(--text);
    box-shadow:
        0 0.72rem 1.45rem rgba(15, 26, 20, 0.24),
        inset 0 -0.12rem 0.18rem rgba(24, 45, 31, 0.12);
    cursor: pointer;
    transition:
        transform 110ms ease,
        box-shadow 110ms ease,
        background 110ms ease;
    -webkit-tap-highlight-color: transparent;
}

.app-fab:hover,
.app-fab:focus-visible {
    background: var(--surface-raised, var(--surface));
}

.app-fab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.app-fab.is-pressed,
.app-fab:active {
    transform: translateY(0.16rem) scale(0.965);
    box-shadow:
        0 0.28rem 0.72rem rgba(15, 26, 20, 0.2),
        inset 0 0.08rem 0.18rem rgba(24, 45, 31, 0.16);
}

.app-fab-illustration {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    pointer-events: none;
}

.app-fab-illustration-source {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.app-fab-illustration-dark {
    display: none;
}

html[data-theme="dark"] .app-fab-illustration-light {
    display: none;
}

html[data-theme="dark"] .app-fab-illustration-dark {
    display: block;
}

html[data-theme="dark"] .app-fab {
    border-color: color-mix(in srgb, var(--accent) 58%, var(--border));
    background: color-mix(in srgb, var(--surface) 88%, #13261d 12%);
    box-shadow:
        0 0.72rem 1.55rem rgba(0, 0, 0, 0.36),
        inset 0 -0.12rem 0.18rem rgba(210, 222, 190, 0.07);
}

.app-fab-menu {
    min-width: 11.25rem;
    max-width: min(18rem, calc(100vw - 2rem));
    overflow: clip;
    border: 1px solid var(--border);
    border-radius: 0.88rem;
    background: var(--surface);
    box-shadow: 0 0.85rem 2rem rgba(15, 24, 18, 0.24);
}

.app-fab-menu[hidden] {
    display: none;
}

.app-fab-menu > a,
.app-fab-menu > button,
.app-fab-menu > form > button {
    width: 100%;
    min-height: 2.75rem;
    display: block;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: 0.7rem 0.9rem;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 750;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.app-fab-menu > * + * {
    border-top: 1px solid var(--border);
}

.app-fab-menu form {
    margin: 0;
}

.app-fab-menu button:disabled {
    color: var(--text-muted);
    cursor: not-allowed;
}

.app-fab-menu > a:hover,
.app-fab-menu > a:focus-visible,
.app-fab-menu > button:hover,
.app-fab-menu > button:focus-visible,
.app-fab-menu > form > button:hover,
.app-fab-menu > form > button:focus-visible {
    background: var(--surface-soft);
}

html[data-shell-mode="desktop"] .app-fab-cluster {
    display: none !important;
}

@media (min-width: 981px) {
    html[data-shell-mode="desktop"] .desktop-shell-actions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.55rem;
        margin-block: 1rem;
    }

    html[data-shell-mode="desktop"] .desktop-shell-actions form {
        margin: 0;
    }
}

/* Shared desktop context-menu foundation. Domain screens opt in explicitly. */
.app-context-menu,
[data-context-menu] {
    position: fixed;
    z-index: 120;
    min-width: 11rem;
    max-width: min(20rem, calc(100vw - 1rem));
    overflow: clip;
    border: 1px solid var(--border);
    border-radius: 0.72rem;
    padding: 0.25rem;
    background: var(--surface);
    box-shadow: 0 0.85rem 2rem rgba(12, 20, 15, 0.3);
}

[data-context-menu][hidden] {
    display: none;
}

[data-context-menu] a,
[data-context-menu] button {
    width: 100%;
    min-height: 2.35rem;
    display: flex;
    align-items: center;
    border: 0;
    border-radius: 0.5rem;
    padding: 0.5rem 0.68rem;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

[data-context-menu] a:hover,
[data-context-menu] a:focus-visible,
[data-context-menu] button:hover,
[data-context-menu] button:focus-visible {
    background: var(--surface-soft);
}

/* Phase 2: shell mode follows the per-device setting, not component breakpoints. */
html[data-shell-mode="mobile"] {
    --mobile-header-height: 4rem;
    --mobile-bottom-height: 4.75rem;
}

@media (min-width: 981px) {
    html[data-shell-mode="mobile"] .app-shell {
        display: block;
        min-height: 100vh;
    }

    html[data-shell-mode="mobile"] .app-main,
    html[data-shell-mode="mobile"] .app-authenticated .main-content {
        overflow: visible;
    }

    html[data-shell-mode="mobile"] .app-sidebar,
    html[data-shell-mode="mobile"] .desktop-workspace-header {
        display: none;
    }

    html[data-shell-mode="mobile"] .mobile-app-header {
        position: fixed;
        z-index: 60;
        top: 0;
        right: 0;
        left: 0;

        min-height: var(--mobile-header-height);
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        align-items: center;
        gap: 0.5rem;

        border-bottom: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
        padding:
            max(0.45rem, env(safe-area-inset-top))
            max(0.75rem, env(safe-area-inset-right))
            0.45rem
            max(0.75rem, env(safe-area-inset-left));

        background: color-mix(in srgb, var(--surface) 94%, transparent);
        backdrop-filter: blur(18px);
        box-shadow: 0 0.35rem 1.4rem rgba(47, 52, 45, 0.08);
    }

    html[data-shell-mode="mobile"] .mobile-app-title {
        overflow: hidden;
        color: var(--text);
        font-family: Georgia, "Times New Roman", serif;
        font-size: 1.12rem;
        line-height: 1.2;
        text-align: center;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    html[data-shell-mode="mobile"] .mobile-header-action {
        width: 2.7rem;
        height: 2.7rem;
        display: grid;
        place-items: center;
        margin: 0;
        border: 0;
        border-radius: 50%;
        padding: 0;
        background: transparent;
        color: var(--text);
    }

    html[data-shell-mode="mobile"] .mobile-header-action:hover,
    html[data-shell-mode="mobile"] .mobile-header-action:focus-visible {
        background: var(--accent-soft);
        color: var(--accent);
    }

    html[data-shell-mode="mobile"] .mobile-account-link {
        justify-self: start;
    }

    html[data-shell-mode="mobile"] .mobile-management-link,
    html[data-shell-mode="mobile"] .mobile-header-spacer {
        justify-self: end;
    }

    html[data-shell-mode="mobile"] .mobile-user-avatar {
        width: 2.2rem;
        height: 2.2rem;
        display: grid;
        place-items: center;
        border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
        border-radius: 50%;
        background: var(--accent);
        color: var(--accent-text);
        font-size: 0.76rem;
        font-weight: 800;
        letter-spacing: 0.05em;
    }

    html[data-shell-mode="mobile"] .mobile-header-action.is-current {
        background: var(--accent-soft);
        color: var(--accent);
    }

    html[data-shell-mode="mobile"] .mobile-header-spacer {
        visibility: hidden;
        pointer-events: none;
    }

    html[data-shell-mode="mobile"] .mobile-header-management-image {
        width: 2.05rem;
        height: 2.05rem;
    }

    html[data-shell-mode="mobile"] .app-authenticated .main-content {
        width: min(calc(100% - 1.25rem), var(--max-width));
        padding:
            calc(var(--mobile-header-height) + 1rem)
            0
            calc(var(--mobile-bottom-height) + env(safe-area-inset-bottom) + 1.25rem);
    }

    html[data-shell-mode="mobile"] .mobile-bottom-navigation {
        position: fixed;
        z-index: 65;
        right: 0.55rem;
        bottom: max(0.45rem, env(safe-area-inset-bottom));
        left: 0.55rem;

        min-height: var(--mobile-bottom-height);
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: 1fr;
        align-items: stretch;

        border: 1px solid color-mix(in srgb, var(--accent) 42%, var(--border));
        border-radius: 1.25rem;
        padding: 0.28rem;

        background: color-mix(in srgb, var(--sidebar-background) 96%, transparent);
        color: var(--sidebar-text);
        backdrop-filter: blur(18px);
        box-shadow: 0 0.7rem 2rem rgba(27, 40, 31, 0.2);
    }

    html[data-shell-mode="mobile"] .mobile-bottom-navigation a,
    html[data-shell-mode="mobile"] .mobile-bottom-navigation button {
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.18rem;
        margin: 0;
        border: 0;
        border-radius: 0.9rem;
        padding: 0.35rem 0.2rem;
        background: transparent;
        color: inherit;
        font-size: 0.59rem;
        font-weight: 700;
        line-height: 1;
        text-decoration: none;
    }

    html[data-shell-mode="mobile"] .mobile-bottom-navigation a.is-current,
    html[data-shell-mode="mobile"] .mobile-bottom-navigation button.is-current {
        background: var(--sidebar-surface-active);
        color: var(--sidebar-accent);
    }

    html[data-shell-mode="mobile"] .mobile-bottom-navigation .mobile-bottom-image {
        width: 2rem;
        height: 2rem;
        flex: 0 0 2rem;
    }

    html[data-shell-mode="mobile"] .pwa-update-banner {
        bottom: calc(
            var(--mobile-bottom-height, 4.75rem)
            + max(0.8rem, env(safe-area-inset-bottom))
        );
    }
}

html[data-shell-mode="mobile"] .journal-create-button {
    display: none;
}

[data-context-menu] form {
    margin: 0;
}

[data-context-menu] button:disabled {
    color: var(--text-muted);
    cursor: default;
    opacity: 0.62;
}

[data-context-menu] button:disabled:hover,
[data-context-menu] button:disabled:focus-visible {
    background: transparent;
}

[data-context-menu] .app-context-danger {
    margin-top: 0.18rem;
    border-top: 1px solid var(--border);
    border-radius: 0 0 0.5rem 0.5rem;
    color: var(--danger);
}
