/* Mobile presentation only. Keep desktop >=1024px and print rules untouched.
   Reuse the existing palette so light/dark themes and branding stay consistent. */
@media screen and (max-width: 768px) {
    .app-shell,
    .login-screen {
        --mobile-gap: 16px;
        --mobile-radius: 16px;
        font-size: 15px;
        line-height: 1.5;
    }

    .app-shell .page-shell {
        padding: 16px 12px 32px !important;
        display: grid;
        /* An auto track inherits a wide document table's min-content width. */
        grid-template-columns: minmax(0, 1fr);
        gap: var(--mobile-gap);
    }

    .app-shell .page-shell > * {
        min-width: 0;
        max-width: 100%;
    }

    /* Topbar mobile layout is defined in design-system.css. */

    .page-shell .hero,
    .page-shell .panel,
    .page-shell .invoice-erp-card,
    .page-shell .payment-card {
        padding: 16px;
        border-radius: var(--mobile-radius);
        background: var(--panel);
        border: 1px solid var(--border);
        box-shadow: 0 2px 8px var(--primary-soft);
        min-width: 0;
    }

    .page-shell .hero {
        gap: 16px;
        margin: 0;
    }

    .page-shell .section-title {
        font-size: 24px;
        line-height: 1.25;
        margin-block: 8px;
    }

    .page-shell .section-copy,
    .page-shell .panel__header p {
        font-size: 14px;
        line-height: 1.6;
        margin-block: 4px 0;
    }

    .page-shell .panel__header {
        margin-bottom: 16px;
        gap: 12px;
    }

    .page-shell .panel__header h3,
    .page-shell .invoice-section-heading h3,
    .page-shell .invoice-lines-header h3 {
        font-size: 18px;
        line-height: 1.35;
        margin-block: 0 4px;
    }

    .page-shell .layout-grid,
    .page-shell .document-form,
    .page-shell .module-grid {
        gap: var(--mobile-gap);
    }

    .page-shell .module-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .page-shell .module-card {
        flex-direction: row;
        align-items: flex-start;
        gap: 12px;
        height: auto;
        padding: 14px;
        border-radius: 14px;
        background: var(--panel-alt);
    }

    .page-shell .module-card__badge {
        flex: 0 0 48px;
        min-width: 48px;
        width: 48px;
        height: 48px;
        padding: 0 4px;
        font-size: 12px;
        border-radius: 12px;
        letter-spacing: 0;
    }

    .page-shell .module-card h4 {
        font-size: 16px;
        line-height: 1.4;
        margin: 0;
    }

    .page-shell .module-card p {
        font-size: 14px;
        line-height: 1.5;
    }

    .page-shell .module-card > div,
    .page-shell .snapshot-item,
    .page-shell .metric-card,
    .page-shell .users-kpi-card {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .page-shell a.module-card:focus-visible,
    .page-shell .button:focus-visible {
        outline: 2px solid var(--primary);
        outline-offset: 3px;
    }

    .page-shell .metric-card,
    .page-shell .users-kpi-card {
        padding: 14px 16px;
        border-radius: 14px;
        background: var(--panel);
    }

    .page-shell .metric-card__value,
    .page-shell .users-kpi-card__value {
        font-size: 26px;
        line-height: 1.3;
        margin: 4px 0;
    }

    .page-shell .metric-card__caption {
        font-size: 13px;
        margin: 4px 0 0;
    }

    .page-shell .form-grid,
    .page-shell .invoice-form-grid,
    .page-shell .invoice-address-grid,
    .page-shell .payment-document-grid,
    .page-shell .payment-header-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
    }

    .page-shell .form-field,
    .login-screen .form-field {
        gap: 7px;
        font-size: 14px;
        line-height: 1.5;
    }

    .page-shell .form-field input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    .page-shell .form-field select,
    .page-shell .form-field textarea,
    .page-shell .form-control,
    .page-shell .invoice-document-form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    .page-shell .invoice-document-form select,
    .page-shell .financial-document-form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    .page-shell .financial-document-form select,
    .login-screen .form-field input {
        min-height: 46px;
        padding: 11px 12px;
        font-size: 16px;
        border-radius: 10px;
        max-width: 100%;
        box-sizing: border-box;
    }

    .page-shell .form-field > span,
    .page-shell .form-field > label {
        font-size: 14px;
        font-weight: 600;
    }

    .page-shell .form-field__help,
    .page-shell .form-field__error {
        font-size: 13px;
        line-height: 1.5;
    }

    .page-shell .button,
    .page-shell .btn-erp {
        min-height: 44px;
        padding: 10px 14px;
        font-size: 14px;
        line-height: 1.4;
        border-radius: 10px;
        white-space: normal;
    }

    .page-shell .invoice-section-heading,
    .page-shell .invoice-lines-header {
        flex-direction: column;
        gap: 12px;
        padding-bottom: 12px;
    }

    .page-shell .invoice-document-card,
    .page-shell .invoice-party-card,
    .page-shell .invoice-lines-card {
        gap: 16px;
    }

    .page-shell .invoice-lines-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .page-shell .invoice-lines-actions .button {
        flex: 1 1 120px;
    }

    .page-shell .invoice-party-grid,
    .page-shell .partner-snapshot__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .page-shell .snapshot-item {
        padding: 12px;
        border-radius: 10px;
    }

    .page-shell .snapshot-item strong,
    .page-shell .snapshot-item--important strong {
        font-size: 16px;
        line-height: 1.5;
    }

    .page-shell .invoice-metrics-strip,
    .page-shell .tracking-modal__summary {
        gap: 10px;
    }

    .page-shell .invoice-metric {
        padding: 12px 14px;
        border-radius: 12px;
    }

    .page-shell .invoice-metric span {
        font-size: 12px;
        letter-spacing: 0;
    }

    .page-shell .invoice-metric strong {
        font-size: 20px;
        line-height: 1.4;
    }

    .page-shell .invoice-metric--total {
        border-inline-start: 3px solid var(--primary);
        background: var(--primary-soft);
    }

    .page-shell .invoice-submit-bar,
    .page-shell .payment-actions {
        gap: 12px;
        padding: 14px;
        flex-wrap: wrap;
    }

    .page-shell .banking-filter-bar__inputs,
    .page-shell .banking-filter-bar__actions,
    .page-shell .report-filter-bar__inputs,
    .page-shell .report-filter-bar__actions {
        width: 100%;
        gap: 12px;
    }

    .page-shell .banking-filter-bar .form-field,
    .page-shell .report-filter-bar .form-field {
        flex: 1 1 100%;
    }

    .page-shell .report-filter-bar button,
    .page-shell .banking-filter-bar button {
        min-height: 44px;
        height: auto !important; /* Legacy 42px height clips wrapped treasury actions. */
        padding-block: 10px;
    }

    .page-shell .banking-filter-bar__actions,
    .page-shell .report-filter-bar__actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: stretch;
    }

    .page-shell .banking-filter-bar__actions > *,
    .page-shell .report-filter-bar__actions > * {
        min-width: 0;
        width: 100%;
        overflow-wrap: anywhere;
    }

    .page-shell .table-wrap,
    .page-shell .table-wrapper,
    .page-shell .invoice-lines-scroll {
        border-radius: 12px;
        scrollbar-width: thin;
        scrollbar-color: var(--primary) var(--panel-alt);
        border-block-end: 3px solid var(--primary-soft);
    }

    /* Document grids keep their column widths; only their controls grow. */
    .page-shell .invoice-line-input,
    .page-shell .journal-line-input,
    .page-shell .grpo-lines-table .line-input {
        min-height: 44px;
        height: auto;
        font-size: 16px;
    }

    .page-shell .status-pill,
    .page-shell .badge-status {
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
        line-height: 1.5;
    }

    .page-shell .config-list__row {
        flex-wrap: wrap;
        gap: 8px;
        overflow-wrap: anywhere;
    }

    .page-shell .crm-toolbar__date {
        flex-wrap: wrap;
        min-width: 0;
        max-width: 100%;
    }

    .page-shell .crm-toolbar__date > input {
        flex: 1 1 140px;
        min-width: 0;
        max-width: 100%;
    }

    .page-shell .crm-sales-quotation .sq-label {
        font-size: 14px;
        font-weight: 600;
        color: var(--text);
    }

    .page-shell .crm-sales-quotation .sq-input,
    .page-shell .crm-sales-quotation .sq-select {
        min-height: 46px;
        font-size: 16px;
        color: var(--text);
        background: var(--panel);
        border-color: var(--border);
    }

    .page-shell .crm-sales-quotation .sq-input[readonly] {
        background: var(--panel-alt);
    }

    /* Keep the existing pipeline move menu clear of scrolling column clips. */
    .page-shell .card-move-menu,
    .page-shell .card-move-menu.is-upwards {
        position: fixed;
        top: auto;
        bottom: 16px;
        inset-inline: 16px;
        width: auto;
        min-width: 0;
        max-width: calc(100vw - 32px);
        max-height: min(420px, calc(100dvh - 80px));
        background: var(--panel);
        color: var(--text);
    }

    .page-shell .card-move-menu [role="menuitem"] {
        min-height: 44px;
        white-space: normal;
    }

    /* CRM owns separate styles; match its controls to the mobile touch scale. */
    .page-shell .crm-dashboard .crm-dashboard__hero-title {
        font-size: 24px;
        font-weight: 700;
        line-height: 1.25;
        overflow-wrap: anywhere;
    }

    .page-shell .crm-dashboard .crm-dashboard__filter-pill,
    .page-shell .crm-dashboard .crm-dashboard__action-btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
    }

    .page-shell .crm-dashboard .crm-dashboard__module-card {
        min-height: 0;
        padding: 16px;
        border-radius: var(--mobile-radius);
    }

    .page-shell .crm-dashboard .crm-dashboard__container {
        padding-inline: 0;
    }

    .page-shell .erp-record-card {
        /* Bridge legacy card tokens to the existing light/dark palette. */
        --surface: var(--panel);
        --surface-subtle: var(--panel-alt);
        --border-color: var(--border);
        --text-color: var(--text);
        --text-muted: var(--muted);
        padding: 14px;
        gap: 10px;
        border-radius: 14px;
    }

    .page-shell .erp-record-card__meta-label,
    .page-shell .erp-record-card__subtitle,
    .page-shell .erp-record-card__entity-code {
        font-size: 13px;
    }

    .page-shell .erp-record-card__meta-val {
        white-space: normal;
        overflow: visible;
        overflow-wrap: anywhere;
        font-size: 14px;
    }

    .page-shell .invoice-summary,
    .page-shell .form-alert,
    .page-shell .message {
        font-size: 14px;
        line-height: 1.6;
        padding: 12px 14px;
        overflow-wrap: anywhere;
    }

    .tracking-modal__panel,
    .users-modal__panel,
    .statement-modal__panel {
        border-radius: 16px;
    }

    .tracking-modal__panel .form-field,
    .users-modal__panel .form-field {
        min-width: 0;
        gap: 7px;
        font-size: 14px;
        overflow-wrap: anywhere;
    }

    .tracking-modal__panel .form-field input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
    .tracking-modal__panel .form-field select,
    .users-modal__panel .form-field input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
    .users-modal__panel .form-field select {
        min-height: 44px;
        max-width: 100%;
        min-width: 0;
        font-size: 16px;
    }

    .tracking-modal__panel .button,
    .users-modal__panel .button {
        min-height: 44px;
        white-space: normal;
    }

    .login-screen {
        padding: 16px 12px 28px;
        align-items: flex-start;
        background: var(--bg);
    }

    .login-screen .login-shell {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
        max-width: 480px;
    }

    .login-screen .login-copy,
    .login-screen .login-card {
        padding: 20px;
        border-radius: 20px;
    }

    .login-screen .login-copy__topbar {
        flex-direction: row;
        align-items: center;
    }

    .login-screen .login-copy__brand {
        min-height: 0;
    }

    .login-screen .login-copy__brand-image {
        width: min(100%, 220px);
        max-height: 120px;
    }

    .login-screen .login-card__header {
        flex-wrap: wrap;
        gap: 16px;
        margin-bottom: 20px;
    }

    .login-screen .login-card__header h2 {
        font-size: 24px;
        margin-block: 0 6px;
    }

    .login-screen .login-form {
        gap: 18px;
    }

    .login-screen .button {
        min-height: 46px;
        font-size: 15px;
        border-radius: 10px;
    }
}

@media screen and (max-width: 480px) {
    .page-shell .users-header {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .page-shell .users-header__actions {
        width: 100%;
    }

    .page-shell .users-header__actions > .button,
    .page-shell .users-header__actions > form {
        flex: 1 1 140px;
    }

    .page-shell .users-header__actions > form > .button {
        width: 100%;
    }

    .page-shell .hero__actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
    }

    .page-shell .form-section {
        padding: 14px;
    }

    .page-shell .invoice-party-grid .snapshot-item--name {
        grid-column: 1 / -1;
    }
}
