/* Phone/tablet workspace refinements. Desktop layout remains in its existing styles. */
.workspace-mobile-topbar,
.logistics-mobile-readonly-value { display: none; }

@media (max-width: 900px) {
    body.workspace-shell-active { --dashboard-mobile-top-offset: calc(56px + env(safe-area-inset-top, 0px)); }
    body.workspace-shell-active .workspace-mobile-topbar {
        display: flex; align-items: center; justify-content: space-between; gap: 12px;
        position: fixed; inset: 0 0 auto; z-index: 950;
        box-sizing: border-box; height: calc(56px + env(safe-area-inset-top, 0px));
        padding: env(safe-area-inset-top, 0px) 16px 0;
        background: #fafaf9; border-bottom: 1px solid #d6d8d4;
    }
    .workspace-mobile-brand { display: flex; align-items: center; min-height: 44px; }
    .workspace-mobile-brand img { width: 100px; height: 38px; object-fit: contain; }
    #workspace-mobile-menu-btn {
        display: inline-flex; align-items: center; justify-content: center; gap: 8px;
        min-height: 44px; padding: 0 12px; font-size: 14px;
        border: 1px solid #d6d8d4; border-radius: 6px; background: #fff; color: #242624;
    }
    #workspace-mobile-menu-btn.mobile-sidebar-open { background: #e0f0e2; border-color: #b6d9bd; }
    body.workspace-shell-active .main-header { display: none !important; }
    body.workspace-shell-active .app-container > #main-content {
        padding-top: var(--dashboard-mobile-top-offset); box-sizing: border-box;
        min-height: 100dvh; height: auto; overflow: visible;
    }
    body.workspace-shell-active #dashboard-sidebar.dashboard-topbar {
        position: fixed; top: var(--dashboard-mobile-top-offset); left: 0; bottom: 0;
        width: min(320px, calc(100vw - 32px)); min-width: 0;
        height: calc(100dvh - var(--dashboard-mobile-top-offset));
        padding: 16px 16px max(16px, env(safe-area-inset-bottom, 0px));
        box-sizing: border-box; overflow-y: auto; overscroll-behavior: contain;
        transform: translateX(-108%); z-index: 920;
    }
    body.workspace-shell-active #dashboard-sidebar.mobile-open { transform: translateX(0); }
    #dashboard-sidebar .workspace-sidebar-shell { min-height: 100%; height: auto; gap: 20px; }
    body.workspace-shell-active #dashboard-sidebar.dashboard-topbar .workspace-sidebar-scroll {
        flex: none; height: auto; max-height: none; overflow: visible; padding: 0;
    }
    #dashboard-sidebar .workspace-sidebar-brand { display: none; }
    #dashboard-sidebar .sidebar-header { display: none; }
    body.workspace-shell-active #dashboard-sidebar :is(.sidebar-nav, .workflow-steps-group, .sidebar-content, .sidebar-footer, .sidebar-group) {
        width: 100%; min-width: 0; box-sizing: border-box; align-items: stretch; padding: 0;
    }
    body.workspace-shell-active #dashboard-sidebar :is(.sidebar-btn-label, .dashboard-topbar-icon-label) { display: inline !important; }
    body.workspace-shell-active #dashboard-sidebar .dashboard-topbar-icon-label {
        position: static !important; width: auto !important; height: auto !important;
        margin: 0 !important; overflow: visible !important; clip: auto !important; white-space: normal !important;
    }
    body.workspace-shell-active #dashboard-sidebar .sidebar-btn {
        width: 100% !important; padding: 12px !important; height: auto; text-align: left;
    }
    body.workspace-shell-active #dashboard-sidebar.dashboard-topbar .sidebar-footer :is(.sidebar-utility-btn, .sidebar-logout-btn, .workspace-sidebar-language, .workspace-sidebar-user-card) {
        border: 0 !important; border-radius: 6px !important; box-shadow: none !important; background: transparent !important;
    }
    body.workspace-shell-active #dashboard-sidebar.dashboard-topbar .sidebar-footer :is(.sidebar-utility-btn, .sidebar-logout-btn) {
        width: 100% !important; min-height: 44px !important; padding: 8px 12px !important; justify-content: flex-start;
    }
    #dashboard-sidebar .sidebar-utility-btn--icon-only::after { content: attr(title); font-size: 14px; }
    body.workspace-shell-active #dashboard-sidebar .sidebar-footer { border-top: 1px solid #d6d8d4; padding-top: 16px; }
    #dashboard-sidebar :is(.sidebar-nav, .workflow-steps-group) { display: flex; flex-direction: column; gap: 4px; }
    #dashboard-sidebar .sidebar-btn {
        display: flex; width: 100%; min-height: 48px; margin: 0; padding: 12px;
        text-align: left; justify-content: flex-start; font-size: 15px;
    }
    #dashboard-sidebar .sidebar-step-index { display: none; }
    #dashboard-sidebar .sidebar-footer { display: flex; flex: none; flex-direction: column; gap: 8px; margin-top: auto; }
    #dashboard-sidebar .sidebar-group { display: flex; flex-wrap: wrap; gap: 8px; }
    #dashboard-sidebar :is(.sidebar-utility-btn, .sidebar-logout-btn) { min-height: 44px; padding: 10px 12px; }
    #dashboard-sidebar .workspace-sidebar-language { width: 100%; }
    #dashboard-sidebar .workspace-sidebar-language-switch .lang-btn { min-width: 44px; min-height: 44px; }
    #dashboard-sidebar .workspace-topbar-divider { display: none; }
    .dashboard-mobile-backdrop { display: none; inset: var(--dashboard-mobile-top-offset) 0 0; }
    .dashboard-mobile-backdrop.active { display: block; }
    body.dashboard-mobile-sidebar-open { overflow: hidden; }
    body.workspace-shell-active #dashboard-view.active {
        height: auto; min-height: calc(100dvh - var(--dashboard-mobile-top-offset)); overflow: visible;
    }
    body.workspace-shell-active #dashboard-view > .dashboard-main-panel {
        height: auto; min-height: 0; overflow: visible; padding: 16px;
    }
    body.workspace-shell-active .site-footer { display: none; }
    :is(#workspace-mobile-topbar, #dashboard-sidebar, .logistics-detail-shell, .logistics-board-shell) button:focus-visible {
        outline: 2px solid #557660; outline-offset: 2px;
    }

    /* Keep password/SMS options and the submit action together on a phone. */
    #auth-modal { padding: 12px; box-sizing: border-box; }
    #auth-modal .auth-modal-shell {
        width: 100%; max-width: 480px; max-height: calc(100dvh - 24px);
        margin: auto; overflow-y: auto; border-radius: 10px; display: block;
    }
    #auth-modal .auth-brand-panel { display: none; }
    #auth-modal .auth-form-panel { min-width: 0; max-height: none; height: auto; padding: 20px; overflow: visible; }
    #auth-modal .modal-header { margin-bottom: 16px; }
    #auth-modal :is(.auth-tabs, .auth-method-switch) {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; margin-bottom: 12px;
    }
    #auth-modal .hidden { display: none !important; }
    #auth-modal :is(.tab-btn, .auth-method-btn, .password-identifier-btn) {
        min-height: 44px; padding: 8px; font-size: 13px; white-space: normal;
    }
    #auth-modal .form-group { margin-bottom: 16px; }
    #auth-modal :is(input, select) { min-height: 44px; font-size: 16px !important; }
    #auth-modal :is(.close-btn, #forgot-password-open-btn, #auth-submit-btn) { min-height: 44px; }
    #auth-modal .close-btn { min-width: 44px; }

    /* Stack list rows into cards; every cell remains available without sideways scrolling. */
    .logistics-board-shell { gap: 16px; padding: 0; }
    .logistics-board-filters { flex-wrap: wrap; gap: 10px; }
    .logistics-board-search { width: 100%; max-width: none; flex: 1 1 100%; }
    .logistics-board-shell input { font-size: 16px; min-height: 44px; }
    .logistics-table-shell { border: 0; background: transparent; overflow: visible; box-shadow: none; }
    body.workspace-shell-active .logistics-table { display: block; min-width: 0 !important; width: 100%; }
    .logistics-table :is(thead, colgroup) { display: none; }
    .logistics-table tbody { display: grid; gap: 12px; }
    .logistics-table tbody tr {
        display: flex; flex-direction: column; gap: 10px; padding: 16px;
        min-width: 0; width: 100%; box-sizing: border-box;
        border: 1px solid #d6d8d4; border-radius: 8px; background: #fff;
    }
    body.workspace-shell-active .logistics-table tbody td {
        display: block; width: 100%; min-width: 0; min-height: 0 !important; padding: 0 !important; border: 0 !important;
        text-align: left; white-space: normal; box-sizing: border-box;
    }
    .logistics-table .project-cell { order: -1; }
    .logistics-table .qc-primary-line { font-size: 16px; white-space: normal; overflow-wrap: anywhere; }
    .logistics-table .qc-compact-line { align-items: flex-start; gap: 8px; line-height: 1.5; }
    .logistics-table .qc-compact-line span {
        overflow: visible; text-overflow: clip; white-space: normal; overflow-wrap: anywhere;
        font-size: 14px; max-width: 100%;
    }
    .logistics-table .qc-compact-line i { flex-shrink: 0; margin-top: 3px; }
    body.workspace-shell-active .logistics-table :is(.qc-primary-line, .qc-compact-line, .qc-compact-line span, .logistics-waybill-number) {
        white-space: normal !important; overflow: visible !important; text-overflow: clip !important; overflow-wrap: anywhere;
    }
    .logistics-table .qc-status-cell { justify-content: flex-start; }
    .logistics-table .logistics-table-actions { justify-content: flex-end; gap: 8px; }
    body.workspace-shell-active .logistics-table .logistics-table-action {
        min-width: 44px !important; width: 44px; min-height: 44px !important; height: 44px !important; padding: 0 !important;
    }
    .logistics-pagination { flex-wrap: wrap; gap: 12px; }
    .logistics-pagination-actions { flex-wrap: wrap; }

    .logistics-detail-shell { width: 100%; padding: 0; gap: 16px; }
    .logistics-detail-hero { display: flex; flex-direction: column; gap: 16px; padding: 16px; }
    .logistics-detail-hero-main, .logistics-detail-hero-side { width: 100%; min-width: 0; }
    .logistics-detail-hero h2 { font-size: 22px; line-height: 1.25; overflow-wrap: anywhere; }
    .logistics-detail-hero p { font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
    .logistics-detail-hero-side { padding: 0; border: 0; }
    .logistics-detail-hero-toolbar { justify-content: flex-start; flex-wrap: wrap; }
    .logistics-detail-status-row { justify-content: flex-start; }
    .logistics-detail-status-row button { flex: 1 1 140px; white-space: normal; }
    .logistics-detail-shell :is(button, .btn-primary, .btn-outline) { min-height: 44px; }
    .logistics-detail-meta-row { gap: 8px; }
    .logistics-detail-shell .logistics-data-pill { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
    .logistics-shipment-card { display: none; }
    .logistics-audit-card { padding: 16px; }
    .logistics-audit-container { padding: 0; overflow: visible; }
    body.workspace-shell-active .logistics-audit-horizontal { display: flex; flex-direction: column; min-width: 0; padding: 0 !important; gap: 0 !important; }
    .logistics-audit-horizontal::before { display: none; }
    body.workspace-shell-active .logistics-audit-horizontal .audit-trail-item {
        display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 12px;
        flex: none !important; min-width: 0 !important; max-width: none !important; width: 100%; min-height: 54px;
        align-items: start; padding: 0 0 16px !important; text-align: left;
    }
    body.workspace-shell-active .logistics-audit-horizontal .audit-trail-item::before { top: 6px !important; bottom: 0; left: 9px !important; right: auto !important; width: 2px; height: auto !important; }
    .logistics-audit-horizontal .audit-trail-item:last-child::before { display: none; }
    .logistics-audit-horizontal .audit-trail-dot { margin: 4px 0 0; }
    .logistics-audit-horizontal .audit-trail-content { min-width: 0; width: auto; text-align: left; padding: 0; }
    .logistics-audit-horizontal .audit-trail-info-box { min-width: 0; margin-top: 8px; overflow-wrap: anywhere; }
    .logistics-audit-horizontal .audit-trail-item:last-child { padding-bottom: 0; }
    .logistics-detail-work-grid { display: flex; flex-direction: column; gap: 16px; }
    .logistics-detail-work-grid > .logistics-detail-panel { min-width: 0; padding: 16px; }
    .logistics-data-tree-item { width: 100%; min-width: 0; }
    .logistics-data-tree-copy :is(strong, small) { white-space: normal; overflow: visible; overflow-wrap: anywhere; }
    .logistics-evidence-header { flex-direction: column; align-items: stretch; gap: 12px; }
    .logistics-evidence-actions { justify-content: flex-start; }
    body.workspace-shell-active .logistics-evidence-grid {
        grid-template-columns: minmax(0, 1fr) !important; max-height: none !important; overflow: visible !important;
    }
    .logistics-evidence-grid .file-card { min-width: 0; max-width: 100%; }
    .logistics-evidence-grid .file-card:not(.logistics-waybill-card) {
        display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 12px;
    }
    .logistics-evidence-grid .file-icon-wrapper { width: 40px; height: 40px; }
    .logistics-evidence-grid .file-info { min-width: 0; }
    .logistics-evidence-grid .file-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }
    .logistics-evidence-grid .file-actions button { min-width: 44px; min-height: 44px; }
    body.workspace-shell-active .logistics-evidence-grid :is(strong, .file-name, .file-meta) {
        white-space: normal !important; overflow: visible; overflow-wrap: anywhere; text-overflow: clip;
    }
    .logistics-comments { grid-template-columns: minmax(0, 1fr); }
    .logistics-comment-panel .logistics-comment-composer textarea { font-size: 16px; min-height: 88px; }
    .logistics-comment-panel .logistics-comment-composer .btn-primary { min-height: 44px; }

    /* Full-height data sheets with a fixed header and action footer. */
    body:has(.modal[id^="logistics-"]), body:has(#auth-modal:not(.hidden)), body:has(#evidence-preview-modal) { overflow: hidden; }
    .modal[id^="logistics-"] { padding: 8px; box-sizing: border-box; }
    .modal[id^="logistics-"] > .modal-content {
        width: 100%; max-width: 600px; max-height: calc(100dvh - 16px);
        box-sizing: border-box; margin: auto; overflow-y: auto;
    }
    .modal[id^="logistics-"] :is(input:not([type="checkbox"]), select, textarea) {
        font-size: 16px; min-height: 44px; box-sizing: border-box;
    }
    .modal[id^="logistics-"] button { min-height: 44px; }
    .modal[id^="logistics-"] .close-btn { min-width: 44px; }
    body.workspace-shell-active .modal[id^="action-modal-"] { padding: 12px; box-sizing: border-box; }
    body.workspace-shell-active .modal[id^="action-modal-"] .modal-content {
        width: 100%; max-width: 500px; max-height: calc(100dvh - 24px); padding: 20px; overflow-y: auto;
    }
    body.workspace-shell-active .modal[id^="action-modal-"] :is(button, input, textarea, select) { min-height: 44px; font-size: 16px; }
    #logistics-data-modal > .modal-content {
        display: flex; flex-direction: column; overflow: hidden; padding: 0;
        height: calc(100dvh - 16px); border-radius: 8px;
    }
    #logistics-data-modal .modal-header { padding: 8px 12px; gap: 8px; margin: 0; }
    #logistics-data-modal .modal-header h2 { font-size: 16px; line-height: 1.4; }
    #logistics-data-modal .logistics-data-modal-scroll { padding: 12px; }
    #logistics-data-modal .logistics-data-editor-body { padding: 0; border: 0; background: transparent; }
    #logistics-data-modal .logistics-data-modal-actions { padding: 8px 12px max(8px, env(safe-area-inset-bottom, 0px)); }
    #logistics-data-modal .logistics-data-modal-actions button { flex: 1; }
    :is(#logistics-data-modal, #logistics-job-modal) .logistics-contact-grid { grid-template-columns: minmax(0, 1fr); }
    :is(#logistics-data-modal, #logistics-job-modal) .logistics-contact-field { grid-column: 1 / -1; }
    :is(#logistics-data-modal, #logistics-job-modal) .logistics-contact-label { font-size: 13px; line-height: 1.5; }
    :is(#logistics-data-modal, #logistics-job-modal) .logistics-goods-compact { --goods-control-height: 44px; --goods-control-font-size: 16px; }
    :is(#logistics-data-modal, #logistics-job-modal) .logistics-goods-compact .logistics-good-card {
        grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; padding: 12px;
    }
    :is(#logistics-data-modal, #logistics-job-modal) .logistics-good-field { grid-column: span 1; }
    :is(#logistics-data-modal, #logistics-job-modal) :is(.logistics-good-field--item_description, .logistics-good-field--material, .logistics-good-field--use, .logistics-good-field--unit_value, .logistics-good-field--resources) { grid-column: 1 / -1; }
    :is(#logistics-data-modal, #logistics-job-modal) .logistics-goods-compact .logistics-good-language-pair { grid-template-columns: minmax(0, 1fr); gap: 8px; }
    .logistics-good-resource-controls { flex-direction: column; }
    .logistics-good-field--actions { padding-top: 0; justify-content: flex-end; }
    #logistics-data-modal .logistics-mobile-wrapped-control { display: none; }
    #logistics-data-modal .logistics-mobile-readonly-value {
        display: block; min-width: 0; min-height: 44px; box-sizing: border-box;
        padding: 10px 12px; border: 1px solid #d6d8d4; border-radius: 6px;
        background: #fff; color: #242624; font-size: 15px; line-height: 1.5;
        white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text;
    }
    .logistics-mobile-readonly-value[data-language]::before {
        content: attr(data-language); display: block; margin-bottom: 4px; color: #687168; font-size: 12px;
    }
    #logistics-data-modal .logistics-money-control { height: auto; align-items: stretch; }
    #logistics-data-modal .logistics-money-control > .logistics-mobile-readonly-value { flex: 0 0 84px; }
    #logistics-data-modal [data-goods-attachments] a {
        display: flex; align-items: center; min-height: 44px; padding: 8px 0;
        font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; box-sizing: border-box;
    }
    body.workspace-shell-active #evidence-preview-modal { padding: 8px !important; box-sizing: border-box; }
    body.workspace-shell-active #evidence-preview-modal > .modal-content {
        display: flex; flex-direction: column; width: 100% !important; max-width: 100% !important;
        height: calc(100dvh - 16px); max-height: calc(100dvh - 16px) !important;
        padding: 12px !important; box-sizing: border-box;
    }
    #evidence-preview-modal .modal-header { flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
    #evidence-preview-modal .modal-header h2 { font-size: 18px; }
    #evidence-preview-modal :is(button, .btn-outline) { min-width: 44px; min-height: 44px; }
    #evidence-preview-modal .modal-body { min-height: 0; flex: 1; padding: 0 !important; margin-top: 0 !important; }
    #evidence-preview-modal .modal-body iframe { width: 100%; height: 100% !important; min-height: 0; }
    .evidence-mobile-pdf { display: flex; flex-direction: column; height: 100%; min-height: 0; }
    .evidence-pdf-controls { display: flex; align-items: center; gap: 6px; padding-bottom: 8px; }
    .evidence-pdf-controls button { padding: 0; }
    .evidence-pdf-controls span { flex: 1; text-align: center; white-space: nowrap; font-size: 14px; }
    .evidence-pdf-controls select { width: 110px; min-height: 44px; font-size: 16px; padding: 4px; }
    .evidence-pdf-stage { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
    .evidence-pdf-stage canvas { display: block; max-width: none; }
    .evidence-pdf-stage[aria-busy="true"] canvas { opacity: 0.3; }
}
