/* App shell, header, mobile bottom navigation, family workspace and dashboard. Tokens: tokens.css. */

/* ---------- Shell ---------- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
/* viewport-fit=cover: keep content clear of a notch or system bar at the sides. */
.site-header, main { padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
main { flex: 1; min-width: 0; }
.skip-link { position: absolute; top: -100px; left: 1rem; z-index: var(--tm-z-alert); padding: .8rem 1.2rem; border-radius: var(--tm-r-full); background: var(--tm-primary); color: var(--tm-on-primary); }
.skip-link:focus { top: .5rem; color: var(--tm-on-primary); }
.site-header { position: sticky; top: 0; z-index: var(--tm-z-header); border-bottom: 1px solid var(--tm-line); background: var(--tm-glass); -webkit-backdrop-filter: blur(16px) saturate(1.4); backdrop-filter: blur(16px) saturate(1.4); }
.header-inner { position: relative; display: flex; align-items: center; gap: 1.5rem; max-width: var(--tm-page-max); min-height: var(--tm-header-h); margin: auto; padding: 0 var(--tm-gutter); }
.brand { display: inline-flex; align-items: center; text-decoration: none; white-space: nowrap; --brand-icon-size: 34px; --brand-text-size: 1.4rem; }
.primary-nav { display: flex; align-items: center; gap: 4px; }
.primary-nav a { display: inline-flex; align-items: center; min-height: var(--tm-touch); padding: 0 .9rem; border-radius: var(--tm-r-full); color: var(--tm-ink-2); font-size: var(--tm-text-sm); font-weight: 600; text-decoration: none; white-space: nowrap; transition: background-color var(--tm-fast) var(--tm-ease), color var(--tm-fast) var(--tm-ease); }
.primary-nav a:hover { background: var(--tm-surface-2); color: var(--tm-ink); }
.primary-nav a.active { background: var(--tm-primary-soft); color: var(--tm-on-primary-soft); }
#blazor-error-ui { display: none; position: fixed; inset: auto 0 0; z-index: var(--tm-z-alert); padding: 1rem 3rem 1rem 1.5rem; background: var(--tm-warning-soft); color: var(--tm-warning); box-shadow: var(--tm-e-2); }
#blazor-error-ui .reload { margin-left: .75rem; color: inherit; }
#blazor-error-ui .dismiss { position: absolute; top: .65rem; right: 1rem; border: 0; background: transparent; color: inherit; font-size: 1.5rem; cursor: pointer; }

/* ---------- Mobile bottom navigation (compact width only) ---------- */
.bottom-nav { display: none; }
.bottom-nav a { display: grid; justify-items: center; gap: 2px; min-width: 0; padding: 2px 0; border-radius: var(--tm-r-sm); color: var(--tm-ink-2); font-size: var(--tm-text-caption); font-weight: 600; line-height: 1.3; text-decoration: none; }
.bottom-nav-icon { display: grid; place-items: center; width: 56px; height: 30px; border-radius: var(--tm-r-full); transition: background-color var(--tm-fast) var(--tm-ease); }
.bottom-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bottom-nav a.active { color: var(--tm-on-primary-soft); }
.bottom-nav a.active .bottom-nav-icon { background: var(--tm-primary-soft); }
.bottom-nav-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Header tools ---------- */
.header-account-tools { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.header-account-tools > .account-link { display: inline-flex; align-items: center; min-height: var(--tm-touch); padding: 0 1rem; border-radius: var(--tm-r-full); background: var(--tm-primary-soft); color: var(--tm-on-primary-soft); font-size: var(--tm-text-sm); font-weight: 650; text-decoration: none; white-space: nowrap; }
.header-tools { display: flex; align-items: center; gap: .25rem; }
.header-tools .header-menu { position: relative; }
.header-tools .header-menu > summary { display: inline-flex; align-items: center; gap: .3rem; min-height: var(--tm-touch); padding: 0 .9rem; border-radius: var(--tm-r-full); color: var(--tm-ink); font-size: var(--tm-text-sm); font-weight: 600; list-style: none; white-space: nowrap; }
.header-tools .header-menu > summary::-webkit-details-marker { display: none; }
.header-tools .header-menu > summary:hover, .header-tools .header-menu[open] > summary { background: var(--tm-surface-2); }
.header-tools .header-menu > .account-trigger { display: grid; place-items: center; min-width: var(--tm-touch); padding: 0; cursor: pointer; }
.account-seal { display: grid; place-items: center; min-width: var(--tm-s-8); height: var(--tm-s-8); padding-inline: var(--tm-s-1); border-radius: var(--tm-r-xs); background: var(--tm-primary); color: var(--tm-on-primary); font-size: var(--tm-text-label); }
.header-tools .notification-trigger { position: relative; display: grid; place-items: center; width: var(--tm-touch); min-height: var(--tm-touch); padding: 0; border-radius: 50%; }
.bell-icon { display: block; width: 26px; height: 26px; background: currentColor; -webkit-mask: var(--tm-icon-bell) center / contain no-repeat; mask: var(--tm-icon-bell) center / contain no-repeat; }
.unread-dot { position: absolute; top: 8px; right: 9px; width: 9px; height: 9px; border: 2px solid var(--tm-surface); border-radius: 50%; background: var(--tm-accent); }
.header-flyout { position: absolute; top: calc(100% + 8px); right: 0; z-index: var(--tm-z-flyout); padding: 1rem; border: 1px solid var(--tm-line); border-radius: var(--tm-r-lg); background: var(--tm-surface); color: var(--tm-ink); box-shadow: var(--tm-e-2); }
.account-flyout { width: 220px; padding: 8px; }
.account-flyout .account-link { display: flex; align-items: center; width: 100%; min-height: var(--tm-touch); padding: 0 14px; border: 0; border-radius: var(--tm-r-sm); background: transparent; color: var(--tm-ink); font-size: var(--tm-text-sm); font-weight: 500; text-align: left; text-decoration: none; }
.account-flyout .account-link:hover { background: var(--tm-surface-2); }
.account-flyout form { margin: 0; }
.account-flyout .language-menu > summary { display: flex; align-items: center; justify-content: space-between; min-height: var(--tm-touch); padding: 0 14px; border-radius: var(--tm-r-sm); color: var(--tm-ink-2); font-size: var(--tm-text-sm); font-weight: 500; }
.account-flyout .language-menu .language-selector { position: static; min-width: 0; padding: .25rem; border: 0; box-shadow: none; }
.notification-flyout { width: 340px; max-width: calc(100vw - 2 * var(--tm-gutter)); }
.notification-flyout .card-heading { align-items: center; gap: 8px; margin-bottom: 4px; }
.notification-flyout h2 { margin: 0; font-size: 1rem; }
.notification-flyout .btn-link { min-height: 40px; padding: .25rem 0; font-size: var(--tm-text-caption); }
.header-notifications { max-height: 55vh; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.header-notifications li { padding: 12px 0 6px; border-top: 1px solid var(--tm-line); }
.header-notifications a { display: block; color: var(--tm-ink); font-size: var(--tm-text-sm); font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.header-notifications small { display: block; margin-top: 4px; color: var(--tm-ink-2); font-size: var(--tm-text-caption); }
.header-notifications .notification-meta { overflow-wrap: anywhere; }
.header-notifications .is-unread a::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--tm-accent); vertical-align: middle; }
.header-notifications .is-read { opacity: .65; }

/* ---------- Settings dialog ---------- */
.account-settings-dialog { width: min(500px, calc(100% - 28px)); max-height: 85vh; padding: 1.5rem; border: 1px solid var(--tm-line); border-radius: var(--tm-r-lg); background: var(--tm-surface); color: var(--tm-ink); box-shadow: var(--tm-e-3); }
.account-settings-dialog::backdrop { background: var(--tm-scrim); }
.account-settings-dialog .card-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 1.25rem; }
.account-settings-dialog h2 { margin: 0; font-size: var(--tm-text-h2); }
.account-settings-dialog .card-heading .btn { min-width: var(--tm-touch); min-height: var(--tm-touch); padding: 0; border-radius: 50%; color: var(--tm-ink-2); font-size: 1.5rem; text-decoration: none; }
.account-settings-dialog .card-heading .btn:hover { background: var(--tm-surface-2); text-decoration: none; }
.account-settings-dialog > label { display: block; margin-bottom: 8px; font-size: var(--tm-text-label); font-weight: 600; }
.settings-emails { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--tm-line); }
.settings-emails h3 { font-size: 1rem; }
.notification-preference { display: flex; align-items: center; gap: 12px; min-height: var(--tm-touch); }
.notification-preference input { flex-shrink: 0; width: 20px; height: 20px; accent-color: var(--tm-primary); }
.notification-preference span { overflow-wrap: anywhere; }
.settings-actions { margin-top: 1.25rem; }

