/*
 * Mobile-first layer for the existing vanilla Web app.
 * Keep this separate from style.css so phone/tablet behavior stays easy to audit.
 */

.mobile-record-list { display: none; }
.products-refresh { display: none; }

.workflow-toggle {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  padding: 11px 15px;
  border: 1px solid var(--line2);
  border-radius: 13px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--sh);
  -webkit-tap-highlight-color: transparent;
}
.workflow-toggle-copy { flex: 1; min-width: 0; }
.workflow-toggle-copy b { display: block; font-size: 12.5px; font-weight: 650; }
.workflow-toggle-copy small {
  display: block;
  margin-top: 1px;
  color: var(--ink3);
  font-size: 11.5px;
  line-height: 1.45;
}
.workflow-toggle-action { color: var(--red); font-size: 12px; font-weight: 600; }
.workflow-toggle > .i { color: var(--ink3); transition: transform .18s ease; }
.workflow-toggle[aria-expanded="true"] > .i { transform: rotate(90deg); }

@media (min-width: 781px) {
  .view { margin-left: auto; margin-right: auto; }
  .head-in { max-width: 1328px; margin-left: auto; margin-right: auto; }
}

@media (max-width: 780px) {
  html { scroll-padding-bottom: calc(86px + env(safe-area-inset-bottom)); }

  /* Respect notches when viewport-fit=cover is enabled. */
  .head { padding-top: env(safe-area-inset-top); }
  .head-in { min-height: 56px; height: auto; }
  .view {
    min-height: calc(100dvh - 56px);
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .tabbar {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .tabbar button { min-width: 0; padding-left: 1px; padding-right: 1px; }
  .tabbar button.on::before {
    content: "";
    position: absolute;
    top: 0;
    width: 24px;
    height: 2px;
    border-radius: 0 0 3px 3px;
    background: var(--red);
  }
  .tabbar button:active { transform: scale(.96); }
  .tabbar button > span:not(.bd) {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Keep the admin refresh reachable without letting it squeeze the title. */
  .admin-head-refresh {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
  }
  .admin-head-refresh .admin-refresh-label { display: none; }

  /* Bring the next actionable task above the fold; keep the process explainer available but quiet. */
  .hero { gap: 9px 12px; }
  .hero > div:first-child { flex: 1 1 130px; min-width: 0; }
  .hero .div, .hero .sp { display: none; }
  .hero > .btn {
    order: 2;
    flex: 0 0 auto;
    min-height: 44px;
    padding-left: 10px;
    padding-right: 10px;
  }
  .hero .mini {
    order: 3;
    flex: 0 0 100%;
    width: auto;
    gap: 20px;
    padding-top: 9px;
    border-top: 1px solid var(--line);
  }
  .workflow-toggle { margin-bottom: 10px; }
  #ovStats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #ovStats .stat:first-child { display: none; }

  .products-refresh { display: inline-flex; min-height: 44px; }
  .products-summary { display: none; }

  /* Dense desktop tables become scan-friendly, touch-sized records on phones. */
  .desktop-record-list { display: none !important; }
  .mobile-record-list { display: grid; gap: 10px; }
  .record-card {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--line2);
    border-radius: 14px;
    background: #fff;
    box-shadow: var(--sh);
  }
  .record-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
  }
  .record-title {
    min-width: 0;
    color: var(--ink);
    font-size: 14px;
    font-weight: 650;
    line-height: 1.45;
    overflow-wrap: anywhere;
  }
  .record-subtitle {
    display: block;
    margin-top: 2px;
    color: var(--ink3);
    font-size: 11.5px;
    font-weight: 400;
  }
  .record-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
    padding: 11px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }
  .record-field { min-width: 0; }
  .record-field > span {
    display: block;
    margin-bottom: 2px;
    color: var(--ink3);
    font-size: 11px;
  }
  .record-field > b {
    display: block;
    min-width: 0;
    color: var(--ink2);
    font-size: 12.5px;
    font-weight: 600;
    overflow-wrap: anywhere;
  }
  .record-note, .record-dates {
    margin-top: 10px;
    color: var(--ink3);
    font-size: 11.5px;
    line-height: 1.6;
    overflow-wrap: anywhere;
  }
  .record-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
  }
  .record-actions > .btn {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .record-actions > .btn.wide { grid-column: 1 / -1; }

  .record-card details { margin-top: 10px; color: var(--ink2); }
  .record-card details summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    color: var(--blue);
    cursor: pointer;
  }
  .record-card .record-events {
    display: grid;
    gap: 5px;
    padding: 8px 10px;
    border-radius: 10px;
    background: #f7f8fa;
    font-size: 11.5px;
    overflow-wrap: anywhere;
  }

  input, select, textarea { min-height: 46px; border-radius: 11px; }
  .pcard .stock {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .pcard:active { transform: scale(.985); }
}

@media (max-width: 360px) {
  .record-card { padding: 12px; }
  .tabbar button { font-size: 9.5px; }
}
