/* FullWorth cross-surface UI hardening.
   Keep this layer focused on behavior-safe polish that must win over page CSS. */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
}

body .theme-toggle {
    width: 44px;
    height: 44px;
}

.legal-standalone-layout {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bw-bg);
}

.legal-theme-control {
    position: fixed;
    z-index: 40;
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(16px + env(safe-area-inset-bottom));
}

.legal-theme-control .theme-toggle {
    background: var(--bw-header-bg);
    box-shadow: 0 14px 38px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(22px) saturate(135%);
    -webkit-backdrop-filter: blur(22px) saturate(135%);
}

.legal-page a:focus-visible,
.system-page a:focus-visible,
.legal-theme-control button:focus-visible {
    outline: 2px solid rgba(91, 109, 248, 0.78);
    outline-offset: 3px;
}

html[data-theme="light"] .legal-page {
    color: var(--bw-text);
    background:
        radial-gradient(circle at 8% 0%, rgba(44, 93, 221, 0.09), transparent 28%),
        radial-gradient(circle at 92% 12%, rgba(94, 68, 238, 0.07), transparent 30%),
        var(--bw-bg);
}

html[data-theme="light"] .legal-topbar {
    border-bottom-color: var(--bw-border);
    background: var(--bw-header-bg);
}

html[data-theme="light"] .legal-brand,
html[data-theme="light"] .legal-nav a:hover,
html[data-theme="light"] .legal-nav a.is-active,
html[data-theme="light"] .legal-hero h1,
html[data-theme="light"] .legal-callout strong,
html[data-theme="light"] .legal-document section h2 {
    color: var(--bw-text);
}

html[data-theme="light"] .legal-nav a,
html[data-theme="light"] .legal-lead,
html[data-theme="light"] .legal-callout,
html[data-theme="light"] .legal-document section p,
html[data-theme="light"] .legal-document section li,
html[data-theme="light"] .legal-endnote {
    color: var(--bw-text-muted);
}

html[data-theme="light"] .legal-nav a:hover,
html[data-theme="light"] .legal-nav a.is-active,
html[data-theme="light"] .legal-toc a:hover {
    background: rgba(91, 109, 248, 0.08);
}

html[data-theme="light"] .legal-hero,
html[data-theme="light"] .legal-toc {
    border-color: var(--bw-border);
    background:
        radial-gradient(circle at 100% 0, rgba(67, 82, 223, 0.08), transparent 36%),
        var(--bw-surface-soft);
    box-shadow: var(--bw-card-shadow);
}

html[data-theme="light"] .legal-toc a,
html[data-theme="light"] .legal-meta,
html[data-theme="light"] .legal-toc-label {
    color: var(--bw-text-subtle);
}

html[data-theme="light"] .legal-document section {
    border-bottom-color: var(--bw-border);
}

html[data-theme="light"] .legal-callout {
    border-color: rgba(67, 124, 247, 0.16);
    background: rgba(45, 92, 196, 0.055);
}

html[data-theme="light"] .legal-endnote {
    border-color: rgba(194, 132, 24, 0.18);
    background: rgba(194, 132, 24, 0.06);
}

.system-page {
    width: min(100% - 32px, 760px);
    min-height: min(680px, calc(100dvh - 80px));
    margin: 0 auto;
    padding: 72px 0 92px;
    box-sizing: border-box;
    display: grid;
    place-items: center;
}

.system-card {
    width: 100%;
    padding: clamp(28px, 6vw, 52px);
    box-sizing: border-box;
    border: 1px solid var(--bw-border);
    border-radius: 30px;
    background:
        radial-gradient(circle at 100% 0%, rgba(91, 109, 248, 0.12), transparent 22rem),
        linear-gradient(155deg, rgba(255, 255, 255, 0.035), transparent 48%),
        var(--bw-surface-soft);
    color: var(--bw-text);
    box-shadow: 0 28px 82px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(26px) saturate(125%);
    -webkit-backdrop-filter: blur(26px) saturate(125%);
}

html:not([data-theme="light"]) .system-card,
html[data-theme="dark"] .system-card {
    box-shadow: 0 32px 90px rgba(0, 0, 0, 0.36);
}

.system-icon {
    width: 62px;
    height: 62px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(91, 109, 248, 0.18);
    border-radius: 20px;
    background: rgba(91, 109, 248, 0.11);
    color: #8e9dff;
    font-size: 0.84rem;
    font-weight: 850;
    letter-spacing: 0.03em;
}

.system-icon-error {
    border-color: rgba(229, 111, 103, 0.2);
    background: rgba(229, 111, 103, 0.1);
    color: #e9837d;
    font-size: 1.35rem;
}

