/* Layout adaptation only; desktop appearance and print templates remain page-owned. */
.fyt-menu-toggle { display: none; }
.fyt-nav-drawer { padding: 0; border: 0; }
.fyt-nav-drawer:not([open]) { display: none; }
.fyt-table-scroll-hint { display: none; }
.fyt-filter-toggle { display: none; }

@media screen {
    .fyt-table-scroll { width: 100%; max-width: 100%; overflow-x: auto; }
    [data-fyt-table-scroll] { min-width: 0; max-width: 100%; overscroll-behavior-x: contain; }
    [data-fyt-table-scroll]:focus-visible { outline: 2px solid #00807d; outline-offset: -2px; }
}

@media screen and (max-width: 960px) {
    .fyt-readable-table { min-width: var(--fyt-readable-width) !important; }
    .fyt-readable-table th { word-break: normal; overflow-wrap: normal; }
    .fyt-readable-table td { word-break: normal; overflow-wrap: break-word; }
    .fyt-layout-list :is(.table-container, .table-wrapper, .fyt-table-scroll):not(.fyt-split-table) > .fyt-readable-table:has(> thead) { table-layout: auto; }
    #rfq-table > tbody > tr > td:first-child { white-space: nowrap; }
    .fyt-table-scroll-hint { display: block; flex: 0 0 auto; margin: 0 0 10px; color: var(--fyt-legacy-text, #475569); font-size: 12px; line-height: 1.5; }
    .fyt-responsive-page img { max-width: 100%; }
    .fyt-layout-shell { height: 100vh; height: 100dvh; }
    .fyt-layout-shell .main-content { width: 100%; min-width: 0; min-height: 0; }
    .fyt-layout-shell .iframe-stage { min-height: 0; }
    .fyt-layout-shell header { height: auto; min-height: 64px; padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
    .fyt-layout-shell #top-title { flex: 1; min-width: 0; flex-shrink: 1; font-size: 16px; overflow-wrap: anywhere; }
    .fyt-layout-shell .top-right-tools { flex: 1 0 100%; flex-wrap: wrap; min-width: 0; gap: 8px; justify-content: flex-end; }
    /* The account group moves to its own line only when the row is too narrow for it. */
    .fyt-layout-shell .tools-account { flex: 1 1 auto; min-width: 0; justify-content: flex-end; }
    .fyt-layout-shell .user-info { flex: 1; min-width: 0; gap: 6px; }
    .fyt-layout-shell #display-username { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .fyt-layout-shell .user-avatar { flex-shrink: 0; }
    .fyt-layout-shell .lang-select { max-width: 110px; min-height: 36px; padding: 6px 8px; }
    .fyt-layout-shell .btn-logout { min-height: 36px; padding: 6px 10px; flex-shrink: 0; }
    .fyt-layout-shell .announcement-bar { order: 3; flex: 1 0 100%; margin: 0; }
    .fyt-layout-shell .announcement-bar.no-announcement { display: none; }
    .fyt-layout-shell .tab-bar { padding-left: 8px; padding-right: 8px; }
    .fyt-menu-toggle, .fyt-menu-close { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex-shrink: 0; border: 1px solid var(--fyt-legacy-border, #64748b); border-radius: 6px; background: #0f172a; color: white; font: inherit; font-size: 22px; line-height: 1; cursor: pointer; }
    .fyt-menu-toggle:hover, .fyt-menu-close:hover { background: #334155; }
    .fyt-menu-toggle:active, .fyt-menu-close:active { background: #475569; }
    .fyt-menu-toggle:focus-visible, .fyt-menu-close:focus-visible, .fyt-nav-drawer a:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }
    .fyt-nav-drawer { position: fixed; inset: 0 auto 0 0; width: min(300px, calc(100vw - 40px)); max-width: none; height: 100vh; height: 100dvh; max-height: none; margin: 0; background: #0f172a; color: white; }
    .fyt-nav-drawer::backdrop { background: rgb(15 23 42 / 55%); }
    .fyt-nav-drawer .sidebar { width: 100%; height: 100%; }
    .fyt-nav-drawer .brand-logo { padding-right: 52px; }
    .fyt-nav-drawer .menu-list { min-height: 0; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
    .fyt-menu-close { position: absolute; top: 14px; right: 10px; z-index: 1; }
    .fyt-nav-drawer .menu-item a, .fyt-nav-drawer .submenu-item a { min-height: 44px; }

    body.fyt-responsive-page:not(.fyt-layout-shell) { box-sizing: border-box; min-width: 0; width: auto; padding: 12px; }
    .fyt-responsive-page:not(.fyt-layout-shell) :is(.container, .page-container, .page-card, .panel, .report-container) { min-width: 0; max-width: 100%; box-sizing: border-box; }
    .fyt-responsive-page:not(.fyt-layout-shell) > :is(.card, .panel, .container, .page-container, .page-card) { padding: 18px; width: 100%; max-width: 100%; min-width: 0; }
    .fyt-responsive-page :is(.header-bar, .header-title, .header-row, .panel-header, .toolbar, .tool-bar, .header-right, .actions, .add-area, .add-row) { flex-wrap: wrap; gap: 10px; min-width: 0; max-width: 100%; }
    .fyt-responsive-page :is(.header-bar, .header-title, .header-row, .panel-header) { align-items: flex-start; }
    .fyt-responsive-page :is(h1, h2, h3, label) { overflow-wrap: anywhere; }
    .fyt-responsive-page :is(.header-bar, .header-title, .panel-header) > :is(h1, h2) { min-width: 0; }
    .fyt-responsive-page :is(.table-wrapper, .table-container, .table-body-scroll, .table-frame, .table-shell, .data-area, .fyt-table-scroll) { min-width: 0 !important; max-width: 100%; }
    /* Reuse existing scroll owners; do not force overflow on combo-menu surfaces. */
    .fyt-responsive-page .fyt-split-table { overflow-x: auto !important; }
    .fyt-responsive-page .fyt-split-table > :is(.table-header-row, .table-header, .table-header-table-wrap, .table-body-scroll, .data-scroll, .table-scroll) { width: var(--fyt-split-width, 100%); min-width: var(--fyt-split-width, 100%); max-width: none !important; }
    .fyt-responsive-page .fyt-split-table :is(.table-body-scroll, .data-scroll, .table-scroll) { overflow-x: hidden !important; }
    .fyt-responsive-page .fyt-split-table .table-header-main { max-width: none; }
    .fyt-layout-list .table-container:not(.fyt-split-table) { overflow-x: auto; }
    .fyt-responsive-page :is(.table-header-row, .table-header-main) { min-width: 0; max-width: 100%; }

    /* Form pages scroll as documents; list surfaces retain their existing table scroller. */
    html:has(> body.fyt-layout-form), body.fyt-layout-form { height: auto !important; overflow: visible !important; }
    .fyt-layout-form > :is(.container, .card, .page-container, .page-card) { height: auto !important; min-height: calc(100dvh - 24px); overflow: visible !important; }
    .fyt-layout-form :is(.form-grid, .basic-grid, .person-grid, .title-info-grid, .accounting-grid, .field-grid, .grid, .grid-2, .grid-4, .grid-5) { width: 100% !important; min-width: 0 !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .fyt-layout-form :is(.form-grid, .basic-grid, .person-grid, .title-info-grid, .accounting-grid, .field-grid, .grid, .grid-2, .grid-4, .grid-5) > * { min-width: 0 !important; max-width: 100%; grid-column: auto !important; }
    /* A spanning field (e.g. Upload inside a display:contents row) would add 0px columns; give it the full row instead. */
    .fyt-layout-form :is(.form-grid, .basic-grid, .person-grid, .title-info-grid, .accounting-grid, .field-grid, .grid, .grid-2, .grid-4, .grid-5) :is(.col-span-2, .col-span-3) { grid-column: 1 / -1 !important; }
    .fyt-layout-form :is(.form-group, .field, .input-group, .form-item) :is(input:not([type='checkbox']):not([type='radio']), select, textarea), .fyt-layout-form .form-grid :is(input:not([type='checkbox']):not([type='radio']), select, textarea) { width: 100% !important; max-width: 100% !important; min-width: 0 !important; box-sizing: border-box; }
    .fyt-layout-form :is(.basic-section, .goods-section, .section, .product-card) { min-width: 0; max-width: 100%; }
    .fyt-layout-form :is(.header-title, .sticky-header) { position: relative !important; top: auto !important; }
    .fyt-layout-form::before { display: none; }
    .fyt-layout-form :is(.attachment-container, .attachment-row, .second-row-container) { max-width: 100%; min-width: 0; flex-wrap: wrap; }

    .fyt-layout-list > :is(.container, .card, .page-container, .page-card) { width: 100%; min-width: 0; height: calc(100vh - 24px); height: calc(100dvh - 24px); min-height: 0; }
    .fyt-layout-list :is(.container, .card, .page-container) > .fyt-table-scroll { flex: 1; min-height: 0; overflow: auto; }
    .fyt-layout-list :is(.toolbar, .tool-bar, .add-area, .add-row, .header-right) :is(input:not([type='checkbox']):not([type='radio']), select) { max-width: 100%; min-width: 0; }
    .fyt-layout-list :is(.form-grid, .add-area) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .fyt-layout-hub :is(.grid, .grid-layout, .hub-grid) { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .fyt-layout-hub :is(.grid, .grid-layout, .hub-grid) > * { width: auto; min-width: 0; max-width: 100%; }
    .fyt-responsive-page :is(.report-layout, .chart-top, .pie-chart) { grid-template-columns: minmax(0, 1fr); }
    .fyt-responsive-page :is(.search-grid, .permission-columns, .stats) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .fyt-responsive-page :is(.chart-container, .chart-panel, .report-panel) { min-width: 0; max-width: 100%; }
    .fyt-responsive-page canvas { max-width: 100%; }
    .fyt-layout-auth { min-height: 100vh; min-height: 100dvh; padding-top: 76px !important; padding-bottom: 24px !important; }
    .fyt-layout-auth :is(.login-box, .auth-card, .login-card, .container, .card) { max-width: 100%; }
    .fyt-layout-auth .lang-bar { top: 16px; right: 16px; left: 16px; flex-wrap: wrap; justify-content: flex-end; }
    .fyt-responsive-page :is(.modal-content, .dialog, .modal-box) { max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); box-sizing: border-box; }
    .fyt-responsive-page :is(.actions, .action-bars, .header-actions, .header-step) { flex-wrap: wrap !important; flex-shrink: 1; max-width: 100%; min-width: 0; gap: 8px; }
    .fyt-layout-form .top-freeze-area { position: relative; top: auto; margin: 0 0 20px; padding: 0; width: 100%; }
    .fyt-layout-form .top-selector-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .fyt-layout-form .top-selector-panel > * { min-width: 0; max-width: 100%; }
    .fyt-layout-form :is(.standard-combo-input, .top-selector-panel input) { width: 100%; min-width: 0; max-width: 100%; }
    .fyt-layout-list .toolbar, .fyt-layout-list .add-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .fyt-layout-list .add-row > * { grid-column: auto !important; min-width: 0; width: 100%; box-sizing: border-box; }
    .fyt-layout-form :is(.row-grid-9, .row-grid-8, .row-grid-7, .row-grid-6, .row-grid-5, .row-grid-4, .fields-grid, .tariff-grid) { width: 100% !important; min-width: 0 !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .fyt-layout-form :is(.row-grid-9, .row-grid-8, .row-grid-7, .row-grid-6, .row-grid-5, .row-grid-4, .fields-grid, .tariff-grid) > * { min-width: 0; max-width: 100%; grid-column: auto !important; }
    .fyt-layout-form :is(.actions, .action-bars, .header-actions, .page-actions) { margin-left: 0 !important; margin-right: 0 !important; }
    .fyt-responsive-page :is(.page-header, .page-actions, .main-inputs) { display: flex; flex-wrap: wrap; gap: 8px; max-width: 100%; min-width: 0; }
    .fyt-layout-list :is(.main-inputs-wrap, #specContainer) { width: 100%; max-width: 100%; min-width: 0; }
    .fyt-layout-list .main-inputs { width: 100%; }
    .fyt-layout-list .main-inputs > * { flex: 1 1 150px; max-width: 100%; min-width: 0; }
    .fyt-layout-list #specContainer .spec-item { flex: 1 1 180px; max-width: 100%; min-width: 0; }
    .fyt-layout-list .spec-item .spec-combo { min-width: 0; max-width: 100%; flex: 1; }
    .fyt-layout-list .add-section { flex-wrap: wrap; max-width: 100%; min-width: 0; gap: 10px; grid-template-columns: minmax(0, 1fr); }
    .fyt-layout-list .add-section > .btn-submit { justify-self: start; }
    .fyt-layout-form :is(.our-q-row, .client-po-row, .row-grid-details) { width: 100% !important; min-width: 0 !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .fyt-layout-form :is(.our-q-row, .client-po-row, .row-grid-details) > * { min-width: 0 !important; max-width: 100%; grid-column: auto !important; }
    .fyt-responsive-page :is(.data-scroll, .table-header) { min-width: 0; max-width: 100%; }
    .fyt-layout-form .top-selector-row { grid-template-columns: repeat(2, minmax(0, 1fr)); min-width: 0; }
    .fyt-layout-form .content-scroll { height: auto; min-height: 0; overflow: visible; }
    .fyt-responsive-page :is(.modal-content, .dialog, .modal-box) { min-width: 0 !important; overflow-y: auto; }
    .fyt-responsive-page :is(.page-head, .btn-group, .invoice-toolbar, .search-bar) { flex-wrap: wrap; min-width: 0; max-width: 100%; gap: 8px; }
    .fyt-responsive-page .page-head .actions { flex-basis: 100%; width: 100%; }
    .fyt-layout-form :is(.quotation-main-row, .row-grid-12, .info-grid) { width: 100% !important; min-width: 0 !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .fyt-layout-form :is(.quotation-main-row, .row-grid-12, .info-grid) > * { grid-column: auto !important; min-width: 0; max-width: 100%; }
    .fyt-layout-report { height: auto !important; overflow: visible !important; }
    html:has(> body.fyt-layout-report) { height: auto !important; overflow: visible !important; }
    .fyt-layout-report > :is(.container, .card) { height: auto; min-height: calc(100dvh - 24px); overflow: visible; }
    .fyt-layout-report :is(.report-layout, .chart-panel, .report-panel) { height: auto; overflow: visible; }
}

@media screen and (max-width: 600px) {
    .fyt-responsive-page:not(.fyt-layout-shell) > :is(.card, .panel, .container, .page-container, .page-card) { padding: 14px; }
    .fyt-layout-form :is(.form-grid, .basic-grid, .person-grid, .title-info-grid, .accounting-grid, .field-grid, .grid, .grid-2, .grid-4, .grid-5),
    .fyt-layout-hub :is(.grid, .grid-layout, .hub-grid),
    .fyt-responsive-page :is(.search-grid, .permission-columns),
    .fyt-layout-list :is(.form-grid, .add-area) { grid-template-columns: minmax(0, 1fr) !important; }
    .fyt-layout-form :is(.section, .product-card) { padding: 12px; }
    .fyt-layout-form :is(.top-selector-panel, .input-row-2, .input-row-3) { grid-template-columns: minmax(0, 1fr); }
    .fyt-layout-form :is(.row-grid-9, .row-grid-8, .row-grid-7, .row-grid-6, .row-grid-5, .row-grid-4, .fields-grid, .tariff-grid) { grid-template-columns: minmax(0, 1fr) !important; }
    .fyt-layout-form :is(.our-q-row, .client-po-row, .row-grid-details) { grid-template-columns: minmax(0, 1fr) !important; }
    .fyt-layout-form .top-selector-row { grid-template-columns: minmax(0, 1fr); }
    .fyt-layout-form :is(.quotation-main-row, .row-grid-12, .info-grid) { grid-template-columns: minmax(0, 1fr) !important; }
    .fyt-layout-form .grid-wrapper { flex-wrap: wrap; }
    .fyt-responsive-page > .page { box-sizing: border-box; min-width: 0; max-width: 100%; padding: 14px; }
    .fyt-layout-form :is(.actions, .action-bars, .header-actions) { width: 100%; justify-content: flex-start; }
    .fyt-layout-list :is(.add-area, .add-row, .header-right) { width: 100%; }
    .fyt-layout-list :is(.toolbar, .tool-bar) { width: 100%; gap: 8px; }
    .fyt-responsive-page :is(.header-bar, .header-title, .panel-header) { gap: 10px; }
    .fyt-responsive-page :is(.btn-back, .btn-top-add, .btn-save, .btn-cancel) { padding-left: 12px; padding-right: 12px; }
    .fyt-responsive-page :is(.calendar, .calendar-grid) { grid-template-columns: minmax(0, 1fr); }
    .fyt-layout-overview .kpi-grid, .fyt-layout-overview .finished-grid { grid-template-columns: minmax(0, 1fr); }
    html:has(> body.fyt-layout-list), body.fyt-layout-list { height: auto !important; overflow: visible !important; }
    .fyt-layout-list > :is(.container, .card, .page-container, .page-card) { height: auto !important; min-height: calc(100dvh - 24px); overflow: visible; }
    .fyt-layout-list .table-frame { flex: 0 0 auto; height: 65dvh; min-height: 240px; }
    .fyt-layout-list :is(.table-wrapper, .fyt-table-scroll) { max-height: 65dvh; min-height: 220px; }
    .fyt-layout-list .table-frame .fyt-table-scroll { min-height: 0; }

    /* Phone cards (responsive.js prepareCardTables): one card per row, label left and value right, no sideways scroll. */
    .fyt-card-mode .fyt-table-scroll-hint { display: none !important; }
    .fyt-filter-toggle { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; align-self: flex-start; margin: 0 0 10px; min-height: 36px; padding: 6px 14px; border: 1px solid var(--fyt-legacy-border, #94a3b8); border-radius: 6px; background: var(--fyt-legacy-surface, #fff); color: var(--fyt-legacy-text, #334155); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
    .fyt-filter-toggle::after { content: '▾'; }
    .fyt-filter-toggle[aria-expanded="true"]::after { content: '▴'; }
    .fyt-filter-toggle:focus-visible { outline: 2px solid #00807d; outline-offset: 2px; }
    .fyt-card-scope { overflow-x: hidden !important; }
    .fyt-responsive-page table:is(.fyt-card-table, .fyt-card-head) { display: block; width: 100% !important; min-width: 0 !important; max-width: 100% !important; table-layout: auto; }
    :is(.fyt-card-table, .fyt-card-head) > colgroup { display: none; }
    :is(.fyt-card-table, .fyt-card-head) > :is(thead, tbody) { display: block; }
    .fyt-card-scope:not(.fyt-filters-open) :is(.fyt-card-headwrap, .fyt-card-table > thead) { display: none !important; }
    .fyt-card-scope.fyt-filters-open .fyt-card-headwrap { display: block !important; width: 100% !important; min-width: 0 !important; }
    .fyt-card-headwrap .scrollbar-header-spacer { display: none; }
    .fyt-card-label-row { display: flex !important; justify-content: flex-end; }
    .fyt-card-label-row > :not(:has(button:not([hidden]))) { display: none !important; }
    .fyt-card-label-row > * { position: relative !important; top: auto !important; border: 0 !important; background: transparent !important; }
    .fyt-card-filter-row { display: grid !important; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 4px 0 12px; }
    .fyt-card-filter-row > :is(th, td) { display: block; width: auto !important; min-width: 0 !important; max-width: none !important; height: auto !important; padding: 0 !important; border: 0 !important; position: relative !important; top: auto !important; background: transparent !important; text-align: left !important; }
    /* Sticky-header z-indexes would give every stacked filter its own layer, so later filters covered an open dropdown. */
    .fyt-card-filter-row > :is(th, td) { z-index: auto !important; }
    .fyt-card-filter-row > :is(th, td):is(:focus-within, :has(.show, .open, [aria-expanded="true"])) { z-index: 30 !important; }
    .fyt-card-filter-row > :is(th, td)::before { content: attr(data-fyt-label); display: block; margin: 0 0 4px; color: var(--fyt-legacy-muted, #64748b); font-size: 11px; font-weight: 600; text-transform: uppercase; }
    .fyt-card-filter-row > :is(th, td)[data-fyt-label=""]::before { display: none; }
    .fyt-card-filter-row > :is(th, td):not(:has(input, select, textarea, button)) { display: none !important; }
    /* display sits in :where() so page rules that hide filtered rows or columns still win. */
    :where(.fyt-card-table > tbody > tr, .fyt-card-table > tbody > tr > td) { display: block; }
    .fyt-card-table > tbody > tr { margin: 0 0 10px; padding: 4px 12px; border: 1px solid var(--fyt-legacy-border, #e2e8f0); border-radius: 8px; background: var(--fyt-legacy-surface, #fff); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05); }
    .fyt-responsive-page .fyt-card-table > tbody > tr > td { position: relative !important; left: auto !important; width: auto !important; min-width: 0 !important; max-width: none !important; height: auto !important; min-height: 34px; box-sizing: border-box; padding: 7px 0 7px calc(38% + 12px) !important; border: 0 !important; border-bottom: 1px solid var(--fyt-legacy-border, #f1f5f9) !important; text-align: right !important; white-space: normal !important; overflow: visible !important; overflow-wrap: anywhere; }
    .fyt-responsive-page .fyt-card-table > tbody > tr > td:last-child { border-bottom: 0 !important; }
    .fyt-card-table > tbody > tr > td::before { content: attr(data-fyt-label); position: absolute; left: 0; top: 7px; width: 38%; color: var(--fyt-legacy-muted, #64748b); font-size: 11px; font-weight: 600; line-height: 1.6; text-align: left; text-transform: uppercase; overflow-wrap: anywhere; }
    .fyt-responsive-page .fyt-card-table > tbody > tr > td:is([data-fyt-label=""], [data-fyt-full]) { padding-left: 0 !important; }
    .fyt-card-table > tbody > tr > td:is([data-fyt-label=""], [data-fyt-full])::before { display: none; }
    .fyt-responsive-page .fyt-card-table > tbody > tr > td[data-fyt-full] { text-align: center !important; }
    .fyt-card-table > tbody > tr > td :is(.action-buttons, .actions, .btn-group) { justify-content: flex-end; flex-wrap: wrap; }
}

/* Summary pagination stays below the table while only its records scroll, including phone cards. */
@media screen and (max-width: 960px) {
    html:has(> body.sum-page.fyt-responsive-page), body.sum-page.fyt-responsive-page {
        height: 100vh !important;
        height: 100dvh !important;
        overflow: hidden !important;
    }
    body.sum-page.fyt-responsive-page { padding: 0; }
    .sum-page > .sum-card { height: 100%; min-height: 0; }
    .sum-page .sum-header { flex-wrap: wrap; }
    .sum-page .sum-header-buttons { flex-wrap: wrap; }
}

@media print {
    .fyt-menu-toggle, .fyt-nav-drawer { display: none !important; }
    .fyt-table-scroll { display: contents; }
}
