/* Mobile adaptive layer. Keep desktop CSS as the base and override only narrow viewports. */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

*, *::before, *::after {
    box-sizing: border-box;
}

.mobile-bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    :root {
        --mobile-header-height: 56px;
        --mobile-bottom-nav-height: 66px;
        --mobile-page-x: 12px;
    }

    html,
    body {
        width: 100%;
        min-height: 100dvh;
        overflow-x: hidden;
    }

    body {
        padding-top: var(--mobile-header-height);
        padding-bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
    }

    body,
    button,
    input,
    textarea,
    select,
    a,
    p,
    li,
    span,
    small,
    label,
    h1,
    h2,
    h3,
    h4 {
        writing-mode: horizontal-tb;
        letter-spacing: 0;
    }

    p,
    li,
    small,
    label,
    .text-container,
    .message-content,
    .chat-message .bubble,
    .source-item-title,
    .source-item-body,
    .intent-content,
    .plan-text,
    .result-text,
    .content-box,
    .report-card,
    .service-card,
    .metric-card {
        word-break: keep-all;
        overflow-wrap: break-word;
    }

    body .top-bar,
    body header.top-bar,
    body #appHeader,
    body.mobile-shell-ready .top-bar,
    body.mobile-shell-ready #appHeader {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0 !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        z-index: 10000 !important;
        height: var(--mobile-header-height) !important;
        min-height: var(--mobile-header-height) !important;
        max-height: var(--mobile-header-height) !important;
        padding: 0 var(--mobile-page-x) !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 8px !important;
        border-bottom: 1px solid var(--friendly-line, #c2cec1) !important;
        background: rgba(252, 250, 244, 0.98) !important;
        backdrop-filter: blur(18px) !important;
        -webkit-backdrop-filter: blur(18px) !important;
        box-shadow: 0 4px 16px rgba(23, 32, 25, 0.06) !important;
        box-sizing: border-box !important;
    }

    .top-bar .nav-center {
        display: none !important;
    }

    .top-bar-left,
    .top-bar .logo {
        flex: 1 1 auto;
        min-width: 0;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .logo-sm,
    .top-bar .logo i {
        width: 32px;
        height: 32px;
        min-width: 32px;
        border-radius: 8px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: var(--friendly-accent-soft, #dcebe3) !important;
        color: var(--friendly-accent, #185f4b) !important;
        border: 1px solid rgba(24, 95, 75, 0.34) !important;
    }

    .top-bar-left h1,
    .top-bar .logo span {
        max-width: 136px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 1rem;
        font-weight: 800;
        line-height: 1;
        letter-spacing: 0;
        color: var(--friendly-text, #151a16) !important;
    }

    .top-bar-right {
        flex: 0 0 auto;
        min-width: 0;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 6px;
    }

    .user-badge,
    .top-bar .user-badge {
        width: 36px;
        min-width: 36px;
        height: 36px;
        min-height: 36px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 9px;
        background: var(--friendly-surface-soft, #f7faf5) !important;
        border: 1px solid var(--friendly-line, #c2cec1) !important;
        color: var(--friendly-accent, #185f4b) !important;
        box-sizing: border-box;
    }

    .user-badge #currentUser,
    .user-badge #userTierBadge,
    .user-badge span:not(:first-child) {
        display: none !important;
    }

    .icon-btn,
    .top-bar .icon-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        padding: 0;
        border-radius: 9px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: var(--friendly-surface-soft, #f7faf5) !important;
        border: 1px solid var(--friendly-line, #c2cec1) !important;
        color: var(--friendly-accent, #185f4b) !important;
        box-sizing: border-box;
    }

    .mobile-bottom-nav {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        z-index: 10000 !important;
        height: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom)) !important;
        padding: 6px 8px calc(7px + env(safe-area-inset-bottom)) !important;
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(56px, 1fr)) !important;
        gap: 4px !important;
        background: rgba(252, 250, 244, 0.99) !important;
        border-top: 1px solid var(--friendly-line, #c2cec1) !important;
        box-shadow: 0 -12px 28px rgba(23, 32, 25, 0.12) !important;
        backdrop-filter: blur(18px) !important;
        -webkit-backdrop-filter: blur(18px) !important;
        box-sizing: border-box !important;
    }

    .mobile-bottom-nav a {
        min-width: 0 !important;
        height: 50px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 4px !important;
        color: var(--friendly-muted, #3f493f) !important;
        text-decoration: none !important;
        border-radius: 10px !important;
        font-size: clamp(0.62rem, 2.6vw, 0.68rem) !important;
        font-weight: 750 !important;
        line-height: 1 !important;
        -webkit-tap-highlight-color: transparent !important;
        transition: background 0.15s ease, color 0.15s ease !important;
    }

    .mobile-bottom-nav a i {
        font-size: 1rem !important;
        color: var(--friendly-accent, #185f4b) !important;
    }

    .mobile-bottom-nav a.active {
        color: var(--friendly-accent, #185f4b) !important;
        background: var(--friendly-accent-soft, #dcebe3) !important;
        box-shadow: inset 0 0 0 1px rgba(24, 95, 75, 0.28) !important;
        font-weight: 800 !important;
    }

    .mobile-bottom-nav a.active i {
        color: var(--friendly-accent, #185f4b) !important;
    }

    body.app-history-ready {
        --history-top: var(--mobile-header-height);
        --history-panel-width: min(88vw, 340px);
    }


    .app-history-toggle {
        width: auto;
        min-width: 116px;
        height: 42px;
        left: 14px;
        right: auto;
        bottom: calc(var(--mobile-bottom-nav-height) + 12px + env(safe-area-inset-bottom));
        gap: 8px;
        padding: 0 13px;
        font-size: 0.82rem;
        font-weight: 850;
    }

    .app-history-toggle span {
        display: inline;
    }

    .app-history-drawer {
        top: var(--mobile-header-height);
        width: var(--history-panel-width);
        height: calc(100dvh - var(--mobile-header-height) - var(--mobile-bottom-nav-height) - env(safe-area-inset-bottom));
        border-radius: 0 12px 0 0;
    }

    .app-history-scrim {
        inset: var(--mobile-header-height) 0 calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom)) 0;
    }

    .app-history-head {
        padding: 0.85rem 0.9rem 0.75rem;
    }

    .app-history-actions {
        padding: 0.75rem 0.85rem;
    }

    .app-history-list {
        padding: 0.65rem;
        overflow-x: hidden;
    }

    .app-history-item {
        overflow: visible !important;
    }

    .app-history-item-title-row {
        align-items: flex-start !important;
        gap: 8px !important;
    }

    .app-history-menu {
        position: relative !important;
        z-index: 2 !important;
    }

    .app-history-menu-button {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        border-radius: 9px !important;
    }

    .app-history-item-actions {
        position: static !important;
        min-width: 132px !important;
        margin-top: 6px !important;
        padding: 6px !important;
        border-radius: 10px !important;
        background: #ffffff !important;
        border: 1px solid var(--friendly-line-strong, #b9c7bd) !important;
        box-shadow: 0 10px 22px rgba(23, 32, 25, 0.14) !important;
    }

    .app-history-menu:not(.open) .app-history-item-actions {
        display: none !important;
    }

    .app-history-menu.open .app-history-item-actions {
        display: grid !important;
        gap: 4px !important;
    }

    .app-history-menu-item {
        min-height: 40px !important;
        color: var(--friendly-text, #1f2933) !important;
        font-size: 0.84rem !important;
        border-radius: 8px !important;
    }

    .app-history-menu-item.primary {
        color: var(--friendly-accent-hover, #0f766e) !important;
    }

    .app-history-menu-item.danger {
        color: #b42318 !important;
    }

    .app-history-modal {
        align-items: flex-end;
        inset: var(--mobile-header-height) 0 calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom)) 0;
        padding: 0;
        z-index: 10020;
    }

    .app-history-modal-card {
        width: 100%;
        max-height: 100%;
        border-radius: 14px 14px 0 0;
    }

    .app-history-modal-body {
        max-height: calc(100dvh - var(--mobile-header-height) - var(--mobile-bottom-nav-height) - 96px - env(safe-area-inset-bottom));
    }

    .container {
        width: 100%;
        max-width: none;
        padding: 18px var(--mobile-page-x);
        gap: 16px;
    }

    .usage-page-head {
        gap: 12px;
        margin: 0;
        padding-bottom: 12px;
        min-width: 0;
        width: 100%;
    }

    .usage-page-head > div {
        min-width: 0;
        width: 100%;
    }

    .usage-page-head h2 {
        max-width: 100%;
        font-size: 1.08rem;
        line-height: 1.35;
        overflow-wrap: anywhere;
    }

    .usage-page-head p {
        max-width: 100%;
        font-size: 0.8rem;
        line-height: 1.5;
        overflow-wrap: break-word;
    }

    .usage-page-head .date-filter {
        position: relative;
        width: 100%;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        gap: 8px;
        padding: 8px 50px 8px 8px !important;
        border-radius: 10px;
        background: rgba(15, 23, 42, 0.76);
        border: 1px solid rgba(148, 163, 184, 0.18);
        color-scheme: dark;
    }

    .usage-page-head .date-filter input {
        width: 100%;
        min-width: 0;
        min-height: 34px;
        padding: 0 8px;
        border: 1px solid rgba(148, 163, 184, 0.16);
        border-radius: 8px;
        background: rgba(2, 6, 23, 0.36);
        color: #e5e7eb;
        color-scheme: dark;
        font-size: 0.76rem;
        -webkit-appearance: none;
        appearance: none;
    }

    .usage-page-head .date-filter input::-webkit-calendar-picker-indicator {
        opacity: 0.76;
        filter: invert(1);
    }

    .usage-page-head .date-filter input::-webkit-date-and-time-value {
        color: #e5e7eb;
    }

    .usage-page-head .date-filter .icon-btn {
        position: absolute;
        top: 8px;
        right: 8px;
        z-index: 2;
        width: 34px;
        height: 34px;
        min-width: 34px;
        border-radius: 8px;
        border: 1px solid rgba(148, 163, 184, 0.18);
        background: rgba(15, 23, 42, 0.8);
        color: #cbd5e1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .usage-main-stack {
        gap: 12px;
        min-width: 0;
    }

    .usage-summary-grid {
        width: 100%;
        min-width: 0;
    }

    .usage-summary-grid .stat-card {
        min-width: 0;
    }

    .usage-summary-grid .stat-value {
        max-width: 100%;
        overflow-wrap: anywhere;
    }

    .usage-summary-grid .stat-label {
        letter-spacing: 0;
        line-height: 1.2;
    }

    .usage-recent-card {
        padding: 12px;
    }

    .usage-recent-card-inner,
    .usage-recent-metrics {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        width: 100%;
    }

    .usage-recent-title {
        min-width: 0;
    }

    .usage-recent-metrics .stat-info {
        width: 100%;
        padding-left: 0;
        border-left: 0;
    }

    .usage-workspace-head {
        padding: 14px;
    }

    .usage-workspace-control {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 10px 14px;
    }

    .usage-nav-tabs {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        overflow: visible !important;
    }

    .usage-workspace-head .view-btn {
        width: 100% !important;
        justify-content: center;
    }

    .usage-workspace-actions {
        width: 100%;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .usage-workspace-actions .view-btn {
        width: 100% !important;
    }

    .usage-nav-tabs .tab-btn span,
    .usage-nav-tabs .tab-btn small {
        min-width: 0;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .usage-workspace-panel .view-btn,
    .usage-workspace-panel .add-user-btn,
    .usage-nav-tabs .tab-btn {
        background: rgba(15, 23, 42, 0.78) !important;
        border: 1px solid rgba(148, 163, 184, 0.18) !important;
        color: #e5e7eb !important;
        box-shadow: none !important;
    }

    .usage-workspace-panel .view-btn:hover,
    .usage-workspace-panel .add-user-btn:hover,
    .usage-nav-tabs .tab-btn:hover {
        background: rgba(30, 41, 59, 0.88) !important;
        color: #fff !important;
        transform: none !important;
    }

    .usage-nav-tabs .tab-btn.active {
        background: rgba(37, 99, 235, 0.22) !important;
        border-color: rgba(96, 165, 250, 0.36) !important;
        color: #bfdbfe !important;
        box-shadow: inset 0 -2px 0 rgba(96, 165, 250, 0.85) !important;
    }

    .usage-nav-tabs .tab-btn small {
        color: #b8c6db !important;
    }

    .usage-active-note {
        padding: 10px 12px;
        color: #dbeafe;
        background: rgba(37, 99, 235, 0.12);
        border: 1px solid rgba(96, 165, 250, 0.2);
        border-radius: 8px;
    }

    .usage-overview-section .charts-row {
        padding: 0 12px 12px;
    }

    .billing-event-row {
        grid-template-columns: 1fr;
    }

    .glass-panel {
        border-radius: 12px;
        padding: 16px;
    }

    h1,
    .hero-title {
        font-size: clamp(1.8rem, 9vw, 2.6rem);
        line-height: 1.12;
        letter-spacing: 0;
    }

    h2,
    .section-header h2 {
        font-size: 1.45rem;
        line-height: 1.22;
        letter-spacing: 0;
    }

    .cta-group,
    .nav-tabs,
    .period-mode-group,
    .chart-view-group,
    .subgroup-tabs {
        flex-wrap: nowrap;
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .cta-group::-webkit-scrollbar,
    .nav-tabs::-webkit-scrollbar,
    .period-mode-group::-webkit-scrollbar,
    .chart-view-group::-webkit-scrollbar,
    .subgroup-tabs::-webkit-scrollbar {
        display: none;
    }

    .tag,
    .tab,
    .tab-btn,
    .segmented-option,
    .subgroup-tab {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .nav-tabs .tab-btn {
        min-width: max-content;
        padding: 12px 14px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        font-size: 0.84rem;
        line-height: 1.2;
        word-break: keep-all;
        overflow-wrap: normal;
    }

    .nav-tabs:has(#reportSearchGroup) {
        flex-wrap: wrap;
        overflow-x: visible;
    }

    .nav-tabs > div[style*="flex-grow"] {
        display: none !important;
    }

    .nav-tabs #reportSearchGroup {
        flex: 0 0 100%;
        width: 100%;
        padding: 0 12px 12px !important;
        justify-content: stretch;
    }

    .nav-tabs #reportSearchGroup .date-filter,
    .nav-tabs #reportSearchGroup input {
        width: 100% !important;
    }

    .tags {
        flex-wrap: wrap;
        justify-content: flex-start;
        overflow: visible;
    }

    .tag {
        max-width: 100%;
        white-space: normal;
    }

    #nav-tabs.nav-tabs {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        overflow: visible;
    }

    #nav-tabs.nav-tabs .tab {
        width: 100%;
        min-width: 0;
        padding: 12px 8px;
        justify-content: center;
        text-align: center;
        white-space: normal;
        line-height: 1.2;
        font-size: clamp(0.78rem, 3.4vw, 0.9rem);
    }

    .hero {
        min-height: 430px;
        height: calc(100dvh - var(--mobile-header-height) - 48px);
        align-items: flex-end;
        padding: 40px var(--mobile-page-x) 34px;
    }

    .hero-content {
        width: 100%;
        padding: 0;
        text-align: left;
    }

    .hero-subtitle {
        font-size: 0.98rem;
        line-height: 1.55;
        margin-bottom: 26px;
    }

    .cta-group {
        display: flex;
        gap: 10px;
    }

    .btn-primary,
    .btn-secondary {
        flex: 1 1 0;
        min-width: 0;
        padding: 13px 14px;
        border-radius: 12px;
        text-align: center;
        font-size: 0.92rem;
        line-height: 1.25;
        white-space: normal;
        word-break: keep-all;
        overflow-wrap: break-word;
    }

    .services-section {
        padding: 42px 0 24px;
    }

    .section-header {
        margin-bottom: 24px;
        padding: 0 var(--mobile-page-x);
        text-align: left;
    }

    .services-grid,
    .charts-row,
    .billing-dashboard,
    .pricing-grid,
    .admin-grid,
    .cards-grid {
        display: grid;
        grid-template-columns: 1fr !important;
        gap: 14px;
    }

    .summary-cards,
    .metric-strip {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px;
    }

    .stat-card,
    .metric-card {
        min-width: 0;
        padding: 14px;
        gap: 10px;
    }

    .stat-icon {
        width: 42px;
        height: 42px;
        min-width: 42px;
        border-radius: 12px;
        font-size: 1.05rem;
    }

    .stat-info {
        min-width: 0;
    }

    .stat-value,
    .metric-card strong {
        font-size: clamp(1.1rem, 5.5vw, 1.45rem);
        line-height: 1.15;
        letter-spacing: 0;
    }

    .stat-label,
    .metric-card span,
    .metric-card small {
        font-size: clamp(0.64rem, 2.6vw, 0.72rem);
        line-height: 1.3;
        letter-spacing: 0;
        text-transform: none;
    }

    .service-card {
        border-radius: 14px;
        padding: 20px;
    }

    .users-section {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: auto !important;
        min-height: 0;
        padding: 16px 14px !important;
        overflow: visible !important;
    }

    .users-section.glass-panel {
        overflow: visible !important;
    }

    .users-section .section-header {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 12px;
        width: 100%;
        height: auto !important;
        min-height: 0;
        min-width: 0;
        padding: 0 !important;
        margin: 0 0 16px !important;
        overflow: visible;
    }

    .users-section .section-header h2 {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        height: auto;
        min-height: 32px;
        min-width: 0;
        margin: 0;
        padding: 2px 0;
        font-size: 0.96rem;
        line-height: 1.45;
        white-space: normal;
        word-break: keep-all;
        overflow-wrap: break-word;
        overflow: visible;
    }

    .add-user-btn,
    .view-btn,
    .login-btn,
    .empty-state button,
    .pay-main-btn,
    .btn-topup {
        max-width: 100%;
        min-width: 0;
        min-height: 44px;
        white-space: normal;
        word-break: keep-all;
        overflow-wrap: break-word;
        line-height: 1.25;
        text-align: center;
    }

    .add-user-btn {
        width: 100%;
        height: auto !important;
        min-height: 48px;
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 12px 14px;
        overflow: visible;
    }

    .card-actions {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px !important;
    }

    .card-actions .view-btn,
    .card-actions .delete-btn {
        width: 100%;
        min-width: 0;
        padding: 10px 8px !important;
    }

    .table-wrapper {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-card,
    .modal-content,
    .report-modal {
        width: 100% !important;
        max-width: calc(100vw - 24px) !important;
        min-width: 0;
    }

    .modal-overlay,
    .modal {
        z-index: 10020 !important;
        align-items: flex-start !important;
        justify-content: center !important;
        min-height: 100dvh;
        height: 100dvh;
        padding: calc(var(--mobile-header-height) + 12px) 12px calc(var(--mobile-bottom-nav-height) + 12px + env(safe-area-inset-bottom)) !important;
        overflow-y: auto;
    }

    .modal-card {
        max-height: calc(100dvh - var(--mobile-header-height) - var(--mobile-bottom-nav-height) - 36px - env(safe-area-inset-bottom)) !important;
        padding: 1rem !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-header {
        align-items: flex-start !important;
        gap: 10px;
        margin-bottom: 1rem !important;
    }

    .modal-header h3 {
        min-width: 0;
        line-height: 1.35;
        white-space: normal;
        overflow-wrap: break-word;
    }

    .report-modal-content {
        padding: 1rem !important;
    }

    .pricing-page .container,
    .pricing-hero,
    .pricing-layout,
    .topup-grid,
    .billing-content-grid,
    .billing-topline {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .pricing-hero,
    .billing-topline {
        flex-direction: column;
        align-items: stretch;
    }

    .pricing-page .view-btn,
    .pricing-page .add-user-btn {
        width: 100% !important;
        justify-content: center;
    }

    .override-item {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .override-options {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }

    .override-options label,
    .permission-chip,
    .manage-override-btn {
        min-width: 0;
        white-space: normal;
        overflow-wrap: break-word;
        line-height: 1.25;
    }

    .dashboard-controls {
        width: 100%;
        padding: 12px var(--mobile-page-x);
        display: flex;
        flex-direction: column;
        gap: 12px;
        overflow: hidden;
    }

    .date-filter {
        width: 100%;
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        padding: 12px !important;
        border-radius: 14px;
    }

    .date-filter > i {
        display: none;
    }

    .date-filter input {
        width: 100%;
        min-width: 0;
        font-size: 16px;
    }

    #recentActivity {
        padding: 14px !important;
        border-left-width: 3px !important;
    }

    #recentActivity > div {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 14px;
    }

    #recentActivity > div > div:first-child {
        align-items: center !important;
        min-width: 0;
    }

    #recentActivity > div > div:last-child {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px !important;
        width: 100%;
    }

    #recentActivity .stat-info {
        min-width: 0;
        border-left: 0 !important;
        padding-left: 0 !important;
    }

    #recentActivity .stat-info:first-child {
        grid-column: 1 / -1;
    }

    #recentActivity .stat-label,
    #recentActivity .stat-value {
        display: block !important;
        width: 100%;
        white-space: normal !important;
        word-break: keep-all;
        overflow-wrap: break-word;
    }

    #recentActivity h4,
    #recentActivity p {
        white-space: normal;
        word-break: keep-all;
        overflow-wrap: break-word;
    }

    .period-panel {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 12px;
        border-radius: 12px;
    }

    #toggle-search-btn,
    #btn-search,
    .primary-btn,
    .btn-save {
        width: 100%;
        min-height: 44px;
        justify-content: center;
    }

    #search-panel,
    #search-panel .glass-panel {
        width: 100%;
    }

    #search-panel .glass-panel {
        flex-direction: column;
        align-items: stretch !important;
        padding: 14px !important;
    }

    #search-name,
    #search-years {
        width: 100% !important;
        min-width: 0 !important;
        font-size: 16px !important;
    }

    .chart-panel-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .chart-metric-select,
    .chart-metric-select select {
        width: 100%;
    }

    .charts-grid .glass-panel {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #main-content,
    #main-content > *,
    .charts-grid,
    .metric-strip {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .chart-container {
        width: 100% !important;
        min-width: 0;
        height: clamp(250px, 38dvh, 320px) !important;
        min-height: 250px;
    }

    .table-container,
    .analysis-table-wrapper,
    .account-group-body {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .account-groups,
    .account-group {
        max-width: 100%;
        min-width: 0;
    }

    .account-groups-title {
        gap: 8px;
    }

    .account-group-header {
        min-height: 58px;
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 8px;
        padding: 0.75rem;
    }

    .group-icon {
        width: 34px;
        height: 34px;
    }

    .group-copy strong {
        font-size: 0.9rem;
    }

    .group-copy small {
        font-size: 0.7rem;
        line-height: 1.35;
    }

    .group-meta,
    .group-total {
        display: none;
    }

    table,
    .naver-style-table,
    .analysis-table {
        min-width: min(720px, 190vw);
    }

    .analysis-table {
        width: 100%;
        min-width: 0;
        display: block;
        border-collapse: separate;
    }

    .analysis-table thead {
        display: none;
    }

    .analysis-table tbody {
        display: grid;
        gap: 10px;
    }

    .analysis-table tr {
        display: block;
        overflow: hidden;
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 12px;
        background: rgba(15, 23, 42, 0.48);
    }

    .analysis-table th,
    .analysis-table td,
    .analysis-table th:first-child,
    .analysis-table td:first-child {
        position: static;
        min-width: 0;
        background: transparent;
    }

    .analysis-table td {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 12px;
        min-height: 42px;
        padding: 10px 12px;
        text-align: right;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    .analysis-table td::before {
        content: attr(data-label);
        min-width: 0;
        color: var(--text-secondary);
        font-weight: 800;
        text-align: left;
        overflow-wrap: break-word;
    }

    .analysis-table td:first-child {
        display: block;
        padding: 12px;
        text-align: left;
        color: var(--text-primary);
        font-size: 0.95rem;
        font-weight: 850;
        background: rgba(255, 255, 255, 0.035);
    }

    .analysis-table td:first-child::before,
    .analysis-table td.missing-value-cell {
        display: none;
    }

    .analysis-table td:last-child {
        border-bottom: 0;
    }

    th,
    td {
        padding: 10px 8px;
        font-size: 0.8rem;
    }

    .chat-layout {
        width: 100%;
        max-width: 100vw;
        height: calc(100dvh - var(--mobile-header-height) - var(--mobile-bottom-nav-height) - env(safe-area-inset-bottom));
        min-height: 0;
        margin: 0;
        border: 0;
        border-radius: 0;
        overflow-x: hidden;
    }

    .chat-header {
        padding: 12px 14px;
    }

    .chat-header h2 {
        font-size: 1rem;
        line-height: 1.35;
    }

    .chat-header p {
        display: none;
    }

    .status-indicator {
        margin-top: 8px;
        font-size: 0.74rem;
    }

    .chat-window {
        padding: 16px 12px;
        gap: 16px;
        min-height: 0;
        min-width: 0;
        overflow-x: hidden;
    }

    .chat-message,
    .chat-message.ai,
    .chat-message.user {
        max-width: 100%;
        width: 100%;
        gap: 0;
        min-width: 0;
        align-self: flex-start;
        margin-bottom: 8px;
    }

    .chat-message.user {
        flex-direction: row;
    }

    .chat-message .avatar {
        display: none !important;
    }

    .chat-message .bubble {
        padding: 14px 16px;
        border-radius: 12px !important;
        font-size: 0.95rem;
        line-height: 1.6;
        overflow-wrap: break-word;
        min-width: 0;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }

    .chat-message.ai .bubble {
        background: rgba(15, 23, 42, 0.6);
        border: 1px solid rgba(0, 210, 255, 0.15);
        border-left: 4px solid #00d2ff !important;
    }

    .chat-message.user .bubble {
        background: rgba(30, 41, 59, 0.7);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-right: 4px solid #a855f7 !important;
        border-left: 1px solid rgba(255, 255, 255, 0.1) !important;
    }

    .chat-message .bubble table,
    .text-container table,
    .message-content table {
        display: block !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        white-space: nowrap !important;
        box-sizing: border-box;
    }

    .text-container,
    .message-content {
        font-size: 0.95rem;
        line-height: 1.6;
        overflow-wrap: break-word;
        min-width: 0;
    }

    .text-container p,
    .text-container li,
    .message-content p,
    .message-content li {
        overflow-wrap: break-word;
        word-break: keep-all;
    }

    .chat-input-wrapper {
        flex: 0 0 auto;
        align-items: center;
        padding: 8px 10px 10px;
        gap: 8px;
    }

    #chat-input {
        height: min(10.5dvh, 88px);
        min-height: min(10.5dvh, 88px);
        min-width: 0;
        max-height: min(16dvh, 120px);
        padding: 12px;
        font-size: 16px;
        line-height: 1.28;
        overflow-y: auto;
    }

    #chat-send-btn,
    .mode-selector-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        border-radius: 10px;
    }

    .monitor-link-btn,
    #monitorLinkBtn {
        display: none !important;
    }

    a[href*="/monitor"],
    button[onclick*="/monitor"],
    .monitor-btn,
    .monitor-link-btn,
    #monitorLinkBtn {
        display: none !important;
    }

    .mode-selector-btn {
        justify-content: center;
        padding: 8px;
    }

    .mode-label,
    .mode-chevron {
        display: none;
    }

    .mode-dropdown {
        bottom: 52px;
        left: 0;
        min-width: min(290px, calc(100vw - 20px));
        max-width: calc(100vw - 20px);
        max-height: min(420px, calc(100dvh - 180px));
        overflow-y: auto;
    }

    .sources-container,
    .intent-box {
        margin-bottom: 16px;
        border-radius: 10px;
    }

    .sources-header {
        padding: 12px 14px;
        font-size: 0.8rem;
        gap: 8px;
        min-width: 0;
    }

    .source-item-title {
        align-items: flex-start;
        gap: 8px;
        line-height: 1.35;
    }

    .source-item-title .source-meta-tag {
        flex: 0 0 auto;
        margin-left: 0;
    }

    .sources-container.expanded .sources-content {
        max-height: 220px;
        padding: 12px;
    }

    .modal,
    .modal-overlay {
        align-items: flex-end;
        padding: 12px;
    }

    .modal-content,
    .settings-modal {
        width: 100%;
        max-width: none;
        max-height: calc(100dvh - 24px);
        padding: 1rem;
        border-radius: 14px;
        overflow-y: auto;
    }

    .settings-header h2 {
        font-size: 1.05rem;
        line-height: 1.35;
    }

    .settings-subtitle,
    .setting-desc {
        font-size: 0.8rem;
        line-height: 1.45;
    }

    .setting-section {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .setting-section > div[style*="space-between"] {
        align-items: flex-start !important;
        flex-direction: column;
        gap: 10px;
    }

    .module-grid {
        grid-template-columns: 1fr !important;
    }

    .api-key-input-wrapper {
        flex-direction: column;
    }

    body:has(.usage-page-head) .container,
    .usage-page-head,
    .usage-main,
    .usage-main-stack,
    .usage-summary-grid,
    .usage-workspace-panel {
        max-width: 100%;
        min-width: 0;
    }

    .usage-page-head .date-filter {
        max-width: calc(100vw - (var(--mobile-page-x) * 2));
    }

    .usage-workspace-panel .usage-nav-tabs .tab-btn {
        min-width: 0 !important;
        padding: 10px 8px !important;
        display: flex !important;
        flex: 1 1 0 !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        justify-content: center !important;
        gap: 3px !important;
        white-space: normal;
    }

    .usage-workspace-panel .usage-nav-tabs {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        overflow: visible !important;
    }

    .usage-workspace-panel .usage-nav-tabs .tab-btn::after {
        display: none !important;
    }

    /* Chat mobile polish: use the full viewport and contain rich markdown. */
    body:has(.chat-layout) {
        padding-top: var(--mobile-header-height) !important;
        padding-bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom)) !important;
        overflow: hidden !important;
    }

    body:has(.chat-layout) .chat-layout {
        width: 100vw !important;
        max-width: 100vw !important;
        height: calc(100dvh - var(--mobile-header-height) - var(--mobile-bottom-nav-height) - env(safe-area-inset-bottom)) !important;
        margin: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    body:has(.chat-layout) .chat-window {
        width: 100% !important;
        max-width: 100% !important;
        padding: 12px 8px 14px !important;
        gap: 12px !important;
        overflow-x: hidden !important;
        scrollbar-gutter: auto !important;
    }

    body:has(.chat-layout) .chat-message,
    body:has(.chat-layout) .chat-message.ai,
    body:has(.chat-layout) .chat-message.user,
    body:has(.chat-layout) .chat-message.welcome-message {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        align-self: stretch !important;
    }

    body:has(.chat-layout) .chat-message .bubble {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        padding: 12px !important;
        border-radius: 8px !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    body:has(.chat-layout) .chat-message.ai .bubble,
    body:has(.chat-layout) .chat-message.user .bubble {
        border-left: 1px solid var(--friendly-line-strong) !important;
        border-right: 1px solid var(--friendly-line-strong) !important;
    }

    body:has(.chat-layout) .chat-message.user .bubble {
        background: var(--friendly-accent-soft) !important;
    }

    body.chat-page .chat-message.ai .bubble,
    body:has(.chat-layout) .chat-message.ai .bubble {
        border-left: 5px solid var(--friendly-accent) !important;
        padding-left: 22px !important;
    }

    body.chat-page .chat-message.user .bubble,
    body:has(.chat-layout) .chat-message.user .bubble {
        border-right: 5px solid #2563eb !important;
        padding-right: 14px !important;
    }

    body.chat-page .chat-message.ai .bubble::before,
    body:has(.chat-layout) .chat-message.ai .bubble::before {
        left: 10px !important;
    }

    body:has(.chat-layout) .text-container,
    body:has(.chat-layout) .message-content,
    body:has(.chat-layout) .source-item-body,
    body:has(.chat-layout) .intent-content {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-wrap: anywhere !important;
        word-break: keep-all !important;
    }

    body:has(.chat-layout) .markdown-table-scroll,
    body:has(.chat-layout) .text-container:has(> table),
    body:has(.chat-layout) .message-content:has(> table),
    body:has(.chat-layout) .source-item-body:has(> table) {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        border: 1px solid var(--friendly-line) !important;
        border-radius: 8px !important;
        background: #ffffff !important;
    }

    body:has(.chat-layout) .markdown-table-scroll table,
    body:has(.chat-layout) .chat-message .bubble table,
    body:has(.chat-layout) .text-container table,
    body:has(.chat-layout) .message-content table,
    body:has(.chat-layout) .source-item-body table {
        display: table !important;
        width: max-content !important;
        min-width: 100% !important;
        max-width: none !important;
        white-space: nowrap !important;
        table-layout: auto !important;
        margin: 0 !important;
    }

    body:has(.chat-layout) .chat-message .bubble th,
    body:has(.chat-layout) .chat-message .bubble td,
    body:has(.chat-layout) .source-item-body th,
    body:has(.chat-layout) .source-item-body td {
        white-space: nowrap !important;
        word-break: normal !important;
        overflow-wrap: normal !important;
        font-size: 0.78rem !important;
        padding: 8px 10px !important;
    }

    body:has(.chat-layout) .sources-container,
    body:has(.chat-layout) .intent-box,
    body:has(.chat-layout) .quality-box,
    body:has(.chat-layout) .iteration-box {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin-bottom: 12px !important;
        overflow: hidden !important;
    }

    body.chat-page .sources-container.expanded .sources-content,
    body:has(.chat-layout) .sources-container.expanded .sources-content {
        max-height: min(62dvh, 520px) !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: contain !important;
        touch-action: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    body.chat-page .sources-container:not(.expanded) .sources-content,
    body:has(.chat-layout) .sources-container:not(.expanded) .sources-content,
    body.chat-page .source-item:not(.expanded) .source-item-body,
    body:has(.chat-layout) .source-item:not(.expanded) .source-item-body {
        max-height: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        opacity: 0 !important;
        overflow: hidden !important;
    }

    body:has(.chat-layout) .chat-input-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        padding: 8px !important;
        gap: 6px !important;
    }

    body:has(.chat-layout) #chat-input {
        min-width: 0 !important;
    }

    body.chat-page,
    body:has(.chat-layout) {
        min-height: 100dvh !important;
    }

    body.chat-page .background-elements,
    body:has(.chat-layout) .background-elements {
        display: none !important;
    }

    body.chat-page .chat-layout,
    body:has(.chat-layout) .chat-layout {
        display: flex !important;
        flex-direction: column !important;
        min-height: 0 !important;
        max-height: calc(100dvh - var(--mobile-header-height) - var(--mobile-bottom-nav-height) - env(safe-area-inset-bottom)) !important;
    }

    body.chat-page .chat-header,
    body:has(.chat-layout) .chat-header {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        flex: 0 0 auto !important;
        min-width: 0 !important;
        padding: 12px 10px !important;
    }

    body.chat-page .chat-header h2,
    body:has(.chat-layout) .chat-header h2 {
        max-width: 100% !important;
        white-space: normal !important;
        overflow-wrap: break-word !important;
    }

    body.chat-page .user-guide-strip,
    body:has(.chat-layout) .user-guide-strip {
        display: none !important;
    }

    body.chat-page .status-indicator,
    body:has(.chat-layout) .status-indicator {
        display: flex !important;
        max-width: 100% !important;
        padding: 7px 10px !important;
        line-height: 1.25 !important;
        margin: 0 auto !important;
    }

    body.chat-page .chat-window,
    body:has(.chat-layout) .chat-window {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        min-width: 0 !important;
        padding-bottom: 10px !important;
    }

    body.chat-page .chat-message .bubble > *,
    body:has(.chat-layout) .chat-message .bubble > * {
        max-width: 100% !important;
    }

    body.chat-page .chat-message .bubble img,
    body:has(.chat-layout) .chat-message .bubble img {
        max-width: 100% !important;
        height: auto !important;
    }

    body.chat-page .chat-message .bubble pre,
    body.chat-page .chat-message .bubble code,
    body:has(.chat-layout) .chat-message .bubble pre,
    body:has(.chat-layout) .chat-message .bubble code {
        max-width: 100% !important;
        overflow-x: auto !important;
        white-space: pre-wrap !important;
    }

    body.chat-page .markdown-table-scroll,
    body:has(.chat-layout) .markdown-table-scroll {
        margin: 10px 0 !important;
    }

    body.chat-page .sources-header span,
    body.chat-page .source-item-title,
    body:has(.chat-layout) .sources-header span,
    body:has(.chat-layout) .source-item-title {
        min-width: 0 !important;
        overflow-wrap: anywhere !important;
    }

    body.chat-page .source-module-header,
    body:has(.chat-layout) .source-module-header {
        align-items: flex-start !important;
        gap: 8px !important;
        padding: 9px 10px !important;
    }

    body.chat-page .source-module-title small,
    body:has(.chat-layout) .source-module-title small {
        display: none !important;
    }

    body.chat-page .source-item-title,
    body:has(.chat-layout) .source-item-title {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 8px !important;
    }

    body.chat-page .source-title-text,
    body:has(.chat-layout) .source-title-text {
        white-space: normal !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
    }

    body.chat-page .source-title-side,
    body:has(.chat-layout) .source-title-side {
        justify-content: flex-start !important;
        flex-wrap: wrap !important;
    }

    body.chat-page .source-body-title,
    body.chat-page .source-fact-grid,
    body:has(.chat-layout) .source-body-title,
    body:has(.chat-layout) .source-fact-grid {
        display: none !important;
    }

    body.chat-page .source-body-summary,
    body:has(.chat-layout) .source-body-summary {
        font-size: 0.82rem !important;
        line-height: 1.55 !important;
    }

    body.chat-page .source-body-paragraphs,
    body:has(.chat-layout) .source-body-paragraphs {
        gap: 7px !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(h1, h2, h3, h4) + p,
    body.chat-page .chat-message .bubble .message-content :where(h1, h2, h3, h4) + p,
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2, h3, h4) + p,
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2, h3, h4) + p {
        margin-left: 10px !important;
    }

    body.chat-page .source-item.expanded .source-item-body,
    body:has(.chat-layout) .source-item.expanded .source-item-body {
        max-height: none !important;
        overflow: visible !important;
        overscroll-behavior: auto !important;
        touch-action: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    body.chat-page .source-raw-content,
    body:has(.chat-layout) .source-raw-content {
        max-height: none !important;
        overflow: visible !important;
        overscroll-behavior: auto !important;
        touch-action: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    body.chat-page .source-item-preview,
    body:has(.chat-layout) .source-item-preview {
        padding-left: 13px !important;
        -webkit-line-clamp: 3 !important;
    }

    body.chat-page .chat-input-wrapper,
    body:has(.chat-layout) .chat-input-wrapper {
        display: grid !important;
        grid-template-columns: 44px minmax(0, 1fr) 44px !important;
        flex: 0 0 auto !important;
        align-items: stretch !important;
        min-width: 0 !important;
        overflow: visible !important;
        position: relative !important;
        z-index: 2 !important;
    }

    body.chat-page .mode-selector-wrapper,
    body:has(.chat-layout) .mode-selector-wrapper {
        width: 44px !important;
        min-width: 0 !important;
        max-width: 44px !important;
        flex: none !important;
    }

    body.chat-page .mode-selector-wrapper .mode-selector-btn,
    body:has(.chat-layout) .mode-selector-wrapper .mode-selector-btn {
        max-width: 44px !important;
        overflow: hidden !important;
    }

    body.chat-page .chat-input-wrapper > #chat-input,
    body.chat-page .chat-input-wrapper > #chat-send-btn,
    body.chat-page .chat-input-wrapper > .mode-selector-wrapper,
    body:has(.chat-layout) .chat-input-wrapper > #chat-input,
    body:has(.chat-layout) .chat-input-wrapper > #chat-send-btn,
    body:has(.chat-layout) .chat-input-wrapper > .mode-selector-wrapper {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    body.chat-page .mode-selector-wrapper,
    body:has(.chat-layout) .mode-selector-wrapper {
        min-width: 0 !important;
    }

    body.chat-page .mode-selector-btn,
    body.chat-page #chat-send-btn,
    body:has(.chat-layout) .mode-selector-btn,
    body:has(.chat-layout) #chat-send-btn {
        flex: 0 0 44px !important;
        width: 44px !important;
        min-width: 44px !important;
        height: 52px !important;
        min-height: 52px !important;
    }

    body.chat-page #chat-input,
    body:has(.chat-layout) #chat-input {
        flex: 1 1 0 !important;
        width: 0 !important;
        min-width: 0 !important;
        max-width: 100% !important;
        height: 52px !important;
        min-height: 52px !important;
        max-height: min(18dvh, 104px) !important;
    }

    body.chat-page .mode-dropdown,
    body:has(.chat-layout) .mode-dropdown {
        bottom: calc(100% + 8px) !important;
    }

    body.chat-page .chat-input-wrapper > .mode-selector-wrapper,
    body:has(.chat-layout) .chat-input-wrapper > .mode-selector-wrapper {
        grid-column: 1 !important;
    }

    body.chat-page .chat-input-wrapper > #chat-input,
    body:has(.chat-layout) .chat-input-wrapper > #chat-input {
        grid-column: 2 !important;
        width: 100% !important;
        justify-self: stretch !important;
    }

    body.chat-page .chat-input-wrapper > #chat-send-btn,
    body:has(.chat-layout) .chat-input-wrapper > #chat-send-btn {
        grid-column: 3 !important;
        display: flex !important;
        justify-self: stretch !important;
    }
}

@media (max-width: 768px) {
    /* Final usage date restore: keep the real date inputs visible on mobile. */
    body:has(.usage-page-head) .usage-page-head .usage-date-filter {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) 12px minmax(0, 1fr) 42px !important;
        align-items: end !important;
        gap: 8px !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 8px !important;
        border-radius: 10px !important;
        background: #f8faf6 !important;
        border: 1px solid var(--friendly-line-strong, #b9c7bd) !important;
        color-scheme: light !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter > i {
        display: none !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-field {
        min-width: 0 !important;
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 4px !important;
        padding: 0 !important;
        background: transparent !important;
        border: 0 !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-field > span {
        display: block !important;
        color: var(--friendly-accent-hover, #0f766e) !important;
        font-size: 0.72rem !important;
        font-weight: 900 !important;
        line-height: 1 !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter input[type="date"] {
        position: static !important;
        inset: auto !important;
        display: block !important;
        width: 100% !important;
        height: 38px !important;
        min-height: 38px !important;
        padding: 0 8px !important;
        border: 1px solid var(--friendly-line-strong, #b9c7bd) !important;
        border-radius: 8px !important;
        background: #ffffff !important;
        color: var(--friendly-text, #1f2933) !important;
        -webkit-text-fill-color: var(--friendly-text, #1f2933) !important;
        opacity: 1 !important;
        font-size: clamp(0.72rem, 3.1vw, 0.86rem) !important;
        font-weight: 800 !important;
        letter-spacing: 0 !important;
        line-height: 38px !important;
        text-align: left !important;
        appearance: auto !important;
        -webkit-appearance: auto !important;
        color-scheme: light !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter input[type="date"]::-webkit-date-and-time-value {
        color: var(--friendly-text, #1f2933) !important;
        -webkit-text-fill-color: var(--friendly-text, #1f2933) !important;
        text-align: left !important;
        min-height: 38px !important;
        line-height: 38px !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter input[type="date"]::-webkit-calendar-picker-indicator {
        opacity: 0.9 !important;
        filter: none !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-separator {
        align-self: center !important;
        color: var(--friendly-muted, #6b7280) !important;
        font-size: 1rem !important;
        font-weight: 800 !important;
        text-align: center !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter .icon-btn {
        position: static !important;
        width: 42px !important;
        min-width: 42px !important;
        height: 38px !important;
        align-self: end !important;
        justify-self: end !important;
        border-radius: 8px !important;
    }
}

@media (max-width: 768px) {
    /* Final mobile hierarchy pass: keep sub-sections indented and width-balanced. */
    body.chat-page .chat-message .bubble .text-container :where(h1, h2),
    body.chat-page .chat-message .bubble .message-content :where(h1, h2),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2) {
        margin-left: 0 !important;
        max-width: 100% !important;
    }

    body.chat-page .chat-message .bubble .text-container h3,
    body.chat-page .chat-message .bubble .message-content h3,
    body:has(.chat-layout) .chat-message .bubble .text-container h3,
    body:has(.chat-layout) .chat-message .bubble .message-content h3 {
        margin-left: 12px !important;
        max-width: calc(100% - 12px) !important;
        padding-left: 0 !important;
    }

    body.chat-page .chat-message .bubble .text-container h4,
    body.chat-page .chat-message .bubble .message-content h4,
    body:has(.chat-layout) .chat-message .bubble .text-container h4,
    body:has(.chat-layout) .chat-message .bubble .message-content h4 {
        margin-left: 20px !important;
        max-width: calc(100% - 20px) !important;
        padding-left: 0 !important;
    }

    body.chat-page .chat-message .bubble .text-container .markdown-section-body,
    body.chat-page .chat-message .bubble .message-content .markdown-section-body,
    body.chat-page .chat-message .bubble .text-container :where(h3, h4) + :where(p, ul, ol, blockquote, div),
    body.chat-page .chat-message .bubble .message-content :where(h3, h4) + :where(p, ul, ol, blockquote, div),
    body:has(.chat-layout) .chat-message .bubble .text-container .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .message-content .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h3, h4) + :where(p, ul, ol, blockquote, div),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h3, h4) + :where(p, ul, ol, blockquote, div) {
        margin-left: 12px !important;
        max-width: calc(100% - 12px) !important;
        padding-left: 0 !important;
        border-left: 0 !important;
        box-sizing: border-box !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(ul, ol),
    body.chat-page .chat-message .bubble .message-content :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(ul, ol) {
        padding-left: 1.2rem !important;
        box-sizing: border-box !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(ul, ol) :where(ul, ol),
    body.chat-page .chat-message .bubble .message-content :where(ul, ol) :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(ul, ol) :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(ul, ol) :where(ul, ol) {
        margin-left: 8px !important;
        max-width: calc(100% - 8px) !important;
    }

    body:has(.usage-page-head) .usage-history-open-btn {
        display: none !important;
    }

    body:has(.usage-page-head) .usage-workspace-actions {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    /* Final mobile hierarchy pass: preserve readable nested structure inside AI answers. */
    body.chat-page .chat-message .bubble .text-container :where(h1, h2),
    body.chat-page .chat-message .bubble .message-content :where(h1, h2),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2) {
        margin-left: 0 !important;
        max-width: 100% !important;
    }

    body.chat-page .chat-message .bubble .text-container h3,
    body.chat-page .chat-message .bubble .message-content h3,
    body:has(.chat-layout) .chat-message .bubble .text-container h3,
    body:has(.chat-layout) .chat-message .bubble .message-content h3 {
        margin-left: 12px !important;
        max-width: calc(100% - 12px) !important;
        padding-left: 0 !important;
    }

    body.chat-page .chat-message .bubble .text-container h4,
    body.chat-page .chat-message .bubble .message-content h4,
    body:has(.chat-layout) .chat-message .bubble .text-container h4,
    body:has(.chat-layout) .chat-message .bubble .message-content h4 {
        margin-left: 20px !important;
        max-width: calc(100% - 20px) !important;
        padding-left: 0 !important;
    }

    body.chat-page .chat-message .bubble .text-container .markdown-section-body,
    body.chat-page .chat-message .bubble .message-content .markdown-section-body,
    body.chat-page .chat-message .bubble .text-container :where(h3, h4) + :where(p, ul, ol, blockquote, div),
    body.chat-page .chat-message .bubble .message-content :where(h3, h4) + :where(p, ul, ol, blockquote, div),
    body:has(.chat-layout) .chat-message .bubble .text-container .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .message-content .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h3, h4) + :where(p, ul, ol, blockquote, div),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h3, h4) + :where(p, ul, ol, blockquote, div) {
        margin-left: 12px !important;
        max-width: calc(100% - 12px) !important;
        padding-left: 0 !important;
        border-left: 0 !important;
        box-sizing: border-box !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(ul, ol),
    body.chat-page .chat-message .bubble .message-content :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(ul, ol) {
        padding-left: 1.2rem !important;
        box-sizing: border-box !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(ul, ol) :where(ul, ol),
    body.chat-page .chat-message .bubble .message-content :where(ul, ol) :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(ul, ol) :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(ul, ol) :where(ul, ol) {
        margin-left: 8px !important;
        max-width: calc(100% - 8px) !important;
    }

    /* Usage already has the floating history launcher; hide the duplicate workspace button on mobile. */
    body:has(.usage-page-head) .usage-history-open-btn {
        display: none !important;
    }

    body:has(.usage-page-head) .usage-workspace-actions {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    body:has(.usage-page-head) .usage-page-head .usage-date-filter {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) 12px minmax(0, 1fr) 42px !important;
        align-items: end !important;
        gap: 8px !important;
        width: 100% !important;
        padding: 8px !important;
        border-radius: 10px !important;
        background: #f8faf6 !important;
        border: 1px solid var(--friendly-line-strong, #b9c7bd) !important;
        box-shadow: none !important;
        color-scheme: light !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter > i {
        display: none !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-field {
        min-width: 0 !important;
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 4px !important;
        padding: 0 !important;
        background: transparent !important;
        border: 0 !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-field > span {
        display: block !important;
        color: var(--friendly-accent-hover, #0f766e) !important;
        font-size: 0.72rem !important;
        font-weight: 900 !important;
        line-height: 1 !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter input[type="date"] {
        position: static !important;
        inset: auto !important;
        display: block !important;
        width: 100% !important;
        height: 38px !important;
        min-height: 38px !important;
        padding: 0 8px !important;
        border: 1px solid var(--friendly-line-strong, #b9c7bd) !important;
        border-radius: 8px !important;
        background: #ffffff !important;
        color: var(--friendly-text, #1f2933) !important;
        -webkit-text-fill-color: var(--friendly-text, #1f2933) !important;
        opacity: 1 !important;
        font-size: clamp(0.72rem, 3.1vw, 0.86rem) !important;
        font-weight: 800 !important;
        letter-spacing: 0 !important;
        line-height: 38px !important;
        text-align: left !important;
        appearance: auto !important;
        -webkit-appearance: auto !important;
        color-scheme: light !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter input[type="date"]::-webkit-date-and-time-value {
        color: var(--friendly-text, #1f2933) !important;
        -webkit-text-fill-color: var(--friendly-text, #1f2933) !important;
        text-align: left !important;
        min-height: 38px !important;
        line-height: 38px !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter input[type="date"]::-webkit-calendar-picker-indicator {
        opacity: 0.9 !important;
        filter: none !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-separator {
        align-self: center !important;
        color: var(--friendly-muted, #6b7280) !important;
        font-size: 1rem !important;
        font-weight: 800 !important;
        text-align: center !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter .icon-btn {
        position: static !important;
        width: 42px !important;
        min-width: 42px !important;
        height: 38px !important;
        align-self: end !important;
        justify-self: end !important;
        border-radius: 8px !important;
    }
}

@media (max-width: 420px) {
    .mobile-bottom-nav a {
        font-size: 0.64rem;
    }

    .mobile-bottom-nav a i {
        font-size: 0.95rem;
    }

    .top-bar-left h1,
    .top-bar .logo span {
        max-width: 92px;
    }
}

@media (max-width: 768px) {
    :where(html, body) {
        max-width: 100%;
    }

    :where(body, .top-bar, main, section, article, div, form, nav, header, footer) {
        min-width: 0;
    }

    :where(img, svg, canvas, video, iframe) {
        max-width: 100%;
    }

    body:has(.usage-page-head) .usage-page-head .date-filter {
        grid-template-columns: minmax(0, 1fr) 10px minmax(0, 1fr) 34px !important;
        gap: 5px !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 7px !important;
        background: #f7faf5 !important;
        color-scheme: light !important;
    }

    body:has(.usage-page-head) .usage-page-head .date-filter > i {
        display: none !important;
    }

    body:has(.usage-page-head) .usage-page-head .date-field {
        min-width: 0 !important;
        padding: 6px 5px !important;
    }

    body:has(.usage-page-head) .usage-page-head .date-field > span {
        font-size: clamp(0.6rem, 2.45vw, 0.68rem) !important;
        line-height: 1 !important;
    }

    body:has(.usage-page-head) .usage-page-head .date-display {
        min-width: 0 !important;
        font-size: clamp(0.66rem, 2.9vw, 0.76rem) !important;
        line-height: 1.08 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: clip !important;
    }

    body:has(.usage-page-head) .usage-page-head .date-filter input {
        min-width: 0 !important;
        height: 32px !important;
        padding: 0 4px !important;
        font-size: clamp(0.66rem, 2.8vw, 0.76rem) !important;
        letter-spacing: 0 !important;
        text-align: center !important;
        background: #ffffff !important;
        color: var(--friendly-text) !important;
        color-scheme: light !important;
    }

    body:has(.usage-page-head) .usage-page-head .date-filter .icon-btn {
        width: 32px !important;
        min-width: 32px !important;
        height: 32px !important;
    }

    body:has(.usage-page-head) :where(.usage-main, .usage-main-stack, .usage-main-panel, .usage-tip-panel, .usage-overview-section, .usage-chart-grid, .usage-workspace-panel, .usage-workspace-control, .usage-section-title, .summary-cards) {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-x: hidden !important;
    }

    body:has(.usage-page-head) .usage-recent-card {
        padding: 12px !important;
    }

    body:has(.usage-page-head) .usage-recent-card-inner,
    body:has(.usage-page-head) .usage-recent-metrics {
        grid-template-columns: 1fr !important;
        width: 100% !important;
        min-width: 0 !important;
    }

    body:has(.usage-page-head) .usage-recent-title,
    body:has(.usage-page-head) .usage-recent-metrics .stat-info {
        min-width: 0 !important;
        width: 100% !important;
    }

    body:has(.usage-page-head) .usage-recent-metrics .stat-value,
    body:has(.usage-page-head) .stat-value,
    body:has(.usage-page-head) .metric-card strong {
        font-size: clamp(0.86rem, 4vw, 1.08rem) !important;
        line-height: 1.12 !important;
        overflow-wrap: anywhere !important;
    }

    body.chat-page .chat-layout,
    body:has(.chat-layout) .chat-layout,
    body.chat-page .chat-window,
    body:has(.chat-layout) .chat-window,
    body.chat-page .chat-message,
    body:has(.chat-layout) .chat-message,
    body.chat-page .chat-message .bubble,
    body:has(.chat-layout) .chat-message .bubble,
    body.chat-page .chat-message .bubble > *,
    body:has(.chat-layout) .chat-message .bubble > *,
    body.chat-page .text-container,
    body:has(.chat-layout) .text-container,
    body.chat-page .message-content,
    body:has(.chat-layout) .message-content,
    body.chat-page .sources-container,
    body:has(.chat-layout) .sources-container,
    body.chat-page .sources-content,
    body:has(.chat-layout) .sources-content,
    body.chat-page .source-module-group,
    body:has(.chat-layout) .source-module-group,
    body.chat-page .source-module-list,
    body:has(.chat-layout) .source-module-list,
    body.chat-page .source-item,
    body:has(.chat-layout) .source-item,
    body.chat-page .source-item-body,
    body:has(.chat-layout) .source-item-body,
    body.chat-page .source-body-article,
    body:has(.chat-layout) .source-body-article,
    body.chat-page .source-body-paragraphs,
    body:has(.chat-layout) .source-body-paragraphs,
    body.chat-page .source-raw-details,
    body:has(.chat-layout) .source-raw-details,
    body.chat-page .source-raw-content,
    body:has(.chat-layout) .source-raw-content {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    body.chat-page .chat-message .bubble,
    body:has(.chat-layout) .chat-message .bubble {
        padding: 12px 10px 12px 16px !important;
        overflow-x: hidden !important;
    }

    body.chat-page .text-container,
    body.chat-page .message-content,
    body:has(.chat-layout) .text-container,
    body:has(.chat-layout) .message-content {
        font-size: clamp(0.86rem, 3.75vw, 0.95rem) !important;
        line-height: 1.62 !important;
    }

    body.chat-page .text-container :where(p, li, blockquote, div, span),
    body.chat-page .message-content :where(p, li, blockquote, div, span),
    body.chat-page .source-item-body :where(p, li, div, span),
    body:has(.chat-layout) .text-container :where(p, li, blockquote, div, span),
    body:has(.chat-layout) .message-content :where(p, li, blockquote, div, span),
    body:has(.chat-layout) .source-item-body :where(p, li, div, span) {
        max-width: 100% !important;
        overflow-wrap: anywhere !important;
        word-break: keep-all !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(h1, h2, h3, h4),
    body.chat-page .chat-message .bubble .message-content :where(h1, h2, h3, h4),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2, h3, h4),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2, h3, h4) {
        margin-left: 0 !important;
        padding-left: 8px !important;
        font-size: clamp(0.98rem, 4.45vw, 1.16rem) !important;
        line-height: 1.35 !important;
    }

    body.chat-page .chat-message .bubble .text-container .markdown-section-body,
    body.chat-page .chat-message .bubble .message-content .markdown-section-body,
    body.chat-page .chat-message .bubble .text-container :where(h1, h2, h3, h4) + :where(p, ul, ol),
    body.chat-page .chat-message .bubble .message-content :where(h1, h2, h3, h4) + :where(p, ul, ol),
    body:has(.chat-layout) .chat-message .bubble .text-container .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .message-content .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2, h3, h4) + :where(p, ul, ol),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2, h3, h4) + :where(p, ul, ol) {
        margin-left: 8px !important;
        padding-left: 10px !important;
    }

    body.chat-page .chat-message .bubble :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble :where(ul, ol) {
        padding-left: 1.15rem !important;
    }

    body.chat-page .markdown-table-scroll,
    body:has(.chat-layout) .markdown-table-scroll {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior-x: contain !important;
        touch-action: pan-x pan-y !important;
    }

    body.chat-page .chat-message .bubble table,
    body.chat-page .source-item-body table,
    body:has(.chat-layout) .chat-message .bubble table,
    body:has(.chat-layout) .source-item-body table {
        width: max-content !important;
        min-width: min(100%, 560px) !important;
        max-width: none !important;
    }

    body.chat-page .source-module-header,
    body:has(.chat-layout) .source-module-header {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto !important;
        min-width: 0 !important;
    }

    body.chat-page .source-module-title,
    body.chat-page .source-title-main,
    body:has(.chat-layout) .source-module-title,
    body:has(.chat-layout) .source-title-main {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    body.chat-page .source-score,
    body:has(.chat-layout) .source-score,
    body.chat-page .source-meta-tag,
    body:has(.chat-layout) .source-meta-tag,
    body.chat-page .source-module-count,
    body:has(.chat-layout) .source-module-count {
        font-size: clamp(0.62rem, 2.6vw, 0.72rem) !important;
        line-height: 1.15 !important;
        padding: 4px 6px !important;
        max-width: 100% !important;
    }

    body.chat-page .source-empty-state,
    body:has(.chat-layout) .source-empty-state,
    body.chat-page .source-module-group:not(:has(.source-item)),
    body:has(.chat-layout) .source-module-group:not(:has(.source-item)) {
        display: none !important;
    }

    body.chat-page .sources-container.expanded .sources-content,
    body:has(.chat-layout) .sources-container.expanded .sources-content {
        max-height: min(54dvh, 440px) !important;
        padding: 10px !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    body.chat-page .source-item.expanded .source-item-body,
    body:has(.chat-layout) .source-item.expanded .source-item-body {
        max-height: none !important;
        padding: 10px !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
    }

    body.chat-page .source-raw-content,
    body:has(.chat-layout) .source-raw-content {
        max-height: 220px !important;
        overflow: auto !important;
        padding: 9px !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(h1, h2, h3, h4),
    body.chat-page .chat-message .bubble .message-content :where(h1, h2, h3, h4),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2, h3, h4),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2, h3, h4) {
        padding-left: 9px !important;
        margin-top: 0.9rem !important;
        border-left-width: 3px !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(h1, h2, h3, h4) + :where(p, ul, ol),
    body.chat-page .chat-message .bubble .message-content :where(h1, h2, h3, h4) + :where(p, ul, ol),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2, h3, h4) + :where(p, ul, ol),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2, h3, h4) + :where(p, ul, ol) {
        margin-left: 10px !important;
    }
}

@media (max-width: 380px) {
    body:has(.usage-page-head) .usage-page-head .date-filter {
        grid-template-columns: minmax(0, 1fr) 8px minmax(0, 1fr) 32px !important;
    }

    body:has(.usage-page-head) .usage-page-head .date-filter > i {
        display: none !important;
    }

    body:has(.usage-page-head) .usage-page-head .date-filter input {
        font-size: 0.66rem !important;
    }
}

@media (max-width: 768px) {
    /* Mobile clarity pass: prioritize readable content over desktop density. */
    body.mobile-shell-ready .app-history-toggle {
        display: none !important;
    }

    body:has(.usage-page-head) .container {
        padding: 14px 10px calc(var(--mobile-bottom-nav-height) + 18px + env(safe-area-inset-bottom)) !important;
    }

    body:has(.usage-page-head) .usage-main-stack {
        gap: 12px !important;
    }

    body:has(.usage-page-head) .usage-recent-card,
    body:has(.usage-page-head) .usage-tip-panel,
    body:has(.usage-page-head) .usage-workspace-panel,
    body:has(.usage-page-head) .users-section {
        border-radius: 8px !important;
        box-shadow: 0 8px 20px rgba(23, 32, 25, 0.08) !important;
    }

    body:has(.usage-page-head) .usage-recent-card {
        padding: 14px !important;
    }

    body:has(.usage-page-head) .usage-recent-title {
        display: grid !important;
        grid-template-columns: 46px minmax(0, 1fr) !important;
        gap: 12px !important;
        align-items: center !important;
    }

    body:has(.usage-page-head) .usage-recent-title-icon {
        width: 46px !important;
        height: 46px !important;
        border-radius: 8px !important;
    }

    body:has(.usage-page-head) .usage-recent-title h4 {
        margin: 0 !important;
        font-size: 1rem !important;
        line-height: 1.25 !important;
    }

    body:has(.usage-page-head) .usage-recent-title p {
        margin: 4px 0 0 !important;
        font-size: 0.82rem !important;
        line-height: 1.25 !important;
    }

    body:has(.usage-page-head) .usage-recent-metrics {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px 10px !important;
        margin-top: 14px !important;
    }

    body:has(.usage-page-head) .usage-recent-metrics .stat-info {
        padding: 0 !important;
        border: 0 !important;
    }

    body:has(.usage-page-head) .usage-recent-metrics .stat-label {
        font-size: 0.72rem !important;
        line-height: 1.1 !important;
    }

    body:has(.usage-page-head) .usage-recent-metrics .stat-value {
        margin-top: 4px !important;
        font-size: 1rem !important;
        line-height: 1.15 !important;
    }

    body:has(.usage-page-head) .usage-tip-panel {
        display: grid !important;
        grid-template-columns: minmax(0, auto) minmax(0, 1fr) !important;
        gap: 12px !important;
        align-items: start !important;
        padding: 13px 14px !important;
    }

    body:has(.usage-page-head) .usage-tip-label {
        white-space: nowrap !important;
        font-size: 0.78rem !important;
    }

    body:has(.usage-page-head) .usage-tip-panel p {
        margin: 0 !important;
        font-size: 0.9rem !important;
        line-height: 1.55 !important;
    }

    body:has(.usage-page-head) .usage-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }

    body:has(.usage-page-head) .usage-summary-grid .stat-card {
        min-height: 92px !important;
        padding: 12px !important;
        display: grid !important;
        grid-template-columns: 44px minmax(0, 1fr) !important;
        gap: 10px !important;
        align-items: center !important;
    }

    body:has(.usage-page-head) .usage-summary-grid .stat-icon {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        border-radius: 8px !important;
    }

    body:has(.usage-page-head) .usage-summary-grid .stat-value {
        font-size: clamp(1rem, 4.4vw, 1.2rem) !important;
        line-height: 1.08 !important;
    }

    body:has(.usage-page-head) .usage-summary-grid .stat-label {
        margin-top: 3px !important;
        font-size: clamp(0.68rem, 2.8vw, 0.78rem) !important;
        line-height: 1.18 !important;
    }

    body:has(.usage-page-head) .usage-workspace-panel {
        padding: 0 !important;
        overflow: hidden !important;
    }

    body:has(.usage-page-head) .usage-workspace-head {
        padding: 18px 14px 14px !important;
        gap: 14px !important;
    }

    body:has(.usage-page-head) .usage-workspace-head h3 {
        margin: 8px 0 0 !important;
        font-size: 1.08rem !important;
        line-height: 1.36 !important;
        letter-spacing: 0 !important;
    }

    body:has(.usage-page-head) .usage-workspace-head p {
        margin: 8px 0 0 !important;
        font-size: 0.88rem !important;
        line-height: 1.55 !important;
    }

    body:has(.usage-page-head) .usage-workspace-actions {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    body:has(.usage-page-head) .usage-workspace-actions .view-btn {
        min-height: 46px !important;
        padding: 0 12px !important;
        justify-content: flex-start !important;
        gap: 10px !important;
        background: #185f4b !important;
        border-color: #185f4b !important;
        color: #ffffff !important;
        font-size: 0.92rem !important;
        font-weight: 850 !important;
    }

    body:has(.usage-page-head) .usage-workspace-control {
        padding: 12px 14px 14px !important;
        gap: 10px !important;
        background: #f7faf5 !important;
        border-top: 1px solid var(--friendly-line) !important;
    }

    body:has(.usage-page-head) .usage-workspace-panel .usage-nav-tabs {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    body:has(.usage-page-head) .usage-workspace-panel .usage-nav-tabs .tab-btn {
        width: 100% !important;
        min-height: 56px !important;
        padding: 10px 12px !important;
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        align-items: center !important;
        text-align: left !important;
        background: #ffffff !important;
        border: 1px solid #98a896 !important;
        color: #151a16 !important;
        box-shadow: none !important;
    }

    body:has(.usage-page-head) .usage-workspace-panel .usage-nav-tabs .tab-btn span {
        display: flex !important;
        align-items: center !important;
        gap: 9px !important;
        color: #151a16 !important;
        font-size: 0.95rem !important;
        font-weight: 900 !important;
        line-height: 1.2 !important;
    }

    body:has(.usage-page-head) .usage-workspace-panel .usage-nav-tabs .tab-btn small {
        margin-top: 4px !important;
        color: #3f493f !important;
        font-size: 0.76rem !important;
        font-weight: 750 !important;
        line-height: 1.2 !important;
    }

    body:has(.usage-page-head) .usage-workspace-panel .usage-nav-tabs .tab-btn.active {
        background: #dcebe3 !important;
        border-color: #185f4b !important;
        color: #104938 !important;
        box-shadow: inset 5px 0 0 #185f4b !important;
    }

    body:has(.usage-page-head) .usage-workspace-panel .usage-nav-tabs .tab-btn.active span,
    body:has(.usage-page-head) .usage-workspace-panel .usage-nav-tabs .tab-btn.active small {
        color: #104938 !important;
    }

    body:has(.usage-page-head) .usage-active-note {
        display: grid !important;
        grid-template-columns: 20px minmax(0, 1fr) !important;
        gap: 8px !important;
        padding: 11px 12px !important;
        background: #ffffff !important;
        border: 1px solid #98a896 !important;
        color: #151a16 !important;
        font-size: 0.88rem !important;
        line-height: 1.5 !important;
    }

    body:has(.usage-page-head) .usage-active-note::before {
        content: "i";
        width: 20px;
        height: 20px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        background: #185f4b;
        color: #ffffff;
        font-size: 0.78rem;
        font-weight: 900;
        font-family: Georgia, serif;
    }

    body:has(.usage-page-head) .users-section {
        padding: 14px !important;
        margin: 0 !important;
    }

    body:has(.usage-page-head) .usage-section-title h3 {
        margin: 0 0 6px !important;
        font-size: 1.04rem !important;
        line-height: 1.3 !important;
    }

    body:has(.usage-page-head) .usage-section-title p {
        margin: 0 !important;
        font-size: 0.86rem !important;
        line-height: 1.5 !important;
    }

    body:has(.usage-page-head) .table-wrapper {
        max-height: 54dvh !important;
        margin-top: 12px !important;
        border: 1px solid var(--friendly-line) !important;
        border-radius: 8px !important;
        overflow: auto !important;
    }

    body:has(.usage-page-head) #usageLogsTable {
        min-width: 620px !important;
        font-size: 0.84rem !important;
    }

    body:has(.usage-page-head) #usageLogsTable th,
    body:has(.usage-page-head) #usageLogsTable td {
        padding: 10px 12px !important;
        line-height: 1.35 !important;
    }

    body.chat-page .chat-layout,
    body:has(.chat-layout) .chat-layout {
        height: calc(100dvh - var(--mobile-header-height) - var(--mobile-bottom-nav-height) - env(safe-area-inset-bottom)) !important;
    }

    body.chat-page .chat-header,
    body:has(.chat-layout) .chat-header {
        padding: 10px 10px 12px !important;
        gap: 7px !important;
        border-bottom: 1px solid var(--friendly-line) !important;
    }

    body.chat-page .chat-header h2,
    body:has(.chat-layout) .chat-header h2 {
        font-size: 1rem !important;
        line-height: 1.25 !important;
    }

    body.chat-page .status-indicator,
    body:has(.chat-layout) .status-indicator {
        max-width: min(100%, 300px) !important;
        min-height: 34px !important;
        padding: 6px 10px !important;
        font-size: 0.82rem !important;
    }

    body.chat-page .chat-window,
    body:has(.chat-layout) .chat-window {
        padding: 14px 10px 96px !important;
        scroll-padding-top: 16px !important;
        scroll-padding-bottom: 104px !important;
    }

    body.chat-page .chat-message.welcome-message .bubble,
    body:has(.chat-layout) .chat-message.welcome-message .bubble {
        padding: 14px !important;
    }

    body.chat-page .welcome-headline-row,
    body:has(.chat-layout) .welcome-headline-row {
        padding-bottom: 12px !important;
        gap: 8px !important;
    }

    body.chat-page .welcome-guide h3,
    body:has(.chat-layout) .welcome-guide h3 {
        font-size: 1.02rem !important;
        line-height: 1.35 !important;
    }

    body.chat-page .welcome-guide p,
    body:has(.chat-layout) .welcome-guide p {
        font-size: 0.86rem !important;
        line-height: 1.55 !important;
    }

    body.chat-page .quick-question-grid,
    body:has(.chat-layout) .quick-question-grid {
        gap: 8px !important;
    }

    body.chat-page .quick-question-grid button,
    body:has(.chat-layout) .quick-question-grid button {
        min-height: 48px !important;
        padding: 10px 12px !important;
        font-size: 0.9rem !important;
        line-height: 1.25 !important;
    }

    body.chat-page .ask-better-note,
    body:has(.chat-layout) .ask-better-note {
        align-items: flex-start !important;
        padding: 10px 12px !important;
        font-size: 0.86rem !important;
        line-height: 1.55 !important;
    }

    body.chat-page .chat-message .bubble,
    body:has(.chat-layout) .chat-message .bubble {
        font-size: 0.94rem !important;
        line-height: 1.7 !important;
    }

    body.chat-page .text-container,
    body.chat-page .message-content,
    body:has(.chat-layout) .text-container,
    body:has(.chat-layout) .message-content {
        font-size: 0.94rem !important;
        line-height: 1.72 !important;
    }

    body.chat-page .chat-input-wrapper,
    body:has(.chat-layout) .chat-input-wrapper {
        grid-template-columns: 42px minmax(0, 1fr) 48px !important;
        padding: 8px 10px 10px !important;
        gap: 7px !important;
        border-top: 1px solid var(--friendly-line) !important;
    }

    body.chat-page #chat-input,
    body:has(.chat-layout) #chat-input {
        height: 56px !important;
        min-height: 56px !important;
        padding: 10px 12px !important;
        font-size: 0.92rem !important;
        line-height: 1.35 !important;
    }

    body.chat-page .mode-selector-btn,
    body:has(.chat-layout) .mode-selector-btn {
        width: 42px !important;
        min-width: 42px !important;
        height: 56px !important;
        min-height: 56px !important;
    }

    body.chat-page #chat-send-btn,
    body:has(.chat-layout) #chat-send-btn {
        width: 48px !important;
        min-width: 48px !important;
        height: 56px !important;
        min-height: 56px !important;
    }
}

@media (max-width: 380px) {
    body:has(.usage-page-head) .usage-summary-grid {
        grid-template-columns: 1fr !important;
    }

    body:has(.usage-page-head) .usage-tip-panel {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    /* Restore the mobile history launcher: visible, clickable, and compact. */
    body.mobile-shell-ready .app-history-toggle {
        display: inline-flex !important;
        left: 12px !important;
        right: auto !important;
        bottom: calc(var(--mobile-bottom-nav-height) + 10px + env(safe-area-inset-bottom)) !important;
        width: auto !important;
        min-width: 108px !important;
        max-width: calc(100vw - 24px) !important;
        height: 42px !important;
        padding: 0 12px !important;
        border-radius: 8px !important;
        background: #111827 !important;
        border: 1px solid rgba(255, 255, 255, 0.14) !important;
        color: #f8fafc !important;
        box-shadow: 0 10px 24px rgba(17, 24, 39, 0.32) !important;
        opacity: 0.96 !important;
        z-index: 9998 !important;
        transform: none !important;
    }

    body.mobile-shell-ready .app-history-toggle span {
        display: inline !important;
        color: inherit !important;
        font-size: 0.86rem !important;
        font-weight: 850 !important;
        line-height: 1 !important;
    }

    body.mobile-shell-ready .app-history-toggle i {
        color: inherit !important;
        font-size: 0.95rem !important;
    }

    body.app-history-open .app-history-toggle {
        opacity: 0 !important;
        pointer-events: none !important;
    }

    /* Mobile answer reset: remove desktop rails and artificial markdown indentation. */
    body.chat-page .chat-message.ai,
    body:has(.chat-layout) .chat-message.ai {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 0 12px !important;
    }

    body.chat-page .chat-message.ai .bubble,
    body:has(.chat-layout) .chat-message.ai .bubble {
        background: #ffffff !important;
        border: 1px solid #c2cec1 !important;
        border-left: 6px solid var(--friendly-accent) !important;
        border-radius: 8px !important;
        padding: 15px 14px 15px 26px !important;
        box-shadow: 0 6px 18px rgba(23, 32, 25, 0.07) !important;
        color: #151a16 !important;
        font-size: 0.95rem !important;
        line-height: 1.72 !important;
        position: relative !important;
    }

    body.chat-page .chat-message.ai .bubble::before,
    body:has(.chat-layout) .chat-message.ai .bubble::before {
        display: block !important;
        content: "" !important;
        position: absolute !important;
        top: 12px !important;
        bottom: 12px !important;
        left: 12px !important;
        width: 1px !important;
        background: rgba(24, 95, 75, 0.28) !important;
        opacity: 0.46 !important;
        pointer-events: none !important;
    }

    body.chat-page .chat-message.user .bubble,
    body:has(.chat-layout) .chat-message.user .bubble {
        border: 1px solid #98a896 !important;
        border-right: 6px solid #2563eb !important;
        padding: 13px 22px 13px 14px !important;
        background: #dcebe3 !important;
        box-shadow: none !important;
        position: relative !important;
    }

    body.chat-page .chat-message.user .bubble::before,
    body:has(.chat-layout) .chat-message.user .bubble::before {
        display: block !important;
        content: "" !important;
        position: absolute !important;
        top: 10px !important;
        bottom: 10px !important;
        right: 10px !important;
        width: 1px !important;
        background: rgba(37, 99, 235, 0.25) !important;
        opacity: 0.46 !important;
        pointer-events: none !important;
    }

    body.chat-page .chat-message .bubble .text-container,
    body.chat-page .chat-message .bubble .message-content,
    body:has(.chat-layout) .chat-message .bubble .text-container,
    body:has(.chat-layout) .chat-message .bubble .message-content {
        color: #151a16 !important;
        font-size: 0.95rem !important;
        line-height: 1.72 !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(h1, h2, h3, h4),
    body.chat-page .chat-message .bubble .message-content :where(h1, h2, h3, h4),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2, h3, h4),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2, h3, h4) {
        margin: 1rem 0 0.55rem !important;
        padding: 0 0 0.35rem !important;
        border-left: 0 !important;
        border-bottom: 1px solid #d7dfd5 !important;
        color: #104938 !important;
        font-size: clamp(1.02rem, 4.4vw, 1.18rem) !important;
        font-weight: 900 !important;
        line-height: 1.34 !important;
        letter-spacing: 0 !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(h1, h2, h3, h4):first-child,
    body.chat-page .chat-message .bubble .message-content :where(h1, h2, h3, h4):first-child,
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2, h3, h4):first-child,
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2, h3, h4):first-child {
        margin-top: 0 !important;
    }

    body.chat-page .chat-message .bubble .text-container .markdown-section-body,
    body.chat-page .chat-message .bubble .message-content .markdown-section-body,
    body.chat-page .chat-message .bubble .text-container :where(h1, h2, h3, h4) + :where(p, ul, ol, blockquote, div),
    body.chat-page .chat-message .bubble .message-content :where(h1, h2, h3, h4) + :where(p, ul, ol, blockquote, div),
    body:has(.chat-layout) .chat-message .bubble .text-container .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .message-content .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2, h3, h4) + :where(p, ul, ol, blockquote, div),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2, h3, h4) + :where(p, ul, ol, blockquote, div) {
        margin-left: 0 !important;
        padding-left: 0 !important;
        border-left: 0 !important;
    }

    body.chat-page .chat-message .bubble .text-container p,
    body.chat-page .chat-message .bubble .message-content p,
    body:has(.chat-layout) .chat-message .bubble .text-container p,
    body:has(.chat-layout) .chat-message .bubble .message-content p {
        margin: 0 0 0.85rem !important;
        color: #151a16 !important;
        line-height: 1.72 !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(ul, ol),
    body.chat-page .chat-message .bubble .message-content :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(ul, ol) {
        margin: 0.55rem 0 0.9rem !important;
        padding-left: 1.25rem !important;
        border-left: 0 !important;
    }

    body.chat-page .chat-message .bubble .text-container li,
    body.chat-page .chat-message .bubble .message-content li,
    body:has(.chat-layout) .chat-message .bubble .text-container li,
    body:has(.chat-layout) .chat-message .bubble .message-content li {
        margin-bottom: 0.45rem !important;
        padding-left: 0.1rem !important;
    }

    body.chat-page .chat-message .bubble .text-container blockquote,
    body.chat-page .chat-message .bubble .message-content blockquote,
    body:has(.chat-layout) .chat-message .bubble .text-container blockquote,
    body:has(.chat-layout) .chat-message .bubble .message-content blockquote {
        margin: 0.8rem 0 !important;
        padding: 10px 12px !important;
        border-left: 3px solid #185f4b !important;
        border-radius: 8px !important;
        background: #eef6f1 !important;
        color: #2f3b32 !important;
        font-style: normal !important;
    }

    body.chat-page .chat-message .bubble .text-container strong,
    body.chat-page .chat-message .bubble .message-content strong,
    body:has(.chat-layout) .chat-message .bubble .text-container strong,
    body:has(.chat-layout) .chat-message .bubble .message-content strong {
        color: #104938 !important;
        font-weight: 900 !important;
    }

    body.chat-page .quality-box,
    body.chat-page .iteration-box,
    body.chat-page .intent-box,
    body:has(.chat-layout) .quality-box,
    body:has(.chat-layout) .iteration-box,
    body:has(.chat-layout) .intent-box {
        border-radius: 8px !important;
        box-shadow: none !important;
    }
}

@media (max-width: 768px) {
    /* Final usage date restore: keep the real date inputs visible on mobile. */
    body:has(.usage-page-head) .usage-page-head .usage-date-filter {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) 12px minmax(0, 1fr) 42px !important;
        align-items: end !important;
        gap: 8px !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 8px !important;
        border-radius: 10px !important;
        background: #f8faf6 !important;
        border: 1px solid var(--friendly-line-strong, #b9c7bd) !important;
        color-scheme: light !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter > i {
        display: none !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-field {
        min-width: 0 !important;
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 4px !important;
        padding: 0 !important;
        background: transparent !important;
        border: 0 !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-field > span {
        display: block !important;
        color: var(--friendly-accent-hover, #0f766e) !important;
        font-size: 0.72rem !important;
        font-weight: 900 !important;
        line-height: 1 !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter input[type="date"] {
        position: static !important;
        inset: auto !important;
        display: block !important;
        width: 100% !important;
        height: 38px !important;
        min-height: 38px !important;
        padding: 0 8px !important;
        border: 1px solid var(--friendly-line-strong, #b9c7bd) !important;
        border-radius: 8px !important;
        background: #ffffff !important;
        color: var(--friendly-text, #1f2933) !important;
        -webkit-text-fill-color: var(--friendly-text, #1f2933) !important;
        opacity: 1 !important;
        font-size: clamp(0.72rem, 3.1vw, 0.86rem) !important;
        font-weight: 800 !important;
        letter-spacing: 0 !important;
        line-height: 38px !important;
        text-align: left !important;
        appearance: auto !important;
        -webkit-appearance: auto !important;
        color-scheme: light !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter input[type="date"]::-webkit-date-and-time-value {
        color: var(--friendly-text, #1f2933) !important;
        -webkit-text-fill-color: var(--friendly-text, #1f2933) !important;
        text-align: left !important;
        min-height: 38px !important;
        line-height: 38px !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter input[type="date"]::-webkit-calendar-picker-indicator {
        opacity: 0.9 !important;
        filter: none !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-separator {
        align-self: center !important;
        color: var(--friendly-muted, #6b7280) !important;
        font-size: 1rem !important;
        font-weight: 800 !important;
        text-align: center !important;
    }

    body:has(.usage-page-head) .usage-page-head .usage-date-filter .icon-btn {
        position: static !important;
        width: 42px !important;
        min-width: 42px !important;
        height: 38px !important;
        align-self: end !important;
        justify-self: end !important;
        border-radius: 8px !important;
    }
}

@media (max-width: 768px) {
    /* EOF mobile hierarchy pass: this must stay after all other mobile answer resets. */
    body.chat-page .chat-message .bubble .text-container h3,
    body.chat-page .chat-message .bubble .message-content h3,
    body:has(.chat-layout) .chat-message .bubble .text-container h3,
    body:has(.chat-layout) .chat-message .bubble .message-content h3 {
        margin-left: 12px !important;
        max-width: calc(100% - 12px) !important;
    }

    body.chat-page .chat-message .bubble .text-container h4,
    body.chat-page .chat-message .bubble .message-content h4,
    body:has(.chat-layout) .chat-message .bubble .text-container h4,
    body:has(.chat-layout) .chat-message .bubble .message-content h4 {
        margin-left: 20px !important;
        max-width: calc(100% - 20px) !important;
    }

    body.chat-page .chat-message .bubble .text-container .markdown-section-body,
    body.chat-page .chat-message .bubble .message-content .markdown-section-body,
    body.chat-page .chat-message .bubble .text-container :where(h3, h4) + :where(p, ul, ol, blockquote, div),
    body.chat-page .chat-message .bubble .message-content :where(h3, h4) + :where(p, ul, ol, blockquote, div),
    body:has(.chat-layout) .chat-message .bubble .text-container .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .message-content .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h3, h4) + :where(p, ul, ol, blockquote, div),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h3, h4) + :where(p, ul, ol, blockquote, div) {
        margin-left: 12px !important;
        max-width: calc(100% - 12px) !important;
        padding-left: 0 !important;
        border-left: 0 !important;
        box-sizing: border-box !important;
    }

    body:has(.usage-page-head) .usage-history-open-btn {
        display: none !important;
    }

    body:has(.usage-page-head) .usage-workspace-actions {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    /* EOF usage date display pass: show our text value, use native date input only as tap target. */
    .usage-page-head .usage-date-filter {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) 12px minmax(0, 1fr) 42px !important;
        align-items: end !important;
        gap: 8px !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 8px !important;
        border-radius: 10px !important;
        background: #f8faf6 !important;
        border: 1px solid var(--friendly-line-strong, #b9c7bd) !important;
    }

    .usage-page-head .usage-date-filter > i {
        display: none !important;
    }

    .usage-page-head .usage-date-field {
        position: relative !important;
        min-width: 0 !important;
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 4px !important;
        min-height: 52px !important;
        padding: 7px 8px !important;
        border: 1px solid var(--friendly-line-strong, #b9c7bd) !important;
        border-radius: 8px !important;
        background: #ffffff !important;
        box-sizing: border-box !important;
    }

    .usage-page-head .usage-date-label {
        display: block !important;
        color: var(--friendly-accent-hover, #0f766e) !important;
        font-size: 0.7rem !important;
        font-weight: 900 !important;
        line-height: 1 !important;
    }

    .usage-page-head .usage-date-field > span:not(.usage-date-label):not(.usage-date-value) {
        display: none !important;
    }

    .usage-page-head .usage-date-value {
        display: block !important;
        color: var(--friendly-text, #1f2933) !important;
        -webkit-text-fill-color: var(--friendly-text, #1f2933) !important;
        font-size: clamp(0.74rem, 3.15vw, 0.86rem) !important;
        font-weight: 850 !important;
        line-height: 1.1 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: clip !important;
    }

    .usage-page-head .usage-date-filter input[type="date"] {
        position: absolute !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        min-height: 100% !important;
        padding: 0 !important;
        border: 0 !important;
        background: transparent !important;
        color: transparent !important;
        -webkit-text-fill-color: transparent !important;
        opacity: 0.01 !important;
        appearance: auto !important;
        -webkit-appearance: auto !important;
        color-scheme: light !important;
        cursor: pointer !important;
    }

    .usage-page-head .usage-date-separator {
        align-self: center !important;
        color: var(--friendly-muted, #6b7280) !important;
        font-size: 1rem !important;
        font-weight: 800 !important;
        text-align: center !important;
    }

    .usage-page-head .usage-date-filter .icon-btn {
        position: static !important;
        width: 42px !important;
        min-width: 42px !important;
        height: 52px !important;
        align-self: end !important;
        justify-self: end !important;
        border-radius: 8px !important;
    }
}

@media (max-width: 768px) {
    /* Final mobile cleanup: one visible date control per field, no duplicated helper value. */
    .usage-page-head .usage-date-field {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 6px !important;
        min-height: 0 !important;
        padding: 8px !important;
        align-items: stretch !important;
    }

    .usage-page-head .usage-date-label,
    .usage-page-head .usage-date-value {
        display: none !important;
    }

    .usage-page-head .usage-date-field > span:not(.usage-date-label):not(.usage-date-value) {
        display: none !important;
        color: var(--friendly-accent-hover, #0f766e) !important;
        font-size: 0.72rem !important;
        font-weight: 900 !important;
        line-height: 1 !important;
    }

    .usage-page-head .usage-date-filter input[type="date"] {
        position: static !important;
        inset: auto !important;
        display: block !important;
        width: 100% !important;
        height: 34px !important;
        min-height: 34px !important;
        padding: 0 4px !important;
        border: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
        color: var(--friendly-text, #1f2933) !important;
        -webkit-text-fill-color: var(--friendly-text, #1f2933) !important;
        opacity: 1 !important;
        font-size: clamp(0.78rem, 3.3vw, 0.92rem) !important;
        font-weight: 850 !important;
        line-height: 34px !important;
        color-scheme: light !important;
    }

    body.chat-page .chat-message .bubble .text-container .markdown-section-body,
    body.chat-page .chat-message .bubble .message-content .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .text-container .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .message-content .markdown-section-body {
        margin-left: 0 !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        border-left: 0 !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(ul, ol),
    body.chat-page .chat-message .bubble .message-content :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(ul, ol) {
        margin: 0.55rem 0 0.9rem !important;
        padding-left: 1.15rem !important;
    }

    body.chat-page .chat-message .bubble .text-container li > :where(ul, ol),
    body.chat-page .chat-message .bubble .message-content li > :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .text-container li > :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .message-content li > :where(ul, ol) {
        margin-top: 0.35rem !important;
        padding-left: 1rem !important;
    }
}

@media (max-width: 768px) {
    /* Restore comfortable mobile answer gutters after the empty-list cleanup. */
    body.chat-page .chat-message.ai .bubble,
    body:has(.chat-layout) .chat-message.ai .bubble {
        padding-left: 18px !important;
        padding-right: 18px !important;
        overflow-x: hidden !important;
    }

    body.chat-page .chat-message .bubble .text-container,
    body.chat-page .chat-message .bubble .message-content,
    body:has(.chat-layout) .chat-message .bubble .text-container,
    body:has(.chat-layout) .chat-message .bubble .message-content {
        max-width: 100% !important;
        overflow-wrap: anywhere !important;
    }

    body.chat-page .chat-message .bubble .text-container .markdown-section-body,
    body.chat-page .chat-message .bubble .message-content .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .text-container .markdown-section-body,
    body:has(.chat-layout) .chat-message .bubble .message-content .markdown-section-body {
        margin-left: 0.35rem !important;
        max-width: calc(100% - 0.35rem) !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(ul, ol),
    body.chat-page .chat-message .bubble .message-content :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(ul, ol),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(ul, ol) {
        margin-left: 0.45rem !important;
        padding-left: 1.35rem !important;
        list-style-position: outside !important;
        max-width: calc(100% - 0.45rem) !important;
        box-sizing: border-box !important;
    }

    body.chat-page .chat-message .bubble .text-container li,
    body.chat-page .chat-message .bubble .message-content li,
    body:has(.chat-layout) .chat-message .bubble .text-container li,
    body:has(.chat-layout) .chat-message .bubble .message-content li {
        padding-left: 0.08rem !important;
    }
}

@media (max-width: 768px) {
    /* User comfort pass: keep the mobile site readable and easy to type into. */
    :root {
        --mobile-page-x: 14px;
    }

    body.chat-page .chat-window,
    body:has(.chat-layout) .chat-window {
        padding-left: 14px !important;
        padding-right: 14px !important;
        padding-bottom: 112px !important;
        scroll-padding-bottom: 116px !important;
    }

    body.chat-page .chat-message,
    body:has(.chat-layout) .chat-message {
        max-width: 100% !important;
    }

    body.chat-page .chat-message.ai .bubble,
    body:has(.chat-layout) .chat-message.ai .bubble {
        border-radius: 10px !important;
        border-left: 6px solid var(--friendly-accent) !important;
        padding: 16px 16px 16px 26px !important;
    }

    body.chat-page .chat-message.user .bubble,
    body:has(.chat-layout) .chat-message.user .bubble {
        border-radius: 10px !important;
        border-right: 6px solid #2563eb !important;
        padding: 14px 22px 14px 16px !important;
    }

    body.chat-page .chat-message .bubble .text-container,
    body.chat-page .chat-message .bubble .message-content,
    body:has(.chat-layout) .chat-message .bubble .text-container,
    body:has(.chat-layout) .chat-message .bubble .message-content {
        overflow-wrap: anywhere !important;
        word-break: keep-all !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(p, li),
    body.chat-page .chat-message .bubble .message-content :where(p, li),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(p, li),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(p, li) {
        line-height: 1.74 !important;
    }

    body.chat-page .chat-message .bubble .text-container :where(h1, h2, h3, h4),
    body.chat-page .chat-message .bubble .message-content :where(h1, h2, h3, h4),
    body:has(.chat-layout) .chat-message .bubble .text-container :where(h1, h2, h3, h4),
    body:has(.chat-layout) .chat-message .bubble .message-content :where(h1, h2, h3, h4) {
        margin-left: 0 !important;
        max-width: 100% !important;
        padding-left: 0 !important;
    }

    body.chat-page .chat-input-wrapper,
    body:has(.chat-layout) .chat-input-wrapper {
        grid-template-columns: 44px minmax(0, 1fr) 52px !important;
        gap: 8px !important;
        padding: 9px 12px calc(10px + env(safe-area-inset-bottom)) !important;
        align-items: center !important;
        background: rgba(252, 250, 244, 0.98) !important;
    }

    body.chat-page .mode-selector-btn,
    body:has(.chat-layout) .mode-selector-btn {
        width: 44px !important;
        min-width: 44px !important;
        height: 54px !important;
        min-height: 54px !important;
    }

    body.chat-page #chat-input,
    body:has(.chat-layout) #chat-input {
        height: 54px !important;
        min-height: 54px !important;
        max-height: 112px !important;
        padding: 12px 13px !important;
        line-height: 1.35 !important;
        overflow-y: auto !important;
    }

    body.chat-page #chat-input::placeholder,
    body:has(.chat-layout) #chat-input::placeholder {
        font-size: 0.9rem !important;
        line-height: 1.35 !important;
    }

    body.chat-page #chat-send-btn,
    body:has(.chat-layout) #chat-send-btn {
        width: 52px !important;
        min-width: 52px !important;
        height: 54px !important;
        min-height: 54px !important;
    }

    .mobile-bottom-nav {
        height: calc(64px + env(safe-area-inset-bottom)) !important;
        padding-top: 6px !important;
    }

    .mobile-bottom-nav a {
        height: 50px !important;
        border-radius: 10px !important;
    }
}

@media (max-width: 768px) {
    /* History action menu lives outside cards so the list height never jumps. */
    .app-history-menu .app-history-item-actions,
    .app-history-menu.open .app-history-item-actions {
        display: none !important;
    }

    .app-history-floating-menu {
        position: fixed !important;
        z-index: 10030 !important;
        display: none !important;
        min-width: 148px !important;
        padding: 7px !important;
        border-radius: 12px !important;
        background: #ffffff !important;
        border: 1px solid var(--friendly-line-strong, #b9c7bd) !important;
        box-shadow: 0 16px 34px rgba(23, 32, 25, 0.22) !important;
    }

    .app-history-floating-menu.open {
        display: grid !important;
        gap: 4px !important;
    }

    .app-history-floating-menu .app-history-menu-item {
        min-height: 42px !important;
        padding: 0 12px !important;
        border-radius: 9px !important;
        color: var(--friendly-text, #1f2933) !important;
        font-size: 0.86rem !important;
        background: transparent !important;
    }

    .app-history-floating-menu .app-history-menu-item.primary {
        color: var(--friendly-accent-hover, #0f766e) !important;
    }

    .app-history-floating-menu .app-history-menu-item.danger {
        color: #b42318 !important;
    }
}

@media (max-width: 991px) {
    /* Mobile viewport sync pass: keep header, page body, chat input, and bottom nav on one shared height contract. */
    :root {
        --mobile-header-height: 56px;
        --mobile-bottom-nav-height: 64px;
        --mobile-chat-input-height: 74px;
        --mobile-chat-status-height: 48px;
        --mobile-page-x: 14px;
        --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
        --mobile-content-height: calc(100dvh - var(--mobile-header-height) - var(--mobile-bottom-nav-height) - var(--mobile-safe-bottom));
    }

    html:has(body.chat-page),
    body.chat-page {
        width: 100% !important;
        min-height: 100dvh !important;
        overflow-x: hidden !important;
    }



    body.chat-page {
        height: 100dvh !important;
        min-height: 100dvh !important;
        width: 100% !important;
        position: fixed !important;
        inset: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        overflow: hidden !important;
        overscroll-behavior: none !important;
    }

    body.chat-page .chat-layout {
        position: fixed !important;
        top: var(--mobile-header-height) !important;
        right: 0 !important;
        bottom: calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom)) !important;
        left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: none !important;
        min-height: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        border: 0 !important;
        border-radius: 0 !important;
        overflow: hidden !important;
        box-shadow: none !important;
    }

    body.chat-page .chat-header {
        flex: 0 0 auto !important;
        padding: 10px 12px !important;
        gap: 7px !important;
    }

    body.chat-page .chat-header h2 {
        margin: 0 !important;
        font-size: clamp(0.98rem, 4vw, 1.08rem) !important;
        line-height: 1.2 !important;
    }

    body.chat-page .chat-header p,
    body.chat-page .user-guide-strip {
        display: none !important;
    }

    body.chat-page .status-indicator {
        min-height: 30px !important;
        padding: 5px 10px !important;
        font-size: 0.8rem !important;
    }

    body.chat-page .chat-window {
        flex: 1 1 0% !important;
        min-height: 0 !important;
        width: 100% !important;
        padding: 12px 12px calc(var(--mobile-chat-input-height) + 16px) !important;
        gap: 12px !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: contain !important;
        scroll-padding: 12px !important;
        scroll-padding-bottom: calc(var(--mobile-chat-input-height) + 18px) !important;
        scroll-behavior: auto !important;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch !important;
    }

    body.chat-page:has(.loading-overlay:not(.hidden)) .chat-window {
        padding-bottom: calc(var(--mobile-chat-input-height) + var(--mobile-chat-status-height) + 20px) !important;
        scroll-padding-bottom: calc(var(--mobile-chat-input-height) + var(--mobile-chat-status-height) + 22px) !important;
    }

    body.chat-page .loading-overlay:not(.hidden) {
        position: fixed !important;
        right: 0 !important;
        bottom: calc(var(--mobile-bottom-nav-height) + var(--mobile-chat-input-height) + var(--mobile-safe-bottom)) !important;
        left: 0 !important;
        z-index: 10009 !important;
        min-height: var(--mobile-chat-status-height) !important;
        padding: 8px 14px !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        gap: 9px !important;
        background: rgba(252, 250, 244, 0.98) !important;
        border-top: 1px solid var(--friendly-line, #c2cec1) !important;
        box-shadow: 0 -6px 16px rgba(23, 32, 25, 0.08) !important;
    }

    body.chat-page .loading-overlay:not(.hidden) .loading-text {
        max-width: min(78vw, 520px) !important;
        color: var(--friendly-accent, #185f4b) !important;
        font-size: 0.78rem !important;
        line-height: 1.35 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    body.chat-page .loading-overlay:not(.hidden) .dots-wrapper {
        flex: 0 0 auto !important;
    }

    body.chat-page .chat-input-wrapper {
        flex: 0 0 auto !important;
        display: grid !important;
        grid-template-columns: 44px minmax(0, 1fr) 52px !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100vw !important;
        max-width: 100% !important;
        height: var(--mobile-chat-input-height) !important;
        min-height: var(--mobile-chat-input-height) !important;
        max-height: var(--mobile-chat-input-height) !important;
        padding: 9px 12px 9px !important;
        position: fixed !important;
        right: 0 !important;
        bottom: calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom)) !important;
        left: 0 !important;
        z-index: 10010 !important;
        background: rgba(252, 250, 244, 0.99) !important;
        border-top: 1px solid var(--friendly-line, #c2cec1) !important;
        box-shadow: 0 -8px 18px rgba(23, 32, 25, 0.08) !important;
    }

    body.chat-page .mode-selector-wrapper {
        width: 44px !important;
        max-width: 44px !important;
    }

    body.chat-page .mode-selector-btn,
    body.chat-page #chat-send-btn {
        width: 44px !important;
        min-width: 44px !important;
        height: 52px !important;
        min-height: 52px !important;
        border-radius: 9px !important;
    }

    body.chat-page #chat-send-btn {
        width: 52px !important;
        min-width: 52px !important;
    }

    body.chat-page #chat-input {
        width: 100% !important;
        min-width: 0 !important;
        height: 52px !important;
        min-height: 52px !important;
        max-height: 104px !important;
        padding: 11px 12px !important;
        font-size: 16px !important;
        line-height: 1.35 !important;
        overflow-y: auto !important;
    }

    body.chat-page .mode-dropdown {
        bottom: calc(100% + 8px) !important;
        left: 0 !important;
        max-width: calc(100vw - 24px) !important;
        max-height: min(48dvh, 360px) !important;
        overflow-y: auto !important;
    }

}

@media (max-width: 991px) {


    body.chat-page .chat-layout {
        top: var(--mobile-header-height) !important;
        bottom: calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom)) !important;
    }

    body.chat-page .chat-header {
        padding: 7px 10px !important;
        gap: 0 !important;
    }

    body.chat-page .chat-header h2 {
        font-size: 0.96rem !important;
        line-height: 1.15 !important;
    }

    body.chat-page .status-indicator {
        display: none !important;
    }

    body.chat-page .chat-window {
        padding: 10px 10px calc(var(--mobile-chat-input-height) + 10px) !important;
        gap: 10px !important;
        scroll-padding-bottom: calc(var(--mobile-chat-input-height) + 12px) !important;
    }

    body.chat-page .chat-input-wrapper {
        grid-template-columns: 40px minmax(0, 1fr) 46px !important;
        height: var(--mobile-chat-input-height) !important;
        min-height: var(--mobile-chat-input-height) !important;
        max-height: var(--mobile-chat-input-height) !important;
        padding: 7px 10px !important;
        gap: 7px !important;
        bottom: calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom)) !important;
    }

    body.chat-page .mode-selector-wrapper {
        width: 40px !important;
        max-width: 40px !important;
    }

    body.chat-page .mode-selector-btn,
    body.chat-page #chat-send-btn {
        height: 46px !important;
        min-height: 46px !important;
        border-radius: 8px !important;
    }

    body.chat-page .mode-selector-btn {
        width: 40px !important;
        min-width: 40px !important;
    }

    body.chat-page #chat-send-btn {
        width: 46px !important;
        min-width: 46px !important;
    }

    body.chat-page #chat-input {
        height: 46px !important;
        min-height: 46px !important;
        max-height: 92px !important;
        padding: 4px 11px 5px !important;
        font-size: 16px !important;
        line-height: 1.15 !important;
    }

    body.chat-page .chat-input-wrapper:focus-within {
        height: 122px !important;
        min-height: 122px !important;
        max-height: 122px !important;
        padding-top: 8px !important;
        padding-bottom: 8px !important;
    }

    body.chat-page .chat-input-wrapper:focus-within #chat-input {
        height: 106px !important;
        min-height: 106px !important;
        max-height: 106px !important;
        padding: 7px 11px !important;
        line-height: 1.25 !important;
    }

    body.chat-page:has(.chat-input-wrapper:focus-within) .chat-window {
        padding-bottom: 132px !important;
        scroll-padding-bottom: 134px !important;
    }

    body.chat-page .mobile-bottom-nav {
        height: calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom)) !important;
        padding: 4px 7px calc(5px + var(--mobile-safe-bottom)) !important;
    }

    body.chat-page .mobile-bottom-nav a {
        height: 45px !important;
        gap: 3px !important;
        border-radius: 9px !important;
        font-size: 0.6rem !important;
    }

    body.chat-page .mobile-bottom-nav a i {
        font-size: 0.94rem !important;
    }
}
