/* Responsive layer for the production, delivery and materials boards.
   Loaded after styles.css / blue-theme.css / operations-board.css. Only the
   rules inside these breakpoints change the desktop layout; at 1101px and
   wider every board keeps its existing sizes and spacing. */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Keep the fixed-width production table readable on smaller laptops by
   letting the table area scroll instead of squeezing all ten columns. */
@media (max-width: 1100px) {
  body:not(.operations-board) .table-scroll {
    overflow: auto;
  }

  body:not(.operations-board) table {
    min-width: 1200px;
  }

  body:not(.operations-board) .kpi-line {
    --metric-gap: 4px;
  }

  /* 生产看板：窄屏下统计栏三列一行。 */
  body:not(.operations-board) .kpi-band {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body:not(.operations-board) .kpi-item {
    border-bottom: 0;
  }

  body:not(.operations-board) .kpi-item:nth-child(3n) {
    border-right: 0;
  }

  /* Give the two-line production date enough room at the smaller fixed table width. */
  body:not(.operations-board) .col-date {
    width: 7%;
  }

  body:not(.operations-board) .col-remark {
    width: 22.5%;
  }

  .operations-board .operations-toolbar {
    display: grid;
    grid-template-columns: 200px 130px minmax(150px, 1fr) minmax(0, max-content);
    align-items: center;
    gap: 10px;
    height: auto;
    min-height: clamp(48px, 4.44vh, 96px);
    padding: 6px clamp(8px, 0.6vw, 23px);
  }

  .operations-board[data-board="materials"] .operations-toolbar {
    grid-template-columns: 225px 225px minmax(150px, 1fr) minmax(0, max-content);
  }

  .operations-board .operations-toolbar > * + * {
    margin-left: 0;
  }

  .operations-board .operations-toolbar .field-group {
    width: auto;
    min-width: 0;
  }

  .operations-board .operations-date {
    width: 200px;
  }

  .operations-board[data-board="materials"] .operations-date {
    width: 180px;
  }

  .operations-board .operations-warehouse,
  .operations-board .operations-inwarehouse {
    width: 225px;
  }

  .operations-board .operations-toolbar .operations-search {
    width: auto;
    max-width: none;
    min-width: 150px;
  }

  .operations-board .operations-list-summary {
    flex: 0 1 auto;
    min-width: 0;
    margin-top: 0;
    justify-content: flex-end;
    justify-self: end;
    overflow: hidden;
    font-size: 14px;
  }

  .operations-board #listDescription {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .operations-board #billCount {
    flex: 0 0 auto;
  }
}

/* The summary stays on the filter row at 1024px and only moves below the
   controls when the available width can no longer hold both. The materials
   page has one extra control, so it reflows earlier than delivery. */
@media (max-width: 940px) {
  .operations-board[data-board="materials"] .operations-toolbar {
    grid-template-columns: 225px 225px minmax(150px, 1fr);
  }

  .operations-board[data-board="materials"] .operations-list-summary {
    grid-column: 1 / -1;
    justify-content: flex-start;
    justify-self: stretch;
    width: 100%;
    margin-top: 2px;
  }
}

@media (max-width: 800px) {
  .operations-board .operations-toolbar {
    grid-template-columns: 200px minmax(150px, 1fr);
  }

  .operations-board .operations-list-summary {
    grid-column: 1 / -1;
    justify-content: flex-start;
    justify-self: stretch;
    width: 100%;
    margin-top: 2px;
  }
}

/* Tablet and phone widths. Each statistic keeps its label, value and unit
   on one line; the blocks reflow around them instead of clipping. */
