/* Hallmark · app-screen audit · custom SPOT IT responsive adaptation · copy: verbatim
   Critique: legacy landscape placements separated the location, capture and record panels.
   Scope: responsive app layouts; phone portrait styling and all wiring are preserved.
   Existing brand tokens, labels and app chrome take precedence over generic style gates. */

/* Shallow phone screens need a compact workbench, not the legacy three-track dashboard.
   Replit reference: bounded content, separate location and capture regions; existing brand tokens retained. */
@media (orientation: landscape) and (min-width: 35rem) and (max-width: 63.999rem) and (max-height: 37.5rem) {
  html:root body { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
  html:root .top-shell header { min-height: 44px; padding: var(--space-2) max(var(--space-4), env(safe-area-inset-right)) var(--space-2) max(var(--space-4), env(safe-area-inset-left)); }
  html:root .top-shell .header-logo { height: 28px; max-height: 28px; }
  html:root .capture-session-bar { margin: var(--space-3) auto; padding-inline: max(var(--space-4), env(safe-area-inset-left)); }
  html:root #inspection-view > main {
    display: grid;
    grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr);
    grid-template-rows: auto auto;
    grid-template-areas: "location capture" "recent capture";
    gap: var(--space-4);
    align-items: start;
    padding: 0 max(var(--space-4), env(safe-area-inset-right)) var(--space-4) max(var(--space-4), env(safe-area-inset-left));
    width: 100%;
    box-sizing: border-box;
  }
  html:root #inspection-view > main > #instrument-panel { grid-area: location; display: block; min-width: 0; min-height: 0; align-self: start; width: 100%; margin: 0; padding: 0; height: auto; }
  html:root #inspection-view #instrument-panel .instrument-head { padding: var(--space-4); }
  html:root #inspection-view #instrument-panel .kmvalue { font-size: 32px; }
  html:root #inspection-view #instrument-panel .instrument-foot { overflow-wrap: anywhere; }
  html:root #inspection-view > main > #defect-section { grid-area: capture; display: block; min-width: 0; margin: 0; }
  html:root #inspection-view #defect-section .defect-focus-bar { margin: 0 0 var(--space-3); gap: var(--space-2); }
  html:root #inspection-view #defect-section .defect-category { margin: 0 0 var(--space-4); min-width: 0; }
  html:root #inspection-view #defect-section .category-label { margin: 0 0 var(--space-2); }
  html:root #inspection-view > main > .lane-divider { display: none; }
  html:root #inspection-view > main > #log-host-inspection { grid-area: recent; min-width: 0; width: 100%; margin: 0; }
  html:root #inspection-view #log-host-inspection #log-register { width: 100%; margin: 0; }
  html:root .app-tab-bar { width: 100%; max-width: none; padding: var(--space-1) max(var(--space-4), env(safe-area-inset-right)) calc(var(--space-1) + env(safe-area-inset-bottom)) max(var(--space-4), env(safe-area-inset-left)); }
  html:root .app-tab-bar .app-tab-btn { min-height: 44px; flex-direction: row; gap: var(--space-2); padding: var(--space-2); }
  html:root .app-tab-bar .app-tab-btn svg { width: 20px; height: 20px; }
  html:root #log-view, html:root #team-view, html:root #settings-view { padding-inline: max(var(--space-4), env(safe-area-inset-left)); }
  html:root #map-view .map-filter-options { max-height: calc(100dvh - var(--app-header-h, 60px) - var(--app-nav-h, 56px) - 80px); overscroll-behavior: contain; }
  html:root #map-view .map-workspace-legend-body { max-height: 30dvh; }
  html:root dialog.inspection-detail-sheet, html:root #edit-modal .entry-sheet { max-height: calc(100dvh - 16px); }
}

/* Narrower rotated phones retain full-width tap targets instead of squeezing two panels. */
@media (orientation: landscape) and (min-width: 35rem) and (max-width: 43.749rem) and (max-height: 37.5rem) {
  html:root #inspection-view > main { grid-template-columns: minmax(0, 1fr); grid-template-areas: "location" "capture" "recent"; }
}

@media (min-width: 48rem) and (max-width: 63.999rem) and (orientation: portrait) {
  html:root #inspection-view > main,
  html:root .capture-session-bar,
  html:root #log-view,
  html:root #settings-view,
  html:root #team-view {
    width: calc(100% - 48px);
    max-width: 680px;
    margin-inline: auto;
  }

  html:root #inspection-view > main { padding-inline: 0; }
  html:root .capture-session-bar { padding-inline: 0; }
  html:root #log-view,
  html:root #settings-view,
  html:root #team-view { padding-inline: 0; }
  html:root .app-tab-bar { width: 680px; max-width: 100%; }
}

