/*
 * MyBook UI foundation
 * A final, presentation-only layer shared by desktop, minimal, mobile and auth views.
 */

:root {
    --ui-bg: #f5f6f8;
    --ui-surface: #ffffff;
    --ui-surface-muted: #f8f9fb;
    --ui-surface-raised: #ffffff;
    --ui-border: #e1e4e9;
    --ui-border-strong: #c8ced8;
    --ui-text: #1d2433;
    --ui-text-muted: #626b7a;
    --ui-primary: #293b74;
    --ui-primary-hover: #1f2f61;
    --ui-primary-soft: #eef1f8;
    --ui-success: #267053;
    --ui-success-soft: #edf7f2;
    --ui-warning: #91651f;
    --ui-warning-soft: #fbf5e9;
    --ui-danger: #a33b45;
    --ui-danger-soft: #fbf0f1;
    --ui-info: #35627b;
    --ui-info-soft: #edf4f7;
    --ui-radius-xs: 4px;
    --ui-radius-sm: 6px;
    --ui-radius: 8px;
    --ui-radius-lg: 10px;
    --ui-shadow-sm: 0 1px 2px rgba(20, 27, 40, 0.05);
    --ui-shadow: 0 8px 24px rgba(20, 27, 40, 0.09);
    --ui-focus: 0 0 0 3px rgba(41, 59, 116, 0.18);
    --ui-control-height: 40px;
    --ui-content-width: 1240px;
    --ui-space-1: 0.25rem;
    --ui-space-2: 0.5rem;
    --ui-space-3: 0.75rem;
    --ui-space-4: 1rem;
    --ui-space-5: 1.5rem;
    --ui-space-6: 2rem;
}

html {
    color-scheme: light;
    background: var(--ui-bg);
}

body {
    color: var(--ui-text) !important;
    background: var(--ui-bg) !important;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif !important;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

:where(h1, h2, h3, h4, h5, h6) {
    color: var(--ui-text);
    font-weight: 650;
    line-height: 1.25;
    letter-spacing: -0.015em;
}

:where(p, small, .text-muted, .help-text, .form-text) {
    color: var(--ui-text-muted);
}

:where(.amount, .balance, .stat-value, td[data-amount]) {
    font-variant-numeric: tabular-nums;
}

a {
    color: var(--ui-primary);
    text-underline-offset: 0.18em;
}

a:hover {
    color: var(--ui-primary-hover);
}

button,
input,
select,
textarea {
    font: inherit;
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--ui-primary) !important;
    outline-offset: 2px;
    box-shadow: var(--ui-focus) !important;
}

:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="hidden"]), select, textarea, .form-control, .form-select) {
    min-height: var(--ui-control-height);
    border: 1px solid var(--ui-border-strong) !important;
    border-radius: var(--ui-radius-sm) !important;
    background-color: var(--ui-surface) !important;
    color: var(--ui-text) !important;
}

:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="hidden"]), select, textarea, .form-control, .form-select):hover {
    border-color: #9dacc0 !important;
}

:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="hidden"]), select, textarea, .form-control, .form-select):focus {
    border-color: var(--ui-primary) !important;
    outline: none !important;
    box-shadow: var(--ui-focus) !important;
}

:where(input, textarea)::placeholder {
    color: #89919e;
    opacity: 1;
}

:where(label, .form-label) {
    color: #3f4857 !important;
    font-weight: 600 !important;
}

:where(.btn, button.btn, a.btn, .mobile-btn) {
    min-height: var(--ui-control-height);
    border-radius: var(--ui-radius-sm) !important;
    border: 1px solid transparent !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.62rem 1rem !important;
    font-weight: 600 !important;
    line-height: 1.2 !important;
    text-decoration: none !important;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease !important;
}

:where(.btn-primary, .mobile-btn:not(.secondary):not(.danger), button[type="submit"]):not(.btn-secondary):not(.btn-danger):not(.btn-warning):not(.btn-success) {
    background: var(--ui-primary) !important;
    border-color: var(--ui-primary) !important;
    color: #fff !important;
}

