/* Mobile-first refinements for the production floor workflow. */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.app-layout,
.workspace,
.panel,
.page-heading,
.batch-workspace,
.batch-form-card,
.auto-details-card,
.created-batch {
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 820px) {
  .topbar {
    height: 58px;
    padding: 0 12px;
  }

  .header-logo {
    width: 82px;
    height: 36px;
    flex-basis: 82px;
  }

  .header-logo img {
    width: 82px;
    height: 82px;
    transform: translateY(-23px);
  }

  .topbar .account {
    gap: 6px;
  }

  #logout {
    min-height: 42px;
    padding: 9px 12px;
  }

  .app-layout {
    min-height: calc(100dvh - 58px);
  }

  .workspace {
    width: 100%;
    padding: 24px 16px 36px;
  }

  .page-heading {
    margin-bottom: 20px;
  }

  .page-heading h1,
  .personal-heading h1 {
    font-size: clamp(28px, 8vw, 34px);
    line-height: 1.08;
  }

  .page-heading .muted,
  .personal-heading .muted,
  .intro {
    font-size: 15px;
    line-height: 1.5;
  }

  input,
  select,
  textarea,
  button,
  .button-link {
    min-height: 48px;
  }

  input,
  select,
  textarea {
    max-width: 100%;
    font-size: 16px;
  }

  .toolbar,
  .page-heading,
  .created-message {
    align-items: stretch;
  }

  .toolbar input,
  .toolbar select,
  .heading-actions,
  .heading-actions > * {
    width: 100%;
    max-width: none;
  }

  .table-wrap {
    max-width: 100%;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  dialog {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
  }

  .dialog-card {
    max-height: 92dvh;
    overflow-y: auto;
    padding: 22px 18px calc(20px + env(safe-area-inset-bottom));
  }

  .toast {
    left: 14px;
    right: 14px;
    bottom: 18px;
    text-align: center;
  }

  /* The employee has four daily actions, kept within thumb reach. */
  #app-view.employee-mode .sidebar {
    position: fixed;
    z-index: 50;
    inset: auto 0 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 2px;
    width: 100%;
    height: calc(66px + env(safe-area-inset-bottom));
    padding: 5px 4px env(safe-area-inset-bottom);
    overflow: visible;
    background: rgba(255, 255, 255, .98);
    border: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(23, 49, 38, .08);
  }

  #app-view.employee-mode .nav-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 100%;
    min-width: 0;
    min-height: 56px;
    margin: 0;
    padding: 4px 2px;
    border-radius: 10px;
    color: #596960;
    font-size: 11px;
    line-height: 1.05;
    text-align: center;
    white-space: normal;
  }

  #app-view.employee-mode .nav-button::before {
    display: block;
    color: currentColor;
    font-size: 20px;
    font-weight: 800;
    line-height: 1;
  }

  #app-view.employee-mode #nav-overview::before { content: "⌂"; }
  #app-view.employee-mode #nav-new-batch::before { content: "+"; }
  #app-view.employee-mode #nav-batches::before { content: "☷"; }
  #app-view.employee-mode .basic-only[data-view="help"]::before { content: "?"; }

  #app-view.employee-mode .nav-button.active {
    background: #e3eedf;
    color: var(--green);
  }

  #app-view.employee-mode .workspace {
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }

  #app-view.employee-mode .toast {
    bottom: calc(78px + env(safe-area-inset-bottom));
  }

  .batch-workspace {
    display: block;
  }

  .batch-form-card,
  .auto-details-card,
  .created-batch {
    width: 100%;
    padding: 18px 16px;
    border-radius: 16px;
  }

  .batch-form-card {
    gap: 18px;
  }

  .batch-form-card label {
    gap: 8px;
    font-size: 14px;
    min-width: 0;
    width: 100%;
  }

  .batch-form-card input,
  .batch-form-card select,
  #create-batch {
    min-height: 54px;
    min-width: 0;
    width: 100%;
  }

  .batch-form-card select {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #create-batch {
    width: 100%;
    margin-top: 2px;
  }

  .step-title {
    gap: 10px;
  }

  .step-title > span {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
  }

  .step-title strong {
    font-size: 16px;
    line-height: 1.3;
  }

  .auto-details-card {
    margin-top: 16px;
    min-height: 0;
  }

  .auto-details-card.is-empty {
    display: none;
  }

  .auto-values {
    grid-template-columns: 1fr 1fr;
  }

  .auto-values .expiry-value {
    grid-column: 1 / -1;
  }

  .created-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .created-actions button {
    width: 100%;
  }

  .personal-heading {
    display: block;
  }

  #personal-refresh {
    display: none;
  }

  .personal-task-cards {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .personal-task-card {
    min-height: 76px;
    padding: 14px;
  }

  .personal-status-strip {
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .personal-status-strip > * {
    scroll-snap-align: start;
  }

  .personal-list {
    padding: 18px 14px;
  }
}

@media (max-width: 520px) {
  .workspace {
    padding-inline: 14px;
  }

  .login-page {
    display: block;
    padding: max(22px, env(safe-area-inset-top)) 14px 24px;
  }

  .login-card {
    width: 100%;
    padding: 28px 20px;
    border-radius: 20px;
  }

  .login-card h1 {
    font-size: 30px;
  }

  .login-card .primary {
    min-height: 52px;
  }

  .summary-grid,
  .dashboard-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .summary-card,
  .dashboard-card {
    min-width: 0;
    padding: 13px;
  }

  .summary-card span,
  .dashboard-card span {
    font-size: 10px;
  }

  .summary-card strong,
  .dashboard-card strong {
    font-size: 24px;
  }

  .product-card,
  .help-steps article,
  .dashboard-visuals > section,
  .trend-card,
  .dashboard-register,
  .system-columns > section {
    border-radius: 14px;
  }

  .sku-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px 12px;
  }

  .category-segments {
    margin-right: -14px;
    padding-right: 14px;
  }

  .system-runtime {
    grid-template-columns: 1fr;
  }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 920px) {
  #app-view.employee-mode .sidebar {
    height: calc(56px + env(safe-area-inset-bottom));
  }

  #app-view.employee-mode .nav-button {
    min-height: 48px;
    flex-direction: row;
    font-size: 12px;
  }

  #app-view.employee-mode .nav-button::before {
    font-size: 17px;
  }

  #app-view.employee-mode .workspace {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }
}
