/* Responsive presentation only. Data, permissions and desktop branding stay unchanged. */
#schedulingCalendarModal > .scheduling-calendar-card { grid-template-rows: minmax(0, 1fr); }
.scheduling-calendar-card .scheduling-calendar-toolbar {
  grid-template-areas: "search week tools";
  grid-template-columns: minmax(160px, 380px) minmax(0, 1fr) max-content;
  padding-right: 0;
}
.scheduling-calendar-card .scheduling-calendar-global-search-wrap {
  grid-area: search;
  position: relative;
  max-width: none;
  width: 100%;
}
.scheduling-calendar-card .scheduling-calendar-week-controls { grid-area: week; }
.scheduling-calendar-tools {
  grid-area: tools;
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 6px;
}
#schedulingCalendarClose { position: relative; top: auto; right: auto; }
#schedulingCalendarModal .scheduling-calendar-grid-wrap { min-width: 0; }
:is(#schedulingColumnSettingsModal, #schedulingResultsModal, #schedulingLogModal).is-over-calendar { z-index: 1001; }
@media (max-width: 700px) {
  #schedulingCalendarModal .scheduling-calendar-corner { left: auto; }
  #schedulingCalendarModal .scheduling-calendar-technician { position: relative; left: auto; }
}
@media (max-width: 1180px) {
  .scheduling-calendar-card .scheduling-calendar-toolbar {
    grid-template-areas: "search tools" "week week";
    grid-template-columns: minmax(0, 1fr) max-content;
  }
}
@media (max-width: 400px) {
  .scheduling-calendar-card .scheduling-calendar-toolbar {
    grid-template-areas: "tools tools" "search search" "week week";
  }
}
.header-reports-group { display: contents; }
#clientsTable td:nth-child(8) .status-badge { max-width: 100%; }
#tab-scheduling .scheduling-table td > * { max-width: 100%; min-width: 0; }

.estimate-select-menu.mobile-viewport-dropdown {
  position: fixed !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  z-index: 5200;
  box-sizing: border-box;
}
.estimate-select-menu.mobile-viewport-dropdown .estimate-select-option { min-height: 40px; }

@media (max-width: 1200px) {
  html { height: 100%; min-height: 0; overflow: hidden; }
  body { height: 100dvh; min-height: 0; overflow: hidden; }
  .topbar, .tabs { position: static; flex: 0 0 auto; }
  main {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    margin: 8px 8px max(8px, env(safe-area-inset-bottom));
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    scrollbar-gutter: stable;
  }
  main > :is(#tab-estimate, #tab-clients, #tab-suppliers, #tab-parts, #tab-history, #tab-scheduling) {
    height: auto; max-height: none; min-height: 0; overflow: visible; padding-right: 0; scrollbar-gutter: auto;
  }
  main > .tab-panel.active { grid-template-rows: auto; }
  main .panel { min-width: 0; }
  main > .tab-panel > .panel,
  main > .tab-panel > .clients-layout > .panel,
  #tab-estimate .estimate-left > .panel,
  #tab-estimate .estimate-right { border: 0; border-radius: 0; }
  #tab-estimate .estimate-right, #tab-parts > .parts-table-panel { border-top: 1px solid var(--line); }
  main > #tab-scheduling { height: 100%; grid-template-rows: minmax(0, 1fr); }
  #tab-scheduling > .scheduling-panel { display: flex; flex-direction: column; height: 100%; overflow: visible; }
  #tab-scheduling :is(.scheduling-toolbar, .scheduling-data-warning) { flex: 0 0 auto; }
  #tab-scheduling .scheduling-table-wrap.active { flex: 1 0 280px; height: auto; min-height: 280px; }
  #tab-history > .panel { height: 100%; overflow: visible; }
  main > #tab-history { height: 100%; grid-template-rows: minmax(0, 1fr); }
  #tab-history .history-toolbar { flex: 0 0 auto; }
  #tab-history .history-table-frame { flex: 1 1 auto; height: auto; min-height: 280px; }
  :is(#tab-clients, #tab-suppliers) .clients-layout { height: auto; overflow: visible; }
  :is(#tab-clients, #tab-suppliers) .clients-layout > .clients-table-panel,
  #tab-suppliers > .suppliers-table-panel { height: auto; max-height: none; overflow: visible; }
  :is(#tab-clients, #tab-suppliers) .clients-layout > .clients-table-panel .table-scroll,
  #tab-suppliers > .suppliers-table-panel .table-scroll,
  #tab-parts > .parts-table-panel .table-scroll {
    flex: 0 0 auto;
    height: clamp(280px, 55dvh, 520px);
    max-height: none;
    overflow: auto !important;
    scrollbar-gutter: auto;
  }
  #tab-parts > .parts-control-panel, #tab-parts > .parts-table-panel {
    min-height: 0; height: auto; max-height: none; overflow: visible;
  }
  #tab-parts > .parts-control-panel .parts-entries-scroll { max-height: 45dvh; overflow-x: auto !important; overflow-y: scroll !important; }
  #partsTable { min-width: 1250px; }
  #tab-suppliers #suppliersTable { min-width: 880px; }
  #suppliersTable col.suppliers-col-id { width: 78px; }
  #suppliersTable col.suppliers-col-name { width: 168px; }
  #suppliersTable col.suppliers-col-cif { width: 102px; }
  #suppliersTable col.suppliers-col-country { width: 44px; }
  #suppliersTable col.suppliers-col-regcom { width: 90px; }
  #suppliersTable col.suppliers-col-address { width: 116px; }
  #suppliersTable col.suppliers-col-email { width: 120px; }
  #suppliersTable col.suppliers-col-phone { width: 102px; }
  #suppliersTable col.suppliers-col-delete { width: 58px; }
  #tab-suppliers #suppliersTable thead th { display: table-cell; }
  main .table-pagination { flex: 0 0 auto; flex-wrap: wrap; gap: 10px; padding-block: 10px; }
  main .table-pagination-actions { flex: 0 0 auto; margin-left: auto; }
  main .parts-pagination-info { flex-wrap: wrap; gap: 6px 14px; }
  #tab-estimate .estimate-layout,
  #tab-estimate .estimate-left,
  #tab-estimate .estimate-left > .panel,
  #tab-estimate .estimate-right { height: auto; max-height: none; overflow: visible; }
  #tab-estimate .sum-box { min-height: 76px; }
  #tab-estimate .sum-box-label { white-space: normal; overflow-wrap: anywhere; }
  #tab-estimate .line-table-scroll { max-height: 55dvh; overflow: auto; }
}

@media (max-width: 900px) {
  .topbar { padding: 8px; gap: 8px; }
  .brand-wrap { margin-left: 0; align-items: center; justify-content: center; }
  .brand-lightning { position: static; transform: none; flex: 0 0 30px; }
  .brand-wrap { gap: 14px; }
  .header-pdf-logo-frame { flex: 0 1 auto; min-width: 0; }
  .top-actions { flex-wrap: nowrap; gap: 6px; justify-content: center; }
  .top-actions:has(.app-find-bar:not(.hidden)) { flex-wrap: wrap; }
  .top-actions .app-find-bar { flex-basis: 100%; max-width: none; }
  .tabs { padding: 8px; gap: 8px; }
  .tabs-button-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .tabs-button-row > .tab { min-width: 0; padding-inline: 6px; justify-content: center; }
}

@media (max-width: 560px) {
  .top-actions { gap: 4px; margin-inline: auto; }
  .top-actions > .ghost { height: 34px; min-height: 34px; font-size: 13px; padding-inline: 6px; }
}

@media (max-width: 360px) {
  .tabs-button-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Filters fill their line; command groups wrap only when their content needs it. */
#tab-scheduling > .scheduling-panel > .scheduling-toolbar :is(.scheduling-search-field, .scheduling-personal-field) {
  flex: 1 1 160px;
  min-width: 120px;
  max-width: none;
  width: auto;
}
#tab-scheduling > .scheduling-panel > .scheduling-toolbar .scheduling-date-pair {
  flex: 1 1 auto;
  max-width: 100%;
}
#tab-scheduling > .scheduling-panel > .scheduling-toolbar .scheduling-date-pair .scheduling-inline-filter {
  flex: 1 1 128px;
  width: 128px;
  min-width: 0;
  max-width: none;
}
.scheduling-command-bar {
  display: flex;
  flex: 0 1 max-content;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}