.system-kicker {
    display: block;
    margin-top: 26px;
    color: #8796ff;
    font-size: 0.67rem;
    font-weight: 820;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.system-card h1 {
    max-width: 620px;
    margin: 10px 0 14px;
    color: var(--bw-text);
    font-size: clamp(2.25rem, 7vw, 3.75rem);
    line-height: 0.98;
    font-weight: 770;
    letter-spacing: -0.06em;
}

.system-card > p {
    max-width: 610px;
    margin: 0;
    color: var(--bw-text-muted);
    font-size: 0.92rem;
    line-height: 1.7;
}

.system-request-id {
    max-width: 100%;
    margin-top: 24px;
    padding: 13px 15px;
    display: grid;
    gap: 5px;
    border: 1px solid var(--bw-border);
    border-radius: 13px;
    background: var(--bw-bg-elevated);
}

.system-request-id span {
    color: var(--bw-text-subtle);
    font-size: 0.65rem;
    font-weight: 760;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.system-request-id code {
    max-width: 100%;
    overflow-wrap: anywhere;
    color: var(--bw-text-secondary);
    font-size: 0.75rem;
}

.system-actions {
    margin-top: 30px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.system-primary-action,
.system-secondary-action {
    min-height: 46px;
    padding: 0 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    color: inherit;
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 760;
}

.system-primary-action {
    border: 1px solid rgba(91, 109, 248, 0.18);
    background: linear-gradient(145deg, #435ef1, #697aff);
    color: #fff;
    box-shadow: 0 13px 32px rgba(70, 96, 242, 0.24);
}

.system-primary-action:hover {
    color: #fff;
}

.system-secondary-action {
    border: 1px solid var(--bw-border);
    background: var(--bw-surface-soft);
    color: var(--bw-text-secondary);
}

@media (max-width: 900px) {
    .app-shell {
        min-height: 100dvh !important;
    }

    .app-shell .app-topbar {
        height: calc(68px + env(safe-area-inset-top)) !important;
        padding-top: env(safe-area-inset-top) !important;
    }

    .site-shell .site-header {
        padding-top: env(safe-area-inset-top);
    }

    .site-shell .site-footer {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .legal-topbar {
        padding-top: calc(14px + env(safe-area-inset-top)) !important;
    }

    .settings-toast,
    .subscription-toast {
        top: calc(72px + env(safe-area-inset-top)) !important;
    }

    .app-shell .app-sidebar {
        bottom: calc(10px + env(safe-area-inset-bottom)) !important;
        height: 72px !important;
        padding: 6px !important;
    }

    .app-shell .app-content {
        padding-bottom: calc(132px + env(safe-area-inset-bottom)) !important;
    }

    .mobile-menu-backdrop {
        position: fixed;
        z-index: 110;
        inset: 0 0 calc(94px + env(safe-area-inset-bottom)) 0;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: color-mix(in srgb, var(--bw-bg) 24%, transparent);
        cursor: default;
        backdrop-filter: blur(12px) saturate(86%);
        -webkit-backdrop-filter: blur(12px) saturate(86%);
    }

    .mobile-more-menu.is-open::before {
        display: none !important;
    }

    .mobile-menu-sheet {
        max-height: min(calc(100dvh - 176px - env(safe-area-inset-bottom) - env(safe-area-inset-top)), 520px) !important;
    }
}

@media (max-width: 600px) {
    .site-shell .header-actions .header-action:last-child {
        display: inline-flex;
    }

    .bills-heading-summary {
        display: flex !important;
        flex-wrap: wrap;
        white-space: normal !important;
    }

    .bills-heading-summary .summary-divider {
        display: none;
    }
}

@media (max-width: 520px) {
    .app-shell .app-sidebar {
        left: 8px !important;
        right: 8px !important;
        bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    }

    .system-page {
        width: min(100% - 24px, 760px);
        padding: 44px 0 70px;
    }

    .system-card {
        border-radius: 24px;
    }

    .system-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .system-primary-action,
    .system-secondary-action {
        width: 100%;
        box-sizing: border-box;
    }
}

@media (max-width: 900px) and (pointer: coarse) {
    .site-shell input:not([type="checkbox"]):not([type="radio"]),
    .site-shell select,
    .site-shell textarea,
    .app-shell input:not([type="checkbox"]):not([type="radio"]),
    .app-shell select,
    .app-shell textarea {
        font-size: 16px !important;
    }
}

@media (pointer: coarse) {
    .bill-filter,
    .activity-filter,
    .alert-secondary-action,
    .alert-primary-action,
    .statement-upload-button,
    .privacy-primary-button,
    .danger-button,
    .cancel-delete-button,
    .final-delete-button,
    .subscription-action,
    .settings-actions button,
    .recovery-code-panel button,
    .admin-primary-button,
    .admin-secondary-button,
    .admin-danger-button,
    .admin-refresh-button,
    .legal-nav a,
    .legal-toc a {
        min-height: 44px !important;
    }

    .legal-nav a,
    .legal-toc a {
        display: inline-flex;
        align-items: center;
    }
}

@media (hover: none) {
    .app-shell a:hover,
    .app-shell button:hover,
    .site-shell a:hover,
    .site-shell button:hover {
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .system-card,
    .system-card *,
    .mobile-menu-backdrop,
    .mobile-menu-sheet {
        animation: none !important;
        transition: none !important;
    }
}
