/* Layout round 1 (2026-11-29): space, navigation and page headers on phones.
 * Presentation only. Loaded after theme-modern.css / checkrow.css; every rule is
 * inside the mobile media query, so desktop is unchanged. layout-r1.js adds the
 * .xj-* helper classes; without it these rules fall back to the previous layout. */

@media (max-width: 820px) and (min-height: 481px), (max-width: 820px) and (orientation: portrait) {
    /* ---------- 1. Bottom navigation: 56px bar, 8px from the edge, pill behind the icon ---------- */
    .compact-ui.has-mobile-nav .topbar nav {
        inset: auto 10px calc(8px + env(safe-area-inset-bottom, 0px)); padding: 4px; gap: 0; border-radius: 20px;
    }
    .compact-ui.has-mobile-nav .topbar nav > a,
    .compact-ui.has-mobile-nav .mobile-nav-more > summary {
        min-height: 48px; gap: 2px; padding: 3px 2px; border-radius: 14px;
        font-size: .6875rem; line-height: 1.2; background: transparent;
    }
    .compact-ui.has-mobile-nav .topbar nav > a.active,
    .compact-ui.has-mobile-nav .mobile-nav-more > summary.active,
    .compact-ui.has-mobile-nav .mobile-nav-more[open] > summary { background: transparent; }
    .compact-ui.has-mobile-nav .mobile-nav-icon {
        box-sizing: content-box; width: 20px; height: 20px; padding: 3px 14px; border-radius: 9999px;
    }
    .compact-ui.has-mobile-nav .topbar nav > a.active .mobile-nav-icon,
    .compact-ui.has-mobile-nav .mobile-nav-more > summary.active .mobile-nav-icon,
    .compact-ui.has-mobile-nav .mobile-nav-more[open] > summary .mobile-nav-icon { background: var(--xj-brand-soft, #EEF2FF); }
    .compact-ui.has-mobile-nav .page,
    .compact-ui.has-mobile-nav main,
    .compact-ui.has-mobile-nav .content { padding-bottom: calc(var(--mobile-nav-height, 56px) + 32px); }
    .compact-ui.has-mobile-nav .mobile-nav-panel { margin-bottom: 8px; }
}

@media (max-width: 820px) {
    /* ---------- 2. Inspection list rows ---------- */
    /* Pending: full title (up to 3 lines), compact round buttons, no empty second row. */
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr.task-card-structured[data-xj-state="pending"]:has([data-quick-result]) {
        grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto; gap: 0 8px; padding: 10px 10px 10px 14px;
    }
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr.task-card-structured[data-xj-state="pending"]:has([data-quick-result]) .dashboard-item-title strong {
        -webkit-line-clamp: 3; font-size: .9375rem; line-height: 1.35; overflow-wrap: anywhere;
    }
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr[data-xj-state="pending"]:has([data-quick-result]) > .dashboard-item-code:not(:has(.dashboard-archive-badge)) { display: none; }
    /* Code text stays hidden; only the archive badge it carries is shown. */
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr[data-xj-state="pending"]:has([data-quick-result]) > .dashboard-item-code:has(.dashboard-archive-badge) {
        grid-column: 1; grid-row: 2; min-width: 0; padding: 0; font-size: 0; line-height: 0;
    }
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr[data-xj-state="pending"]:has([data-quick-result]) > .dashboard-item-actions {
        grid-row: 1 / -1; align-self: center; justify-self: end; width: auto; min-width: 0;
    }
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr[data-xj-state="pending"] .dashboard-item-primary-action:has([data-quick-result]) {
        gap: 4px; justify-content: flex-end;
    }
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr[data-xj-state="pending"][data-inspection-card] .dashboard-item-primary-action [data-quick-result][data-inspection-card-control] {
        width: 42px; min-width: 42px; height: 42px; min-height: 42px; margin: 0;
    }
    /* No item codes on phone cards (cards 2026-11-29). The code cell can also carry the
       archive badge or the deadline; then only the code text itself is hidden. */
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr.dashboard-item-row > .dashboard-item-code:not(:has(.dashboard-archive-badge, .task-deadline)) { display: none; }
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr.dashboard-item-row:not(:has([data-quick-result])) > .dashboard-item-code:has(.dashboard-archive-badge, .task-deadline) { font-size: 0; }
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr.dashboard-item-row:not(:has([data-quick-result])) > .dashboard-item-code > .task-deadline { font-size: .75rem; }
    /* Full titles (up to 3 lines) on every card that is not a collapsed done row. */
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr.dashboard-item-row:is([data-xj-state="pending"], [data-xj-state="issue"], [data-xj-state="review"]) .dashboard-item-title strong {
        display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
        white-space: normal; text-overflow: clip; overflow-wrap: anywhere;
    }
    /* Pending rows this account cannot record (no round, or no inspect right): no empty action area. */
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr[data-xj-state="pending"]:not(:has([data-quick-result])) > .dashboard-item-actions:not(:has(a, button, form, input, select)) { display: none; }

    /* Archive badge: one amber line under the title. */
    .compact-ui.xj-checkrow .dashboard-compact-list tr.dashboard-item-row .dashboard-archive-badge {
        display: inline-block; width: auto; max-width: 100%; margin: 4px 0 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
        font-size: .75rem; font-weight: 600; line-height: 1.3; color: #B54708;
    }
    .compact-ui.xj-checkrow .dashboard-compact-list tr.dashboard-item-row .dashboard-archive-badge::before { content: '● '; font-size: .625rem; vertical-align: 1px; }
    .compact-ui.xj-checkrow.v10-dashboard .dashboard-compact-list tr.dashboard-item-row:is([data-xj-state="ok"], [data-xj-state="na"], [data-xj-state="closed"]):not(.xj-open) .dashboard-archive-badge { display: none; }

    /* ---------- 3. Inspect / not-applicable dialogs only: compact standard, action bar always reachable ---------- */
    .compact-ui dialog[open] .inspection-standard-panel {
        margin: 0; padding: 10px 12px; border: 0; border-radius: 12px; font-size: .8125rem; line-height: 1.5;
        background: var(--xj-surface-2, #F4F6FA); color: var(--xj-ink-2, #334155);
    }
    .compact-ui dialog[open] .inspection-standard-panel > p { margin: 4px 0 0; font-size: .9375rem; color: var(--xj-ink, #0F172A); }
    .compact-ui dialog[open] .inspection-standard-panel.is-empty { padding: 0; background: transparent; color: var(--xj-ink-muted, #64748B); }
    .compact-ui dialog[open] .inspection-standard-panel.is-empty > p { display: none; }
    .compact-ui dialog:is([id^="inspect-"], [id^="na-"])[open] form > .dialog-actions {
        position: sticky; bottom: -16px; z-index: 2; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 8px;
        width: calc(100% + 32px); max-width: none; box-sizing: border-box; margin: 4px -16px -16px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
        background: var(--xj-card, #FFFFFF); box-shadow: 0 -1px 0 var(--xj-line, #E4E7EE); border: 0;
    }
    .compact-ui dialog:is([id^="inspect-"], [id^="na-"])[open] form > .dialog-actions > button { width: 100%; max-width: none; min-height: 48px; margin: 0; flex: none; }

    /* ---------- 4. Inspection list header ---------- */
    /* One progress card while a round is running. */
    .compact-ui.xj-run-merged .inspection-run-panel { display: none; }
    .compact-ui.xj-run-merged .mobile-dashboard-summary > div:not(.xj-run-hero):not(.xj-run-foot),
    .compact-ui.xj-run-merged .mobile-dashboard-summary > p { display: none; }
    .compact-ui .mobile-dashboard-summary :is(.xj-run-hero, .xj-run-foot) { grid-column: 1 / -1; }
    .compact-ui .mobile-dashboard-summary .xj-run-hero { display: flex; flex-direction: column; gap: 2px; margin: 4px 0 0; }
    .compact-ui .mobile-dashboard-summary .xj-run-hero > strong { order: 0; }
    .compact-ui .mobile-dashboard-summary .xj-run-hero > span { order: 1; }
    .compact-ui .mobile-dashboard-summary .xj-run-hero strong { display: block; font-size: 1.75rem; line-height: 1.15; font-weight: 800; color: #FFFFFF; }
    .compact-ui .mobile-dashboard-summary .xj-run-hero span { display: block; font-size: .8125rem; color: var(--xj-on-brand-muted, rgba(255,255,255,.78)); }
    .compact-ui .mobile-dashboard-summary .xj-run-hero a { color: #FFFFFF; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
    .compact-ui .mobile-dashboard-summary .xj-run-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
    .compact-ui .mobile-dashboard-summary .xj-run-foot form { margin: 0; }
    .compact-ui .mobile-dashboard-summary .xj-run-foot button {
        min-height: 32px; padding: 0 12px; border: 1px solid rgba(255,255,255,.45); border-radius: 9999px;
        background: transparent; box-shadow: none; color: #FFFFFF; font-size: .8125rem; font-weight: 600;
    }
    .compact-ui .mobile-dashboard-summary .xj-run-foot .figma-overview-progress { flex: 1; margin: 0; }
    /* Date chip opens the date / filter / calendar panel. */
    .compact-ui .figma-overview-heading .xj-date-chip {
        display: inline-flex; align-items: center; gap: 4px; min-height: 30px; padding: 0 10px;
        border: 0; border-radius: 9999px; background: rgba(255,255,255,.18); box-shadow: none;
        color: #FFFFFF; font-size: .8125rem; font-weight: 600;
    }
    .compact-ui .figma-overview-heading .xj-date-chip::after {
        content: ''; width: 14px; height: 14px; background: currentColor;
        -webkit-mask: url("figma-nav/filter.svg") center/contain no-repeat; mask: url("figma-nav/filter.svg") center/contain no-repeat;
    }
    .compact-ui.xj-date-chip-ready:not(.xj-filters-open) .dashboard-filter-panel { display: none; }
    .compact-ui.xj-date-chip-ready.xj-filters-open .dashboard-filter-panel { margin-top: 8px; }
    .compact-ui.xj-date-chip-ready .figma-overview-heading > span:not(.xj-date-chip) { display: none; }

    /* ---------- 5. 待整改 page ---------- */
    .compact-ui .corrections-summary { gap: 8px; }
    .compact-ui .corrections-status-filters button[data-xj-count="0"]:not([aria-pressed="true"]) { display: none; }
    .compact-ui .corrections-ui.xj-few .corrections-priority { display: none; }
    .compact-ui .corrections-status-filters { display: flex; flex-wrap: wrap; gap: 6px; border: 0; }
    .compact-ui .corrections-status-filters button {
        display: inline-flex; align-items: center; gap: 6px; width: auto; min-height: 34px; padding: 0 12px;
        border: 0; border-radius: 9999px; background: var(--xj-card, #FFFFFF); box-shadow: 0 1px 2px rgba(16,24,40,.06);
        font-size: .8125rem;
    }
    .compact-ui .corrections-status-filters button[aria-pressed="true"] { background: var(--xj-brand-soft, #EEF2FF); color: var(--xj-brand, #3B5BDB); }
    .compact-ui .corrections-status-filters button.is-overdue strong { color: #D92D20; }
    .compact-ui .corrections-history {
        display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; font-size: 0;
        border-radius: 9999px; background: var(--xj-card, #FFFFFF);
    }
    .compact-ui .corrections-history::before {
        content: ''; width: 18px; height: 18px; background: var(--xj-ink-muted, #64748B);
        -webkit-mask: url("figma-nav/calendar.svg") center/contain no-repeat; mask: url("figma-nav/calendar.svg") center/contain no-repeat;
    }
    .compact-ui .corrections-toolbar { display: flex; align-items: center; gap: 8px; }
    .compact-ui .corrections-toolbar .corrections-filter { flex: 1; min-width: 0; }

    /* Card */
    /* minmax(0,1fr): the one-line ellipsis title must not widen the column (and every row) to its full text. */
    .compact-ui article.correction-card.xj-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 14px; min-width: 0; }
    .compact-ui article.correction-card.xj-card .correction-card-heading { display: flex; align-items: flex-start; gap: 8px; margin: 0; }
    .compact-ui article.correction-card.xj-card .correction-card-heading h2 { flex: 1; min-width: 0; margin: 0; font-size: 1rem; line-height: 1.35; overflow-wrap: anywhere; }
    .compact-ui article.correction-card.xj-card[data-correction-state="pending_rectification"] .correction-card-heading > .pill { display: none; }
    .compact-ui article.correction-card.xj-card .xj-due-tag {
        flex: none; padding: 3px 8px; border-radius: 9999px; font-size: .75rem; font-weight: 700; line-height: 1.3;
        background: #FFF4E5; color: #B54708; white-space: nowrap;
    }
    .compact-ui article.correction-card.xj-card .xj-due-tag.is-late { background: #FEE4E2; color: #B42318; }
    .compact-ui article.correction-card.xj-card .task-deadline { display: none; }
    .compact-ui article.correction-card.xj-card .xj-problem { display: flex; gap: 10px; align-items: flex-start; }
    .compact-ui article.correction-card.xj-card .xj-thumb {
        flex: none; position: relative; width: 64px; height: 64px; padding: 0; border: 0; border-radius: 10px; overflow: hidden;
        background: var(--xj-surface-2, #F4F6FA); box-shadow: none;
    }
    .compact-ui article.correction-card.xj-card .xj-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
    .compact-ui article.correction-card.xj-card .xj-thumb b {
        position: absolute; right: 4px; bottom: 4px; padding: 0 5px; border-radius: 6px; background: rgba(15,23,42,.7);
        color: #FFFFFF; font-size: .6875rem; line-height: 1.5;
    }
    .compact-ui article.correction-card.xj-card .correction-card-problem { flex: 1; margin: 0; padding: 0; border: 0; font-size: .9375rem; line-height: 1.45; }
    .compact-ui article.correction-card.xj-card .correction-card-problem.is-empty { color: var(--xj-ink-muted, #64748B); font-style: italic; }
    .compact-ui article.correction-card.xj-card .correction-card-meta { display: block; margin: 0; font-size: .75rem; color: var(--xj-ink-muted, #64748B); }
    .compact-ui article.correction-card.xj-card .correction-card-meta > * { display: inline; margin: 0; padding: 0; border: 0; background: none; font-size: inherit; color: inherit; }
    .compact-ui article.correction-card.xj-card .correction-card-meta > * + *::before { content: ' · '; }
    .compact-ui article.correction-card.xj-card .correction-card-meta [data-column="department-completion"][data-xj-reported="0"] { display: none; }
    .compact-ui article.correction-card.xj-card .correction-card-footer { display: block; margin: 0; padding: 0; border: 0; }
    .compact-ui article.correction-card.xj-card .correction-card-footer > .photo-gallery { display: none; }
    .compact-ui article.correction-card.xj-card .correction-card-actions { display: flex; flex-direction: column-reverse; align-items: stretch; gap: 2px; }
    .compact-ui article.correction-card.xj-card .correction-card-actions > .primary { width: 100%; min-height: 46px; }
    .compact-ui article.correction-card.xj-card .correction-card-actions > a:not(.primary) {
        align-self: center; min-height: 36px; padding: 0 12px; border: 0; background: transparent; box-shadow: none;
        color: var(--xj-ink-muted, #64748B); font-size: .8125rem; font-weight: 500;
    }
    .compact-ui article.correction-card.xj-card .correction-card-actions > a:not(.primary)::before { display: none; }

    /* ---------- 6. 报修 page ---------- */
    .compact-ui .xj-help-icon { display: inline-flex; }
    .compact-ui .xj-help-icon > summary {
        display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0;
        border-radius: 9999px; background: var(--xj-card, #FFFFFF); list-style: none; font-size: 0; cursor: pointer;
    }
    .compact-ui .xj-help-icon > summary::-webkit-details-marker { display: none; }
    .compact-ui .xj-help-icon > summary::before { content: '?'; font-size: .9375rem; font-weight: 700; color: var(--xj-ink-muted, #64748B); }
    .compact-ui .xj-help-icon[open] { display: block; width: 100%; }
    .compact-ui .xj-zero { display: none !important; }
    .compact-ui .xj-area-missing { display: none !important; }
    .compact-ui .module-repairs .section-head .repair-heading { flex-wrap: wrap; align-items: center; gap: 8px; }
    .compact-ui .module-repairs .section-head .repair-heading > h2 { margin: 0; }
    .compact-ui .module-repairs .section-head .repair-heading > .primary { margin-left: auto; }
    .compact-ui .module-repairs .section-head .repair-heading > .xj-help-icon[open] { order: 9; }
    .compact-ui .module-repairs .repair-summary { display: flex; flex-wrap: wrap; gap: 6px; border: 0; padding: 0; }
    .compact-ui .module-repairs .repair-summary > span {
        display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px;
        border-radius: 9999px; background: var(--xj-card, #FFFFFF); font-size: .8125rem;
    }
    .compact-ui .module-repairs .repair-row-body { display: flex; gap: 10px; align-items: flex-start; }
    .compact-ui .module-repairs .repair-row-body .repair-row-text { flex: 1; min-width: 0; }
    .compact-ui .module-repairs .xj-repair-thumb {
        display: block; position: relative; flex: none; width: 64px; height: 64px; border-radius: 10px; overflow: hidden;
        background: var(--xj-surface-2, #F4F6FA);
    }
    .compact-ui .module-repairs .xj-repair-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
    .compact-ui .module-repairs .xj-repair-thumb b {
        position: absolute; right: 4px; bottom: 4px; padding: 0 5px; border-radius: 6px; background: rgba(15,23,42,.7);
        color: #FFFFFF; font-size: .6875rem; line-height: 1.5;
    }
    .compact-ui .module-repairs .xj-repair-thumb ~ .repair-row-text > a.link-button.secondary { display: none; }
    .compact-ui .module-repairs .repair-brief::before { content: attr(data-xj-label) '：'; font-weight: 600; color: var(--xj-ink-2, #334155); }
    .compact-ui .module-repairs .xj-done-group { margin-top: 8px; }
    .compact-ui .module-repairs .xj-done-group > summary {
        min-height: 44px; display: flex; align-items: center; padding: 0 4px; cursor: pointer;
        font-size: .875rem; font-weight: 600; color: var(--xj-ink-muted, #64748B);
    }
}

/* New markup that only the phone layout uses. */
@media (min-width: 821px) {
    .module-repairs .xj-repair-thumb { display: none; }
}