#tab-scheduling .scheduling-command-bar.is-second-row {
  flex-grow: 1;
}

#tab-scheduling > .scheduling-panel > .scheduling-toolbar .scheduling-command-bar.is-second-row .scheduling-view-tabs {
  flex: 0 1 auto;
}

#tab-scheduling > .scheduling-panel > .scheduling-toolbar .scheduling-command-bar.is-second-row .scheduling-actions {
  margin-left: auto;
}
#tab-scheduling > .scheduling-panel > .scheduling-toolbar .scheduling-view-tabs {
  flex: 1 1 auto;
}
#tab-scheduling > .scheduling-panel > .scheduling-toolbar .scheduling-view-tabs > .scheduling-view-tab {
  flex: 1 1 0;
  min-width: fit-content;
  max-width: none;
  padding-inline: 12px;
}
#tab-scheduling > .scheduling-panel > .scheduling-toolbar .scheduling-actions {
  flex: 0 1 auto;
  max-width: 100%;
  margin-left: 0;
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
  scrollbar-width: none;
  scrollbar-gutter: auto;
}
#tab-scheduling .scheduling-toolbar .scheduling-actions::-webkit-scrollbar { display: none; }
#tab-scheduling .scheduling-toolbar .scheduling-actions > button { flex-shrink: 0; }