/* ---------- Family workspace ---------- */
.family-workspace { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: 2rem; }
.workspace-body { min-width: 0; }
.space-icon { display: inline-flex; flex: none; align-items: center; justify-content: center; font-size: 0; line-height: 0; }
.space-icon::before { content: ""; background: currentColor; -webkit-mask: var(--tm-icon-home) center / contain no-repeat; mask: var(--tm-icon-home) center / contain no-repeat; }
.workspace-heading { display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.workspace-heading h1 { margin: 0; }
.workspace-body .spaces-recent { margin: 0; }
.spaces-recent > .card-heading { margin-bottom: .5rem; }
.spaces-actions { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; width: 100%; }
.workspace-body .memory-capsule-grid { gap: 12px 18px; padding-top: 1.1rem; }
.memory-capsule-item { color: inherit; font: inherit; cursor: pointer; }
.spaces-empty { border: 0; }
.workspace-body > .workflow-card > h2 { font-size: var(--tm-text-h3); }
.workspace-body > .workflow-card > ul { margin: 0; padding: 0; list-style: none; }
.workspace-body > .workflow-card > ul > li { padding: 1rem 0; border-bottom: 1px solid var(--tm-line); overflow-wrap: anywhere; }
.workspace-body > .workflow-card > ul > li:last-child { border-bottom: 0; }
.workspace-body > .workflow-card > ul > li > .btn { font-size: var(--tm-text-label); }

/* ---------- Home dashboard ---------- */
.dashboard-overview { display: block; }
.dashboard-page .next-action-panel { padding: clamp(1.25rem, 3vw, 2rem); border: 1px solid var(--tm-line); border-radius: var(--tm-r-lg); background: var(--tm-surface); }
.next-action-panel > .eyebrow { display: block; margin-bottom: .75rem; }
.next-action-panel .next-summary { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: 1.5rem; }
.next-summary h2 { margin: 0 0 .35rem; font-size: clamp(1.4rem, 3vw, 1.75rem); letter-spacing: -.03em; }
.next-summary p { margin: 0 0 .75rem; color: var(--tm-ink-2); font-size: var(--tm-text-sm); }
.next-summary small { display: inline-flex; align-items: center; padding: .25rem .7rem; border-radius: var(--tm-r-full); background: var(--tm-surface-2); color: var(--tm-ink-2); font-size: var(--tm-text-caption); font-weight: 600; }
.next-summary .home-next-actions { margin-top: 1.25rem; }
.home-capsule { position: relative; min-width: 0; border-radius: var(--tm-r-md); background: radial-gradient(120% 90% at 50% 0%, var(--tm-primary-soft), transparent 70%); isolation: isolate; }
.home-capsule .memory-capsule-item { min-height: 200px; }
.family-chooser .family-space-grid { gap: 8px; }
.dashboard-page .family-space-grid a { padding: .75rem 1rem; border: 1px solid var(--tm-line); border-radius: var(--tm-r-md); background: var(--tm-surface); transition: border-color var(--tm-fast) var(--tm-ease), background-color var(--tm-fast) var(--tm-ease); }
.dashboard-page .family-space-grid a:hover { border-color: var(--tm-line-strong); background: var(--tm-surface); }
.family-space-grid .space-icon { width: 44px; height: 44px; border-radius: var(--tm-r-md); background: var(--tm-primary-soft); color: var(--tm-on-primary-soft); }
.family-space-grid .space-icon::before { width: 20px; height: 20px; }
.family-space-grid a:nth-child(even) .space-icon { background: var(--tm-accent-soft); color: var(--tm-accent-ink); }

/* ---------- Responsive ---------- */
@media (max-width: 839.98px) {
    .family-workspace { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 699.98px) {
    .next-action-panel .next-summary { grid-template-columns: 1fr; gap: 1rem; }
    .home-capsule { grid-row: 1; width: 100%; }
    .home-capsule .memory-capsule-item { min-height: 170px; }
    .next-summary .home-next-actions .btn { width: 100%; }
}
@media (max-width: 599.98px) {
    .header-inner { gap: .5rem; }
    .brand { --brand-icon-size: 30px; --brand-text-size: 1.25rem; }
    .primary-nav { display: none; }
    .header-tools .notification-menu { position: static; }
    .notification-flyout { left: var(--tm-gutter); right: var(--tm-gutter); width: auto; max-width: none; }
    .bottom-nav { position: fixed; inset: auto 0 0; z-index: var(--tm-z-nav); display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); border-top: 1px solid var(--tm-line); background: var(--tm-glass); -webkit-backdrop-filter: blur(16px) saturate(1.4); backdrop-filter: blur(16px) saturate(1.4); }
    .app-shell:has(.bottom-nav) { padding-bottom: calc(var(--tm-bottom-nav-h) + env(safe-area-inset-bottom, 0px)); }
    /* Focused work hides the tab bar: writing or managing a capsule, or typing with the on-screen keyboard open. */
    .app-shell:has(.capsule-focused-view[data-capsule-task]:not([data-capsule-task="overview"])) .bottom-nav,
    .app-shell:has(textarea:focus, input:not([type="checkbox"], [type="radio"], [type="file"], [type="button"], [type="submit"]):focus) .bottom-nav { display: none; }
    /* A focused control must not end up under the fixed tab bar. */
    html:has(.bottom-nav) { scroll-padding-bottom: calc(var(--tm-bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 1rem); }
    .account-settings-dialog { width: 100%; max-width: none; max-height: 88dvh; margin: auto 0 0; padding: 1.25rem var(--tm-gutter) calc(1.25rem + env(safe-area-inset-bottom, 0px)); border-width: 1px 0 0; border-radius: var(--tm-r-lg) var(--tm-r-lg) 0 0; }
    .spaces-actions .btn { font-size: var(--tm-text-label); }
}