@media (max-width: 900px) {
  html.kiosk-mode.projection-mode h1 {
    font-size: clamp(18px, 4.4vw, 32px);
  }

  .brand-block,
  html.kiosk-mode .brand-block {
    max-width: 100%;
    overflow: hidden;
  }

  h1,
  html.kiosk-mode h1 {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-update {
    font-size: 11px;
  }

  #lastUpdated {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .operations-board .table-scroll,
  html.kiosk-mode .table-scroll {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Production board: three statistics in one row on tablets. */
  body:not(.operations-board) .kpi-band {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body:not(.operations-board) .kpi-item {
    min-height: clamp(64px, 9vw, 88px);
    padding: 8px 6px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  body:not(.operations-board) .kpi-item:nth-child(3n) {
    border-right: 0;
  }

  body:not(.operations-board) .completion-kpi {
    grid-column: auto;
    border-top: 0;
  }

  body:not(.operations-board) .kpi-line {
    flex-wrap: nowrap;
    --metric-gap: 6px;
  }

  body:not(.operations-board) .kpi-item p {
    width: auto;
    padding-left: 0;
    text-align: center;
    font-size: clamp(11px, 1.5vw, 14px);
  }

  body:not(.operations-board) .kpi-item .kpi-icon {
    position: static;
    display: inline-block;
    width: clamp(14px, 1.8vw, 20px);
    height: clamp(14px, 1.8vw, 20px);
    margin-right: 4px;
    vertical-align: middle;
    transform: none;
  }

  body:not(.operations-board) .kpi-item strong,
  body:not(.operations-board) .day-meta-value {
    font-size: clamp(20px, 2.8vw, 26px);
  }

  body:not(.operations-board) .kpi-item .unit {
    font-size: clamp(10px, 1.2vw, 12px);
  }

  body:not(.operations-board) .metric-note {
    font-size: 10px;
    line-height: 1.2;
    white-space: normal;
  }

  /* Delivery and materials boards: three compact statistics on one row.
     body.operations-board matches the specificity of the kiosk selectors in
     blue-theme.css, so these mobile sizes win over the fixed display sizes. */
  body.operations-board .kpi-band {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body.operations-board .kpi-item {
    min-height: clamp(64px, 9vw, 96px);
    padding: 6px;
    border-right: 1px solid var(--line);
  }

  body.operations-board .kpi-item:nth-child(2) {
    border-right: 1px solid var(--line);
  }

  body.operations-board .kpi-item:last-child {
    border-right: 0;
  }

  body.operations-board .kpi-line {
    flex-wrap: nowrap;
    --metric-gap: 6px;
  }

  html.kiosk-mode body.operations-board .kpi-item p {
    width: auto;
    padding-left: 0;
    text-align: left;
    font-size: clamp(11px, 1.55vw, 16px);
  }

  body.operations-board .kpi-item .kpi-icon {
    position: static;
    display: inline-block;
    width: clamp(14px, 2vw, 24px);
    height: clamp(14px, 2vw, 24px);
    margin-right: 4px;
    vertical-align: middle;
    transform: none;
  }

  html.kiosk-mode body.operations-board .kpi-item strong {
    font-size: clamp(18px, 3vw, 28px);
  }

  html.kiosk-mode body.operations-board .kpi-item .unit {
    font-size: clamp(10px, 1.4vw, 14px);
  }

  html.kiosk-mode body.operations-board .metric-note {
    font-size: 10px;
    line-height: 1.15;
    white-space: normal;
  }

  /* Keep the record count and pager on one footer line; the rotation hint
     is secondary information and is dropped on narrow screens. */
  .table-footer,
  html.kiosk-mode .table-footer {
    flex-wrap: nowrap;
    --footer-gap: 8px;
  }

  .table-footer .rotation-status {
    display: none;
  }

  #recordRange {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Phones, and short landscape windows: allow the page itself to scroll so
   controls and the statistics line never disappear behind a fixed shell. */
@media (max-width: 680px), (max-width: 900px) and (max-height: 520px) {
  /* 窄屏页签：名称、日期、单数保持一行，单数靠右且沿用 KPI 字号。 */
  .day-tab,
  html.kiosk-mode .day-tab {
    padding: 8px 10px;
    column-gap: 6px;
  }

  .day-name,
  html.kiosk-mode .day-name {
    font-size: 12px;
  }

  .day-date,
  html.kiosk-mode .day-date {
    font-size: 13px;
  }

  .day-meta,
  html.kiosk-mode .day-meta {
    font-size: 10px;
  }

  .day-meta-value,
  html.kiosk-mode .day-meta-value {
    font-size: 20px;
  }

  html,
  body,
  html.kiosk-mode,
  html.kiosk-mode body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .board-shell,
  html.kiosk-mode .board-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .topbar,
  html.kiosk-mode .topbar {
    min-height: 64px;
    padding: 4px 12px;
    gap: 6px;
  }

  h1,
  html.kiosk-mode h1 {
    font-size: clamp(18px, 4.8vw, 24px);
  }

  .topbar-status,
  html.kiosk-mode .topbar-status {
    flex-wrap: nowrap;
  }

  .topbar-update {
    font-size: 10px;
  }

  #lastUpdated {
    max-width: 58vw;
  }

  .auto-refresh {
    display: none;
  }

  .table-section,
  html.kiosk-mode .table-section {
    flex: 0 0 auto;
    min-height: 0;
  }

  .table-scroll,
  html.kiosk-mode .table-scroll {
    flex: 0 0 auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  body:not(.operations-board) {
    --row-height: clamp(56px, 8vh, 76px);
  }

  body:not(.operations-board) .table-scroll {
    height: clamp(240px, 38vh, 420px);
  }

  .operations-board {
    --row-height: clamp(44px, 7vh, 66px);
  }

  .operations-board .table-scroll {
    height: clamp(300px, 52vh, 560px);
  }

  .table-footer,
  html.kiosk-mode .table-footer {
    flex-wrap: nowrap;
    min-height: 40px;
    padding: 5px 8px;
    font-size: 12px;
    --footer-gap: 8px;
  }

  .table-footer .rotation-status {
    display: none;
  }

  #recordRange {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .pagination {
    flex: 0 0 auto;
    --page-gap: 6px;
  }

  .pagination .icon-button {
    width: 30px;
    height: 30px;
  }

  /* Production board: two statistics per row on a phone. */
  body:not(.operations-board) .kpi-band {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body:not(.operations-board) .kpi-item {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  body:not(.operations-board) .kpi-item:nth-child(2n) {
    border-right: 0;
  }

  body:not(.operations-board) .kpi-item:last-child {
    border-bottom: 0;
  }

  .operations-board .operations-toolbar,
  .operations-board[data-board="materials"] .operations-toolbar {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 8px 10px;
  }

  .operations-board[data-board="materials"] .operations-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .operations-board[data-board="materials"] .operations-search,
  .operations-board[data-board="materials"] .operations-list-summary {
    grid-column: 1 / -1;
  }

  .operations-board .operations-toolbar .field-group,
  .operations-board .operations-date,
  .operations-board .operations-warehouse,
  .operations-board .operations-inwarehouse,
  .operations-board .operations-toolbar .operations-search {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .operations-board .operations-toolbar .field-group > span {
    margin-bottom: 4px;
    font-size: 12px;
  }

  .operations-board .operations-toolbar .field-group > * + * {
    margin-top: 0;
    margin-left: 0;
  }

  .operations-board .operations-toolbar input,
  .operations-board .operations-toolbar select {
    height: 36px;
    font-size: 14px;
  }

  .operations-board .operations-toolbar input[type="date"] {
    min-width: 0;
  }

  .operations-board .operations-list-summary {
    margin-top: 2px;
    font-size: 12px;
  }

  .operations-board .operations-search .input-with-icon > svg {
    left: 8px;
    width: 16px;
    height: 16px;
  }

  .operations-board .operations-search input {
    padding-left: 30px;
    padding-right: 30px;
  }

  .operations-board .operations-search .clear-search {
    right: 3px;
    width: 28px;
    height: 28px;
  }
}

/* On the narrowest phones show each delivery/materials statistic as its own
   row: label left, value right, both on the same line. */
@media (max-width: 520px) {
  body.operations-board .kpi-band {
    grid-template-columns: 1fr;
  }

  body.operations-board .kpi-item {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    min-height: 0;
    padding: 6px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  body.operations-board .kpi-item:last-child {
    border-bottom: 0;
  }

  body.operations-board .kpi-line {
    width: 100%;
    justify-content: space-between;
  }

  html.kiosk-mode body.operations-board .kpi-item p {
    font-size: 13px;
  }

  html.kiosk-mode body.operations-board .kpi-item strong {
    font-size: 22px;
  }

  html.kiosk-mode body.operations-board .metric-note {
    flex: 1 0 100%;
    margin-top: 2px;
    font-size: 10px;
  }
}

@media (max-width: 480px) {
  .topbar-update {
    font-size: 9px;
  }
}

@media (max-width: 360px) {
  h1,
  html.kiosk-mode h1 {
    font-size: 16px;
  }

  body:not(.operations-board) .kpi-item p {
    font-size: 10px;
  }

  body:not(.operations-board) .kpi-item strong,
  body:not(.operations-board) .day-meta-value {
    font-size: 18px;
  }

  body:not(.operations-board) .kpi-item .kpi-icon {
    width: 13px;
    height: 13px;
  }

  .operations-board .operations-list-summary {
    font-size: 11px;
  }

  .operations-board[data-board="materials"] .operations-toolbar {
    grid-template-columns: 1fr;
  }

  .day-tab,
  html.kiosk-mode .day-tab {
    min-height: 56px;
    padding: 8px;
    column-gap: 6px;
  }

  .day-name {
    font-size: 12px;
  }

  .day-date,
  html.kiosk-mode .day-date {
    font-size: 14px;
  }

  /* 320px 级别只保留月/日，给右侧单数留出空间。 */
  .day-date-week {
    display: none;
  }

  .day-meta,
  html.kiosk-mode .day-meta {
    margin-top: 0;
    font-size: 10px;
  }
}

/* Short laptop windows keep the table usable without shrinking rows to an
   unreadable height: the page scrolls and the table keeps a stable height. */
@media (max-width: 1100px) and (max-height: 700px) {
  html,
  body,
  html.kiosk-mode,
  html.kiosk-mode body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .board-shell,
  html.kiosk-mode .board-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .table-section,
  html.kiosk-mode .table-section {
    flex: 0 0 auto;
    min-height: 0;
  }

  .table-scroll,
  html.kiosk-mode .table-scroll {
    flex: 0 0 auto;
    height: clamp(420px, 68vh, 620px);
    overflow: auto;
  }

  .operations-board {
    --row-height: 44px;
  }

  body:not(.operations-board) {
    --row-height: 56px;
  }
}

/* 生产看板：五项指标在任意宽度下都不给最后一项画右边框（末行不满时也一样）。 */
body:not(.operations-board) .kpi-item:last-child { border-right: 0; }