#tab-estimate .estimate-right { container: estimate-summary / inline-size; }
#tab-estimate .summary { grid-template-columns: repeat(5, minmax(0, 1fr)); }
#tab-estimate .summary.summary-no-vat { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@container estimate-summary (max-width: 680px) {
  #tab-estimate .summary,
  #tab-estimate .summary.summary-no-vat { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  #tab-estimate .summary > .sum-box { grid-column: span 2; }
  #tab-estimate .summary > .sum-box:nth-child(n + 4) { grid-column: span 3; }
  #tab-estimate .summary.summary-no-vat > .sum-box:nth-child(4) { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  #tab-history .history-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #tab-history .history-toolbar > .search-field { grid-column: 1; grid-row: 1; }
  #tab-history .history-toolbar > .history-user-filter { grid-column: 2; grid-row: 1; }
  #tab-history .history-filter-divider { display: none; }
  #tab-history .history-toolbar > .history-target { grid-column: 1 / -1; grid-row: 2; padding: 0; }
}
@media (max-width: 400px) {
  #tab-history .history-toolbar { grid-template-columns: minmax(0, 1fr); }
  #tab-history .history-toolbar > :is(.search-field, .history-user-filter, .history-target) { grid-column: 1; grid-row: auto; }
}
@container estimate-summary (max-width: 420px) {
  #tab-estimate .summary-top .sum-box { min-height: 96px; }
  #tab-estimate .summary-top .sum-box:not(.vat-total-box) .sum-box-label { padding-right: 0; }
  #tab-estimate .summary-top .sum-box-label { align-items: start; gap: 4px; }
  #tab-estimate .summary-top .sum-box-label span[data-i18n] { white-space: normal; overflow-wrap: anywhere; }
  #tab-estimate .summary-number-fields { position: static; order: 3; justify-self: end; }
  #tab-estimate .summary-top .total-field { order: 2; padding-inline: 0; }
  #tab-estimate .summary-top .sum-box-discount { position: static; order: 4; }
}
@media (max-width: 700px) {
  #tab-scheduling > .scheduling-panel > .scheduling-toolbar :is(.scheduling-search-field, .scheduling-personal-field) {
    flex-basis: 110px;
    min-width: 100px;
    max-width: none;
  }
  #tab-scheduling > .scheduling-panel > .scheduling-toolbar .scheduling-date-pair .scheduling-inline-filter {
    flex-basis: calc(104px + var(--app-text-size-offset, 0px) * 6);
    width: calc(104px + var(--app-text-size-offset, 0px) * 6);
  }
  #tab-scheduling > .scheduling-panel > .scheduling-toolbar .scheduling-actions {
    justify-content: flex-start;
    margin-left: 0;
  }
}
