/* ============================================================
   MOBILE
   Mobile shell: tab bar, bottom sheet, FAB and loaders.
   Part of the incremental migration out of components.css:
   the mobile navigation and assistant sheet live here.
   ============================================================ */

/* Tab bar and mobile shell are mobile-only */
#mobile-tab-bar { display: none; }

@media (max-width: 768px) {
    html,
    body {
        width: 100%;
        height: var(--app-viewport-height, 100dvh);
        min-height: var(--app-viewport-height, 100dvh);
        overflow: hidden;
    }

    #app-view {
        height: var(--app-viewport-height, 100dvh);
        min-height: 0;
        max-height: var(--app-viewport-height, 100dvh);
    }

    #app-body {
        padding-bottom: 0;
    }

    /* --- Bottom tab bar: iOS-like glass --- */
    #mobile-tab-bar {
        position: relative;
        left: auto;
        right: auto;
        bottom: auto;
        flex: 0 0 auto;
        width: 100%;
        z-index: 50;
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        gap: 2px;
        padding: 6px 8px max(6px, env(safe-area-inset-bottom, 0px));
        background: color-mix(in srgb, var(--surface-raised) 80%, transparent);
        border-top: 1px solid var(--border-subtle);
        backdrop-filter: blur(22px) saturate(1.3);
        -webkit-backdrop-filter: blur(22px) saturate(1.3);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.14);
    }
    @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
        #mobile-tab-bar { background: var(--surface-raised); }
    }
    .mobile-tab {
        position: relative;
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 6px 2px 4px;
        min-height: var(--touch-target-min);
        color: var(--text-muted);
        border-radius: var(--radius-sm);
        transition: color var(--duration-quick) var(--ease-standard);
    }
    .mobile-tab-icon { width: 23px; height: 23px; flex-shrink: 0; }
    .mobile-tab-label {
        font-size: 0.62rem;
        letter-spacing: 0.01em;
        line-height: 1;
        font-weight: 500;
    }
    .mobile-tab.active { color: var(--accent-primary); }
    .mobile-tab:active { transform: scale(0.96); }
    .mobile-tab-badge {
        position: absolute;
        top: 3px;
        left: calc(50% + 9px);
        width: 6px;
        height: 6px;
        padding: 0;
        background: var(--accent-primary);
        border-radius: 50%;
    }
    #app-view.mobile-chat-open #mobile-tab-bar {
        opacity: 0;
        pointer-events: none;
    }

    /* Keep panel content clear of the tab bar safe area */
    .widget-content {
        padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
    }
    .week-grid::after {
        height: max(20px, env(safe-area-inset-bottom, 0px));
    }
    #app-view.mobile-notes-active .widget-content {
        padding-bottom: 0;
    }

    /* Uniform background across days: drop the alternating tint */
    .week-day-col,
    .week-day-col:nth-child(even) {
        background: transparent;
    }

    #week-view .week-day-col {
        position: relative;
        gap: 6px;
        padding: 16px 16px 18px;
    }

    #week-view .week-day-col:has(.week-item) {
        padding-bottom: 24px;
    }

    #week-view .week-day-col:not(:last-child)::after {
        content: '';
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        height: 1px;
        margin: 0 6px;
        width: auto;
        background: color-mix(in srgb, var(--text-muted) 18%, transparent);
    }

    #week-view .week-day-col.is-empty-day:not(:last-child)::after {
        background: color-mix(in srgb, var(--text-muted) 6%, transparent);
    }

    #week-view.is-empty-week .week-grid {
        padding-bottom: 4px;
    }

    #week-view.is-empty-week .week-day-col {
        padding: 7px 16px 8px;
        gap: 2px;
    }

    #week-view.is-empty-week .week-day-col:not(:last-child)::after {
        margin: 0 8px;
        background: color-mix(in srgb, var(--text-muted) 5%, transparent);
    }

    #week-view.is-empty-week .week-day-list-label {
        font-size: 0.96rem;
        font-weight: 600;
    }

    #week-view .week-day-col.is-empty-day,
    #week-view .week-day-col:has(.week-no-items) {
        gap: 0;
        padding-top: 9px;
        padding-bottom: 10px;
    }

    #week-view.is-empty-week .week-day-col.is-empty-day,
    #week-view.is-empty-week .week-day-col:has(.week-no-items) {
        padding-top: 5px;
        padding-bottom: 6px;
    }

    #week-view .week-day-block-head {
        padding: 0;
        min-height: 0;
    }

    #week-view .week-day-list-label {
        font-size: 0.95rem;
        font-weight: 600;
        letter-spacing: 0.01em;
        color: var(--text-primary);
        opacity: 0.85;
    }

    #week-view .week-day-col.is-empty-day .week-day-list-label {
        color: var(--text-secondary);
        opacity: 0.38;
    }

    #week-view .week-day-col.is-today .week-day-list-label {
        font-size: 1.32rem;
        font-weight: 700;
        color: var(--text-primary);
        opacity: 1;
    }

    #week-view .week-day-col.is-today.is-empty-day .week-day-list-label {
        opacity: 0.78;
    }

    #week-view .week-day-col:has(.week-item) .week-day-items {
        padding-top: 6px;
    }

    #week-view .week-day-items {
        gap: 8px;
        padding-top: 2px;
    }

    #week-view .week-complete-btn {
        width: 28px;
        height: 28px;
        flex: 0 0 28px;
        font-size: 0.78rem;
        padding: 4px;
        margin: -4px -4px -4px 0;
        opacity: 0.82;
        border-color: color-mix(in srgb, var(--text-muted) 22%, var(--border-subtle));
    }

    /* Day headers show only the relative label, no day-of-month */
    .week-day-block-num {
        display: none;
    }

    /* Cards: lifted, lighter surface to contrast with the uniform background */
    #week-view .week-item {
        background: var(--surface-raised);
        border: 1px solid var(--border-subtle);
        box-shadow: var(--shadow-soft);
    }

    #habits-view .habit-card,
    #habits-view .habit-health-panel {
        background: var(--surface-raised);
        border: 1px solid var(--border-subtle);
        box-shadow: var(--shadow-soft);
    }

    /* Top widget tabs move to the bottom bar on mobile */
    .widget-tabs { display: none; }
    .widget-header {
        padding: 0;
        margin: 0;
        border: none;
        min-height: 0;
    }
    .widget-header:not(:has(.review-toggle:not(.hidden))) {
        display: none;
    }

    /* FAB rides above the tab bar */
    #mobile-ai-fab {
        bottom: calc(var(--mobile-tab-bar-height, var(--tab-bar-height)) + 14px);
    }

    #chat-column {
        height: var(--app-viewport-height, 100dvh);
        bottom: auto;
    }

    #onboarding-overlay {
        height: var(--app-viewport-height, 100dvh);
        max-height: var(--app-viewport-height, 100dvh);
    }

    #onboarding-card {
        max-height: min(calc(var(--app-viewport-height, 100dvh) - max(20px, env(safe-area-inset-top, 0px))), 720px);
    }

    @supports (height: 100lvh) {
        @media (display-mode: standalone) {
            html,
            body,
            #app-view,
            #chat-column,
            #onboarding-overlay {
                height: max(var(--app-viewport-height, 100dvh), 100lvh);
            }

            #app-view,
            #onboarding-overlay {
                max-height: max(var(--app-viewport-height, 100dvh), 100lvh);
            }

            #onboarding-card {
                max-height: min(calc(max(var(--app-viewport-height, 100dvh), 100lvh) - max(20px, env(safe-area-inset-top, 0px))), 720px);
            }
        }
    }

    :root:not([data-theme="light"]) #mobile-ai-fab .mind-orb-face {
        color: rgba(18, 14, 10, 0.9);
    }

    .widget-header:has(.review-toggle:not(.hidden)) {
        display: block;
        padding: 0 16px 8px;
    }

    .widget-header-main {
        width: 100%;
    }

    .review-toggle {
        width: 100%;
        justify-content: space-between;
        gap: 12px;
        min-height: 36px;
        padding: 8px 14px;
        border-radius: 999px;
        background: color-mix(in srgb, var(--surface-raised) 72%, transparent);
    }

    .review-toggle-label {
        color: var(--text-secondary);
        font-weight: 500;
    }

    .review-toggle-action {
        display: inline-flex;
        flex-shrink: 0;
        font-size: var(--fs-footnote);
        font-weight: 500;
        color: var(--accent-primary);
        letter-spacing: 0.01em;
    }

    .agenda-toolbar {
        padding: 4px 16px 10px;
    }

    .agenda-toolbar-primary {
        display: flex;
        align-items: center;
        gap: 12px;
        width: 100%;
        padding: 4px 4px 4px 2px;
        border: 1px solid color-mix(in srgb, var(--border-subtle) 68%, transparent);
        border-radius: 999px;
        background: color-mix(in srgb, var(--surface-raised) 55%, transparent);
        box-shadow: none;
        grid-template-columns: unset;
    }

    .agenda-period-nav {
        flex: 1;
        min-width: 0;
        width: auto;
        grid-template-columns: auto minmax(0, 1fr) auto;
        column-gap: 8px;
        padding-left: 4px;
        padding-right: 0;
    }

    .agenda-toolbar-actions {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
        padding-right: 2px;
    }

    .agenda-toolbar-actions::before {
        content: '';
        flex-shrink: 0;
        width: 1px;
        height: 20px;
        margin-right: 2px;
        background: color-mix(in srgb, var(--text-muted) 12%, transparent);
    }

    .agenda-nav-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        color: var(--text-muted);
        opacity: 0.72;
        font-size: 1.05rem;
    }

    .agenda-period-label {
        font-weight: 500;
    }

    .agenda-view-toggle-btn,
    .agenda-create-btn {
        flex-shrink: 0;
        box-sizing: border-box;
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        max-width: 38px;
        max-height: 38px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        border: 1px solid color-mix(in srgb, var(--text-muted) 16%, var(--border-subtle));
        background: color-mix(in srgb, var(--surface-raised) 38%, transparent);
        box-shadow: none;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    :root[data-theme="light"] .agenda-view-toggle-btn,
    :root[data-theme="light"] .agenda-create-btn {
        background: color-mix(in srgb, var(--surface-raised) 60%, transparent);
    }

    .agenda-view-toggle-btn {
        color: var(--text-secondary);
    }

    .agenda-toggle-icon {
        width: 21px;
        height: 21px;
    }

    .agenda-create-btn {
        color: var(--accent-primary);
        border-color: color-mix(in srgb, var(--accent-primary) 45%, var(--border-subtle));
    }

    .agenda-create-label {
        display: none;
    }

    .agenda-create-btn span:first-child {
        font-size: 1.22rem;
        font-weight: 500;
        line-height: 1;
        color: inherit;
        opacity: 1;
        transform: translateY(-1px);
    }

    .week-day-add-btn {
        display: none;
    }

    .week-day-col[data-date] {
        cursor: pointer;
        transition: background var(--duration-quick) var(--ease-standard);
    }

    .week-day-col[data-date]:active {
        background: color-mix(in srgb, var(--accent-primary) 6%, transparent);
    }

    #week-view .week-day-col.is-empty-day,
    #week-view .week-day-col:has(.week-no-items) {
        align-items: stretch;
    }

    #week-view .week-day-col.is-empty-day .week-day-items,
    #week-view .week-day-col:has(.week-no-items) .week-day-items {
        align-items: flex-start;
        padding: 0;
        min-height: 0;
    }

    #week-view .week-day-col.is-empty-day .week-no-items,
    #week-view .week-day-col:has(.week-no-items) .week-no-items {
        opacity: 1;
        padding: 0;
        min-height: 0;
    }

    .week-no-items-dash {
        display: none;
    }

    .week-day-free {
        display: inline;
        font-style: normal;
        font-weight: 400;
        font-size: 0.78rem;
        color: var(--text-muted);
        opacity: 0.72;
        padding: 2px 0 0;
        text-align: left;
        line-height: 1.35;
    }

    #week-view .widget-empty-inline {
        display: grid;
        grid-template-columns: 48px minmax(0, 1fr);
        align-items: start;
        column-gap: 14px;
        row-gap: 6px;
        margin: 12px 16px 0;
        padding: 18px 16px;
        max-width: none;
        text-align: left;
        opacity: 1;
        border: 1px solid color-mix(in srgb, var(--text-muted) 14%, var(--border-subtle));
        border-radius: var(--radius-md);
        background: color-mix(in srgb, var(--surface-raised) 90%, var(--bg-deep));
        box-shadow: none;
    }

    #week-view.is-empty-week .widget-empty-inline {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 14px;
        margin-top: -20px;
        margin-left: auto;
        margin-right: auto;
        padding: 8px 20px 0;
        max-width: 28ch;
        text-align: center;
        border: none;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }

    :root[data-theme="light"] #week-view .widget-empty-inline {
        background: rgba(255, 255, 255, 0.78);
        border-color: rgba(31, 28, 23, 0.1);
    }

    :root[data-theme="light"] #week-view.is-empty-week .widget-empty-inline {
        background: transparent;
        border: none;
    }

    #week-view .widget-empty-inline::before {
        grid-row: 1 / 3;
        align-self: center;
        width: 48px;
        height: 48px;
        margin: 0;
        border: none;
        border-radius: 0;
        opacity: 1;
        background: url('/images/agenda-week-empty.png?v=2') center / contain no-repeat;
    }

    #week-view.is-empty-week .widget-empty-inline::before {
        width: 76px;
        height: 76px;
        align-self: center;
    }

    #week-view.is-empty-week .widget-empty-inline .widget-empty-text,
    #week-view.is-empty-week .widget-empty-inline .widget-empty-hint {
        max-width: none;
        text-align: center;
    }

    #week-view .widget-empty-inline .widget-empty-text {
        font-family: var(--font-serif);
        font-size: 0.92rem;
        font-weight: 400;
        color: var(--text-secondary);
        line-height: 1.4;
    }

    #week-view.is-empty-week .widget-empty-inline .widget-empty-text {
        font-size: 1.02rem;
        color: var(--text-primary);
    }

    #week-view .widget-empty-inline .widget-empty-hint {
        font-family: var(--font-sans);
        font-size: 0.74rem;
        color: var(--text-muted);
        line-height: 1.45;
        max-width: none;
        opacity: 0.9;
    }

    #week-view.is-empty-week .widget-empty-inline .widget-empty-hint {
        font-size: 0.8rem;
        line-height: 1.5;
        opacity: 0.85;
    }

}