:where(.btn-primary, .mobile-btn:not(.secondary):not(.danger), button[type="submit"]):not(.btn-secondary):not(.btn-danger):not(.btn-warning):not(.btn-success):hover {
    background: var(--ui-primary-hover) !important;
    border-color: var(--ui-primary-hover) !important;
    color: #fff !important;
}

.btn-secondary,
.mobile-btn.secondary {
    background: var(--ui-surface) !important;
    border-color: var(--ui-border-strong) !important;
    color: #344258 !important;
}

.btn-secondary:hover,
.mobile-btn.secondary:hover {
    background: var(--ui-surface-muted) !important;
    border-color: #9dacc0 !important;
    color: var(--ui-text) !important;
}

.btn-success { background: var(--ui-success) !important; color: #fff !important; }
.btn-warning { background: var(--ui-warning) !important; color: #fff !important; }
.btn-danger, .mobile-btn.danger { background: var(--ui-danger) !important; color: #fff !important; }

:where(.btn, button.btn, a.btn, .mobile-btn):disabled,
:where(.btn, button.btn, a.btn, .mobile-btn)[aria-disabled="true"] {
    cursor: not-allowed !important;
    opacity: 0.56;
    box-shadow: none !important;
}

:where(.card, .welcome, .stat-card, .chart-card, .settings-card, .report-card, .account-card, .ledger-card, .form-card, .form-container, .filter-card, .summary-card, .page-title-card, .ledgers-container, .transactions-container, .mobile-card, .mobile-card-item) {
    background: var(--ui-surface) !important;
    border: 1px solid var(--ui-border) !important;
    border-radius: var(--ui-radius) !important;
    box-shadow: none !important;
}

:where(.card-header, .modal-header) {
    background: var(--ui-surface-muted) !important;
    border-bottom: 1px solid var(--ui-border) !important;
}

:where(.alert, .error, .success) {
    border: 1px solid currentColor !important;
    border-left-width: 4px !important;
    border-radius: var(--ui-radius-sm) !important;
    box-shadow: none !important;
}

.alert-success, .success { color: #126747 !important; background: var(--ui-success-soft) !important; }
.alert-warning { color: #80500b !important; background: var(--ui-warning-soft) !important; }
.alert-danger, .error { color: #a32934 !important; background: var(--ui-danger-soft) !important; }
.alert-info { color: #145d89 !important; background: var(--ui-info-soft) !important; }

:where(table, .table) {
    width: 100%;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
}

:where(table, .table) thead th {
    background: var(--ui-surface-muted) !important;
    color: #515b6b !important;
    border-bottom: 1px solid var(--ui-border-strong) !important;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.025em;
    text-transform: none;
}

:where(table, .table) tbody td {
    border-color: #e8eaee !important;
    vertical-align: middle;
}

:where(table, .table) tbody tr:hover {
    background: var(--ui-surface-muted) !important;
}

:where(.modal-content, .dialog-content, .confirm-dialog-content) {
    background: var(--ui-surface) !important;
    border: 1px solid var(--ui-border) !important;
    border-radius: var(--ui-radius-lg) !important;
    box-shadow: var(--ui-shadow) !important;
}

:where(.modal, .modal-overlay, .dialog-overlay) {
    background-color: rgba(22, 28, 40, 0.48) !important;
    backdrop-filter: none !important;
}

.app-shell .topbar {
    min-height: 60px;
    background: var(--ui-surface) !important;
    border-bottom: 1px solid var(--ui-border) !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
}

.app-shell .topbar > .page-width {
    width: 100% !important;
    max-width: var(--ui-content-width) !important;
    min-height: 60px;
    margin: 0 auto !important;
    padding: 0 24px !important;
    gap: 24px;
}

.app-shell .topbar-main {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 28px;
}

.app-shell .logo-section {
    flex: 0 0 auto;
}

.app-shell .main-logo,
.app-shell .logo-text {
    color: var(--ui-text) !important;
    font-weight: 700 !important;
    letter-spacing: -0.03em;
    text-decoration: none;
}

.app-shell .main-nav {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 2px;
}

.app-shell :where(.nav-item, .nav-dropdown-toggle) {
    min-height: 40px;
    border-radius: var(--ui-radius-xs) !important;
    color: #4d5665 !important;
    font-weight: 550 !important;
    padding: 0.55rem 0.7rem !important;
}

.app-shell :where(.nav-item, .nav-dropdown-toggle):hover,
.app-shell :where(.nav-item.active, .nav-dropdown-toggle.active) {
    background: var(--ui-surface-muted) !important;
    color: var(--ui-primary) !important;
}

.app-shell .nav-item.active,
.app-shell .nav-dropdown-toggle.active {
    box-shadow: inset 0 -2px 0 var(--ui-primary);
}

.app-shell .nav-dropdown-menu {
    background: var(--ui-surface) !important;
    border: 1px solid var(--ui-border) !important;
    border-radius: var(--ui-radius-sm) !important;
    box-shadow: var(--ui-shadow) !important;
    padding: 0.35rem !important;
}

.app-shell .nav-dropdown-item {
    border-radius: var(--ui-radius-xs) !important;
    color: #4d5665 !important;
}

.app-shell .nav-dropdown-item:hover,
.app-shell .nav-dropdown-item.active {
    background: var(--ui-surface-muted) !important;
    color: var(--ui-primary) !important;
}

.app-shell .topbar-right {
    flex: 0 0 auto !important;
    column-gap: 8px !important;
}

.app-shell .settings-icon {
    color: var(--ui-text-muted) !important;
    border-radius: var(--ui-radius-xs) !important;
    transform: none !important;
}

.app-shell .settings-icon:hover {
    color: var(--ui-primary) !important;
    background: var(--ui-surface-muted) !important;
    transform: none !important;
}

.app-shell .user-info {
    color: var(--ui-text-muted) !important;
    transform: none !important;
}

.app-shell .main-content {
    background: var(--ui-bg) !important;
}

.app-shell .main-content > .page-width {
    width: 100% !important;
    max-width: var(--ui-content-width) !important;
    margin: 0 auto !important;
    padding: clamp(1.25rem, 2vw, 2rem) 24px 3rem !important;
}

.minimal-layout {
    background: var(--ui-bg) !important;
}

.minimal-content {
    max-width: 760px !important;
    padding: clamp(1rem, 4vw, 2.5rem) !important;
}

.minimal-content > :where(.container, .card, form) {
    width: 100%;
}

.mobile-header {
    height: 60px !important;
    background: var(--ui-primary) !important;
    box-shadow: none !important;
}

.mobile-content {
    margin-top: 60px !important;
    padding: 16px !important;
    background: var(--ui-bg) !important;
}

.mobile-sidebar {
    top: 60px !important;
    height: calc(100dvh - 60px) !important;
    border-right: 1px solid var(--ui-border) !important;
    box-shadow: 8px 0 24px rgba(20, 27, 40, 0.12) !important;
}

.mobile-sidebar .nav-item,
.mobile-sidebar .logout-btn {
    min-height: 48px;
    border-bottom-color: #edf1f5 !important;
}

.mobile-sidebar .nav-item:hover,
.mobile-sidebar .nav-item.active {
    background: var(--ui-primary-soft) !important;
    color: var(--ui-primary) !important;
}

.mobile-fab {
    min-width: 56px;
    min-height: 56px;
    background: var(--ui-primary) !important;
    box-shadow: 0 4px 12px rgba(20, 27, 40, 0.16) !important;
}

body.ui-auth,
body.ui-welcome {
    min-height: 100dvh;
    padding: clamp(1rem, 4vw, 2.5rem);
    background: var(--ui-bg) !important;
}

body.ui-auth :where(.login-container, .register-container),
body.ui-welcome > .container {
    background: var(--ui-surface) !important;
    border: 1px solid var(--ui-border) !important;
    border-radius: var(--ui-radius-lg) !important;
    box-shadow: var(--ui-shadow-sm) !important;
}

body.ui-auth :where(.login-container, .register-container) {
    width: min(100%, 430px) !important;
    max-width: 430px !important;
    padding: clamp(1.5rem, 5vw, 2.5rem) !important;
}

body.ui-auth .logo h1,
body.ui-welcome .logo {
    color: var(--ui-text) !important;
    letter-spacing: -0.035em;
}

body.ui-auth .form-group {
    margin-bottom: 1.15rem !important;
}

body.ui-auth .links {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.4rem 0.8rem;
}

body.ui-auth .links a {
    margin: 0 !important;
    font-weight: 600;
}

body.ui-welcome > .container {
    max-width: 760px !important;
    padding: clamp(1.5rem, 5vw, 3rem) !important;
}

body.ui-welcome .feature,
body.ui-welcome .info,
body.ui-welcome .status {
    border: 1px solid var(--ui-border) !important;
    border-left-width: 4px !important;
    border-radius: var(--ui-radius) !important;
    box-shadow: none !important;
}

body.ui-welcome .feature,
body.ui-welcome .info {
    background: var(--ui-surface-muted) !important;
}

body.ui-welcome .status {
    background: var(--ui-success-soft) !important;
    color: #126747 !important;
    border-color: #75c6a7 !important;
}

body.ui-welcome .features {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)) !important;
}

@media (max-width: 768px) {
    :root { --ui-control-height: 44px; }

    .app-shell .main-content > .page-width,
    .app-content {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    :where(.page-header, .card-header) {
        gap: 0.75rem;
    }

    :where(.table-responsive, .table-container, .transactions-table-container) {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    :where(.btn, button.btn, a.btn, .mobile-btn) {
        min-height: 44px;
    }
}

/* Stable application navigation on phones and tablets. This final layer does
   not depend on user-agent classes, so the menu survives full page changes. */
@media (max-width: 1023px) {
    .app-shell .topbar {
        min-height: 64px !important;
    }

    .app-shell .topbar > .page-width {
        min-height: 64px !important;
        padding: 0 16px !important;
        gap: 12px !important;
    }

    .app-shell .topbar-main {
        display: flex !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 10px !important;
    }

    .app-shell .main-nav,
    .app-shell .topbar-right {
        display: none !important;
    }

    .app-shell .main-logo {
        font-size: 1.45rem !important;
    }

    .app-shell .mobile-menu-toggle {
        display: inline-flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: relative !important;
        inset: auto !important;
        flex: 0 0 44px !important;
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 0 !important;
        align-items: center !important;
        justify-content: center !important;
        border: 1px solid var(--ui-border-strong) !important;
        border-radius: var(--ui-radius-sm) !important;
        background: var(--ui-surface) !important;
        color: var(--ui-text) !important;
        box-shadow: none !important;
        cursor: pointer !important;
        z-index: 1302 !important;
    }

    .app-shell .mobile-menu-toggle .hamburger {
        position: relative !important;
        display: block !important;
        width: 20px !important;
        height: 16px !important;
    }

    .app-shell .mobile-menu-toggle .hamburger span {
        position: absolute !important;
        left: 0 !important;
        right: 0 !important;
        width: 20px !important;
        height: 2px !important;
        border-radius: 99px !important;
        background: currentColor !important;
        transition: transform 180ms ease, opacity 180ms ease, top 180ms ease !important;
    }

    .app-shell .mobile-menu-toggle .hamburger span:nth-child(1) { top: 0 !important; }
    .app-shell .mobile-menu-toggle .hamburger span:nth-child(2) { top: 7px !important; }
    .app-shell .mobile-menu-toggle .hamburger span:nth-child(3) { top: 14px !important; }
    .app-shell .mobile-menu-toggle .hamburger.active span:nth-child(1) { top: 7px !important; transform: rotate(45deg) !important; }
    .app-shell .mobile-menu-toggle .hamburger.active span:nth-child(2) { opacity: 0 !important; }
    .app-shell .mobile-menu-toggle .hamburger.active span:nth-child(3) { top: 7px !important; transform: rotate(-45deg) !important; }

    .app-shell .mobile-sidebar {
        display: flex !important;
        visibility: visible !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: min(84vw, 320px) !important;
        height: 100dvh !important;
        min-height: 0 !important;
        padding: 0 !important;
        flex-direction: column !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        background: var(--ui-surface) !important;
        border-right: 1px solid var(--ui-border) !important;
        box-shadow: 8px 0 24px rgba(20, 27, 40, 0.12) !important;
        opacity: 1 !important;
        transform: translateX(-105%) !important;
        transition: transform 220ms ease !important;
        z-index: 1301 !important;
    }

    .app-shell .mobile-sidebar.active {
        left: 0 !important;
        transform: translateX(0) !important;
    }

    .app-shell .mobile-nav-header {
        display: block !important;
        padding: calc(1rem + env(safe-area-inset-top)) 1.25rem 1rem !important;
        background: var(--ui-primary) !important;
    }

    .app-shell .mobile-nav,
    .app-shell .mobile-nav-footer,
    .app-shell .mobile-sidebar .nav-item,
    .app-shell .mobile-sidebar .nav-divider,
    .app-shell .mobile-sidebar .user-info,
    .app-shell .mobile-sidebar .logout-form {
        display: flex !important;
        width: auto !important;
        height: auto !important;
        position: static !important;
        left: auto !important;
        top: auto !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    .app-shell .mobile-nav,
    .app-shell .mobile-nav-footer {
        flex-direction: column !important;
    }

    .app-shell .mobile-nav {
        flex: 1 0 auto !important;
        padding: 0.65rem !important;
    }

    .app-shell .mobile-sidebar .nav-item {
        min-height: 48px !important;
        padding: 0.75rem 1rem !important;
        border: 0 !important;
        border-radius: var(--ui-radius-sm) !important;
        align-items: center !important;
    }

    .app-shell .mobile-nav-footer {
        flex: 0 0 auto !important;
        padding: 0.75rem !important;
        border-top: 1px solid var(--ui-border) !important;
    }

    .app-shell .mobile-sidebar .user-info {
        justify-content: flex-start !important;
        padding: 0.5rem 1rem !important;
        transform: none !important;
    }

    .app-shell .mobile-overlay {
        display: block !important;
        visibility: hidden !important;
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        background: rgba(22, 28, 40, 0.48) !important;
        opacity: 0 !important;
        pointer-events: none !important;
        transition: opacity 220ms ease, visibility 220ms ease !important;
        z-index: 1300 !important;
    }

    .app-shell .mobile-overlay.active {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    body.drawer-open {
        overflow: hidden !important;
        height: 100dvh !important;
    }

    /* The dedicated mobile views now share the same application shell and
       navigation component as every other authenticated page. */
    body.mobile-app .mobile-app-shell .mobile-content {
        margin-top: 0 !important;
        min-height: calc(100dvh - 64px) !important;
    }

    /* Restore the original mobile navigation language: a navy application
       bar, unboxed left menu control, and a drawer below the bar. */
    .app-shell .topbar {
        position: sticky !important;
        top: 0 !important;
        z-index: 1400 !important;
        background: var(--ui-primary) !important;
        border-bottom-color: rgba(255, 255, 255, 0.14) !important;
        color: #fff !important;
    }

    .app-shell .topbar > .page-width {
        position: relative !important;
    }

    .app-shell .mobile-menu-toggle {
        border: 0 !important;
        border-radius: 6px !important;
        background: transparent !important;
        color: #fff !important;
    }

    .app-shell .mobile-menu-toggle:hover,
    .app-shell .mobile-menu-toggle:focus-visible {
        background: transparent !important;
    }

    .app-shell .mobile-menu-toggle .hamburger {
        min-width: 20px !important;
        min-height: 16px !important;
        margin: 0 !important;
    }

    .app-shell .main-logo,
    .app-shell .main-logo:hover,
    .app-shell .main-logo .logo-text {
        color: #fff !important;
    }

    .app-shell .mobile-page-title {
        display: none;
        position: absolute;
        left: 50%;
        top: 50%;
        max-width: 30vw;
        transform: translate(-50%, -50%);
        overflow: hidden;
        color: #fff;
        font-size: 1.05rem;
        font-weight: 650;
        line-height: 1.2;
        text-overflow: ellipsis;
        white-space: nowrap;
        pointer-events: none;
    }

    .app-shell .mobile-sidebar {
        top: 64px !important;
        bottom: auto !important;
        height: calc(100dvh - 64px) !important;
        box-shadow: 6px 0 18px rgba(15, 23, 42, 0.16) !important;
    }

    .app-shell .mobile-nav-header {
        display: none !important;
    }

    .app-shell .mobile-nav {
        flex: 0 0 auto !important;
        padding: 0 !important;
    }

    .app-shell .mobile-sidebar .nav-item {
        min-height: 56px !important;
        padding: 0.9rem 1.5rem !important;
        border-bottom: 1px solid var(--ui-border) !important;
        border-radius: 0 !important;
    }

    .app-shell .mobile-sidebar .nav-item:hover,
    .app-shell .mobile-sidebar .nav-item.active {
        background: #eef2f8 !important;
        color: var(--ui-primary) !important;
    }

    .app-shell .mobile-sidebar .nav-divider {
        margin: 0 !important;
    }

    .app-shell .mobile-nav-footer {
        padding: 0 !important;
    }

    .app-shell .mobile-nav-footer .user-info {
        display: none !important;
    }

    .app-shell .mobile-nav-footer .logout-btn,
    .app-shell .mobile-nav-footer .logout-btn:hover {
        min-height: 56px !important;
        padding: 0.9rem 1.5rem !important;
        border-radius: 0 !important;
        background: var(--ui-primary) !important;
        color: #fff !important;
    }

    .app-shell .mobile-overlay,
    .app-shell .mobile-overlay.active {
        top: 64px !important;
        height: calc(100% - 64px) !important;
    }

    @media (min-width: 640px) {
        .app-shell .mobile-page-title {
            display: block !important;
        }

        .app-shell .topbar-right {
            display: flex !important;
            position: relative !important;
            z-index: 1 !important;
            margin-left: auto !important;
            color: #fff !important;
        }

        .app-shell .topbar-right .user-menu {
            display: flex !important;
            align-items: center !important;
            gap: 12px !important;
        }

        .app-shell .topbar-right .settings-icon {
            display: none !important;
        }

        .app-shell .topbar-right .user-info {
            display: block !important;
            color: #fff !important;
        }

        .app-shell .topbar-right .btn {
            min-height: 44px !important;
            border-color: rgba(255, 255, 255, 0.42) !important;
            background: transparent !important;
            color: #fff !important;
        }
    }
}

/* One horizontal grid for the whole tablet experience. Header controls,
   page content and direct page containers all land on the same 24px rails. */
@media (min-width: 640px) and (max-width: 1023px) {
    .app-shell .topbar > .page-width,
    .app-shell .main-content > .page-width {
        padding-left: 24px !important;
        padding-right: 24px !important;
    }

    .app-shell .main-content > .page-width > .container,
    .app-shell .main-content > .page-width > .page-width {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
}

@media (max-width: 639px) {
    body.mobile-app .mobile-app-shell .mobile-content {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
}

@media (min-width: 1024px) {
    .app-shell .mobile-menu-toggle,
    .app-shell .mobile-sidebar,
    .app-shell .mobile-overlay {
        display: none !important;
    }
}

@media (max-width: 480px) {
    body.ui-auth,
    body.ui-welcome {
        align-items: flex-start !important;
        padding: 0.75rem;
    }

    body.ui-auth :where(.login-container, .register-container),
    body.ui-welcome > .container {
        padding: 1.35rem !important;
        border-radius: var(--ui-radius) !important;
    }

    body.ui-welcome .links {
        display: grid !important;
        grid-template-columns: 1fr;
    }

    body.ui-welcome .btn {
        width: 100%;
    }
}

/* Canonical responsive header row. This intentionally comes after every
   recovered legacy rule so the five visible header elements cannot drift
   onto different baselines or wrap into separate rows. */
@media (max-width: 1023px) {
    body .app-shell .topbar,
    body .app-shell .topbar > .page-width {
        height: 64px !important;
        min-height: 64px !important;
        max-height: 64px !important;
    }

    body .app-shell .topbar > .page-width {
        display: flex !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        align-content: center !important;
    }

    body .app-shell .topbar-main {
        position: static !important;
        height: 64px !important;
        min-height: 64px !important;
        max-height: 64px !important;
        align-self: center !important;
        align-items: center !important;
    }

    body .app-shell .mobile-menu-toggle,
    body .app-shell .logo-section,
    body .app-shell .main-logo {
        align-self: center !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        transform: none !important;
    }

    body .app-shell .logo-section,
    body .app-shell .main-logo {
        height: 44px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        line-height: 1 !important;
    }

    body .app-shell .mobile-page-title {
        top: 50% !important;
        margin: 0 !important;
        line-height: 1 !important;
        transform: translate(-50%, -50%) !important;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    body .app-shell .topbar > .page-width {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
        grid-template-rows: 64px !important;
    }

    body .app-shell .topbar-main {
        grid-column: 1 !important;
        grid-row: 1 !important;
    }

    body .app-shell .mobile-page-title {
        display: flex !important;
        height: 44px !important;
        align-items: center !important;
    }

    body .app-shell .topbar-right {
        grid-column: 3 !important;
        grid-row: 1 !important;
        display: flex !important;
        width: auto !important;
        height: 64px !important;
        min-height: 64px !important;
        max-height: 64px !important;
        margin: 0 !important;
        padding: 0 !important;
        align-self: center !important;
        justify-self: end !important;
        align-items: center !important;
        transform: none !important;
    }

    body .app-shell .topbar-right .user-menu {
        display: flex !important;
        height: 64px !important;
        margin: 0 !important;
        padding: 0 !important;
        align-items: center !important;
        gap: 12px !important;
        transform: none !important;
    }

    body .app-shell .topbar-right .user-info,
    body .app-shell .topbar-right form,
    body .app-shell .topbar-right .btn {
        height: 44px !important;
        min-height: 44px !important;
        max-height: 44px !important;
        margin: 0 !important;
        align-self: center !important;
        align-items: center !important;
        transform: none !important;
        line-height: 1 !important;
    }

    body .app-shell .topbar-right .user-info,
    body .app-shell .topbar-right form,
    body .app-shell .topbar-right .btn {
        display: flex !important;
    }

    body .app-shell .topbar-right .btn {
        justify-content: center !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }
}

@media (max-width: 639px) {
    body .app-shell .topbar-right,
    body .app-shell .mobile-page-title {
        display: none !important;
    }
}

/* iOS Safari drawer rendering. Legacy styles apply hidden backfaces to every
   element; inside a transformed fixed drawer WebKit can then paint borders
   while dropping all text. Keep the closed-state slide, but remove the
   transformed compositing layer once open and give every row a real width. */
@media (max-width: 1023px) {
    body .app-shell .mobile-sidebar,
    body .app-shell .mobile-sidebar * {
        -webkit-backface-visibility: visible !important;
        backface-visibility: visible !important;
    }

    body .app-shell .mobile-sidebar * {
        z-index: auto !important;
        pointer-events: auto !important;
    }

    body .app-shell .mobile-sidebar.active {
        transform: none !important;
    }

    body .app-shell .mobile-nav,
    body .app-shell .mobile-nav-footer,
    body .app-shell .mobile-nav-footer .logout-form,
    body .app-shell .mobile-sidebar .nav-item,
    body .app-shell .mobile-nav-footer .logout-btn {
        width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    body .app-shell .mobile-sidebar .nav-item {
        justify-content: flex-start !important;
        color: #394150 !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    body .app-shell .mobile-sidebar .nav-item.active {
        color: var(--ui-primary) !important;
    }

    body .app-shell .mobile-sidebar .nav-text {
        display: block !important;
        position: static !important;
        inset: auto !important;
        width: auto !important;
        height: auto !important;
        margin: 0 !important;
        color: inherit !important;
        opacity: 1 !important;
        visibility: visible !important;
        -webkit-text-fill-color: currentColor !important;
        transform: none !important;
        font-size: 1rem !important;
        line-height: 1.4 !important;
        white-space: nowrap !important;
    }

    body .app-shell .mobile-nav-footer .logout-btn,
    body .app-shell .mobile-nav-footer .logout-btn .nav-text {
        color: #fff !important;
        -webkit-text-fill-color: #fff !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-contrast: more) {
    :root {
        --ui-border: #9aa8ba;
        --ui-border-strong: #748398;
    }
}
