/* Final UI quality layer.
 * Loaded after the main design system so small responsive and compatibility
 * corrections can be shared across old and newly migrated screens. */

:root {
  /* A few older workspace styles still use the historic medium token. */
  --sm-radius-md: var(--sm-radius);
  --sm-touch-target: 44px;
}

.sm-page-description,
.page-header > div:first-child > p.muted,
.sm-settings-content .section-head small,
.sm-settings-content .settings-subcard-head p,
.sm-settings-content .section-body > p.muted:first-child,
.dashboard-layout-edit-actions > .muted,
.dashboard-widget[data-dashboard-id="staff"] .section-head small,
.dashboard-widget[data-dashboard-id="reports"] .section-body > p.muted {
  display: none !important;
}

/* Generic form styles are loaded after the shell rules and otherwise steal the
   left padding from the topbar search. Keep a dedicated icon gutter. */
.sm-topbar .sm-global-search input {
  padding-left: 44px !important;
  padding-right: 82px !important;
}

/* Defensive sizing: long customer names, serial numbers and imported article
   descriptions must never widen the page beyond the viewport. */
.sm-workspace,
.sm-main,
.sm-content,
.sm-tab-panel,
.card,
.sm-card,
.card-body,
.sm-card-body,
.sm-object-hero > *,
.sm-page-header > *,
.page-header > *,
.sm-card-header > *,
.sm-data-item,
.sm-list-copy,
.sm-asset-list-main,
.input-group,
.input-group > *,
.row > * {
  min-width: 0;
}

.sm-content,
.sm-card,
.card,
.sm-object-hero,
.sm-asset-summary-cell,
.sm-data-item {
  overflow-wrap: anywhere;
}

img,
video,
canvas,
svg:not(.ti) {
  max-width: 100%;
}

.sm-table-wrap,
.table-wrap,
.table-responsive,
.production-table-scroll,
.tabs,
.sm-tabs,
.sm-settings-nav {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
}

/* Breadcrumbs are useful on desktop, but may contain long customer/site names.
   Allow them to wrap instead of forcing horizontal page scrolling. */
.sm-breadcrumb {
  max-width: 100%;
  flex-wrap: wrap;
  row-gap: .2rem;
}
.sm-breadcrumb a,
.sm-breadcrumb strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Sticky save bars stay above gesture/navigation areas on modern phones. */
.sm-form-actions {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* Dialog content must remain reachable when the mobile browser chrome changes
   height while scrolling or when the keyboard opens. */
dialog,
dialog.sm-dialog,
dialog.sm-qr-dialog,
.qr-scanner-dialog,
.planning-edit-dialog {
  max-width: calc(100vw - 16px) !important;
  max-height: calc(100dvh - 16px) !important;
}

/* Component type plates contain exactly the data a technician needs in the
   field. Do not truncate model/serial/location on narrow screens. */
.sm-component-node > summary > span {
  min-width: 0;
}

@media (max-width: 767.98px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body.sm-body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .sm-content {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(48px, calc(28px + env(safe-area-inset-bottom)));
  }

  .sm-topbar {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .sm-topbar .sm-global-search {
    min-width: 0;
  }
  .sm-topbar .sm-global-search input {
    padding-left: 42px !important;
    padding-right: 12px !important;
  }

  /* Avoid iOS/browser zoom and make forms easier to use with gloves. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select,
  textarea,
  .form-control,
  .form-select {
    min-height: var(--sm-touch-target);
    font-size: 16px;
  }

  .btn,
  .navbutton,
  .button-link,
  .menu-action,
  .quick-action,
  .iconbutton,
  summary.sm-details-summary {
    min-height: var(--sm-touch-target);
  }

  .sm-page-actions,
  .page-actions,
  .sm-object-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }
  .sm-page-actions > *,
  .page-actions > *,
  .sm-object-actions > * {
    width: 100%;
    min-width: 0;
    justify-content: center;
    text-align: center;
    white-space: normal;
    line-height: 1.25;
  }
  .sm-page-actions > :only-child,
  .page-actions > :only-child,
  .sm-object-actions > :only-child {
    grid-column: 1 / -1;
  }

  .sm-card-header-actions {
    width: 100%;
    align-items: stretch;
  }
  .sm-card-header-actions > .btn,
  .sm-card-header-actions > .navbutton {
    width: 100%;
    justify-content: center;
    white-space: normal;
  }

  .actions {
    width: 100%;
    align-items: stretch;
  }
  .actions > .btn,
  .actions > .navbutton,
  .actions > .button-link {
    flex: 1 1 180px;
    justify-content: center;
    white-space: normal;
  }

  .sm-component-node {
    margin-left: 8px;
  }
  .sm-component-node::before {
    display: none;
  }
  .sm-component-node > summary {
    min-height: 56px;
    align-items: flex-start;
  }
  .sm-component-node > summary small {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.4;
  }
  .sm-component-body {
    padding: 12px;
  }

  .sm-asset-list-item {
    gap: .6rem;
  }
  .sm-asset-list-item > .ti:last-child {
    align-self: center;
  }

  .sm-inline-form,
  .sm-inline-form .form-select,
  .sm-status-select {
    width: 100%;
    min-width: 0;
  }

  .list-group-item > span,
  .list-group-item > div {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .sm-form-actions {
    bottom: env(safe-area-inset-bottom);
    flex-wrap: wrap;
  }
  .sm-form-actions > .btn,
  .sm-form-actions > .navbutton,
  .sm-form-actions > .button-link {
    flex: 1 1 180px;
  }
}

@media (max-width: 480px) {
  .sm-system-metrics,
  .sm-customer-metrics,
  .dashboard-metrics,
  .sm-work-metrics {
    gap: 8px;
  }

  .metric-card {
    padding: 12px;
  }

  .tabs,
  .sm-tabs {
    margin-inline: -2px;
    scroll-snap-type: x proximity;
  }
  .tabs .tab-link,
  .sm-tabs .nav-link {
    min-height: var(--sm-touch-target);
    scroll-snap-align: start;
  }
}