@media (min-width: 64rem) {
  :root {
    --wide-shell: 1440px;
    --wide-nav-space: 208px;
    --wide-space-5: 20px;
    --wide-gutter: 32px;
    --app-nav-h: 0px;
  }

  html:root body {
    box-sizing: border-box;
    max-width: var(--wide-shell);
    margin-inline: auto;
    padding-inline-start: var(--wide-nav-space);
    padding-bottom: 0;
  }

  html:root .top-shell { margin-inline-start: calc(-1 * var(--wide-nav-space)); }
  html:root .top-shell header { padding-inline: var(--space-6); min-height: 72px; }
  html:root .top-shell .header-logo { height: 32px; max-height: 32px; }

  html:root .app-tab-bar {
    top: calc(var(--app-header-h, 72px) + 24px);
    bottom: auto;
    left: max(24px, calc((100% - var(--wide-shell)) / 2 + 24px));
    transform: none;
    width: 160px;
    max-width: none;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
    padding: var(--space-2);
    border: 1px solid var(--ds-border);
    border-radius: var(--radius-card);
    background: var(--ds-card);
    box-shadow: none;
  }

  html:root .app-tab-bar .app-tab-btn {
    min-height: 52px;
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-control);
    font: 600 14px/1.3 var(--font-ui);
    color: var(--ds-fg-muted);
  }

  html:root .app-tab-bar .app-tab-btn svg { width: 20px; height: 20px; }
  html:root .app-tab-bar .app-tab-btn.active,
  html:root .app-tab-bar #settings-tab.active { background: var(--ds-muted); color: var(--ds-fg); }
  html:root .app-tab-bar .app-tab-btn.active::after {
    top: 14px;
    bottom: 14px;
    left: 0;
    right: auto;
    width: 3px;
    height: auto;
    background: var(--ds-primary);
  }
  html:root .app-tab-bar .app-tab-btn:focus-visible { outline: 2px solid var(--ds-secondary); outline-offset: 2px; }

  html:root .capture-session-bar {
    width: calc(100% - 2 * var(--wide-gutter));
    max-width: 1200px;
    margin: var(--space-6) auto var(--wide-space-5);
    padding: 0;
  }

  html:root #inspection-view > main {
    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, .38fr);
    grid-template-rows: auto auto;
    grid-template-areas: "location recent" "capture recent";
    align-items: start;
    gap: var(--space-6);
    width: calc(100% - 2 * var(--wide-gutter));
    max-width: 1200px;
    margin: 0 auto 40px;
    padding: 0;
  }

  html:root #inspection-view > main > #instrument-panel {
    grid-area: location;
    display: block;
    width: 100%;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    min-width: 0;
  }

  html:root #inspection-view #instrument-panel .instrument-head { padding: var(--wide-space-5) var(--wide-space-5) var(--space-1); }
  html:root #inspection-view #instrument-panel .instrument-main { padding-inline: var(--wide-space-5); }
  html:root #inspection-view #instrument-panel .kmvalue { font-size: 44px; }
  html:root #inspection-view #instrument-panel .instrument-foot { overflow-wrap: anywhere; }

  html:root #inspection-view > main > #defect-section {
    grid-area: capture;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--wide-space-5);
    margin: 0;
    min-width: 0;
  }
  html:root #inspection-view #defect-section .defect-focus-bar,
  html:root #inspection-view #defect-section .defect-gate { grid-column: 1 / -1; margin: 0; }
  html:root #inspection-view #defect-section .defect-category { min-width: 0; margin: 0; }
  html:root #inspection-view #defect-section .category-label { margin: 0 0 var(--space-3); }
  html:root #inspection-view > main > .lane-divider { display: none; }

  html:root #inspection-view > main > #log-host-inspection {
    grid-area: recent;
    position: sticky;
    top: calc(var(--app-header-h, 72px) + 24px);
    align-self: start;
    width: 100%;
    min-width: 0;
    margin: 0;
  }
  html:root #inspection-view #log-host-inspection #log-register { margin: 0; width: 100%; }
  html:root #inspection-view .inspection-record-list .log-empty { padding: var(--space-6) var(--space-4); }

  html:root #log-view,
  html:root #team-view,
  html:root #settings-view {
    box-sizing: border-box;
    width: calc(100% - 2 * var(--wide-gutter));
    max-width: 1200px;
    margin: var(--space-6) auto 40px;
    padding: 0;
    min-width: 0;
  }
  html:root #log-view .register-scopes { max-width: 600px; }
  html:root #log-view .register-search { max-width: 720px; }
  html:root #log-view .inspection-record-list { grid-template-columns: minmax(0, 1fr); }
  html:root #log-view .team-inspector-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  html:root #log-view .register-toolbar { align-items: center; }
  html:root #log-view .register-result { flex: 1; }
  html:root #log-view .register-filter-chips { flex-wrap: wrap; }

  html:root #team-view { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--wide-space-5); align-items: start; }
  html:root #team-view .team-heading,
  html:root #team-view .team-account-card,
  html:root #team-view [aria-labelledby="team-permissions-title"] { grid-column: 1 / -1; }
  html:root #team-view .team-heading { margin: 0; }
  html:root #team-view .team-card { margin: 0; padding: var(--wide-space-5); }

  html:root #settings-view #more-home { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-6); align-items: start; }
  html:root #settings-view #more-home > .ds-view-head { grid-column: 1 / -1; }
  html:root #settings-view .more-group { min-width: 0; margin: 0; }
  html:root #settings-view .more-screen { max-width: 820px; }

  html:root #map-view {
    position: fixed;
    top: var(--app-header-h, 72px);
    bottom: 0;
    left: max(var(--wide-nav-space), calc((100% - var(--wide-shell)) / 2 + var(--wide-nav-space)));
    right: max(0px, calc((100% - var(--wide-shell)) / 2));
    width: auto;
    max-width: none;
    height: auto;
    margin: 0;
    padding: 0;
    min-width: 0;
  }
}

@media (min-width: 80rem) {
  html:root #inspection-view > main > #defect-section:not(.focused) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  html:root #log-view .team-inspector-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
