/* Phone and small-tablet adjustments, loaded after the compiled stylesheet. */

/* Grid tracks must be allowed to shrink below the width of long select options. */
.order-form > *,
.form-grid > *,
.filter-grid > *,
.modal-form > *,
.panel,
.modal-card fieldset {
  min-width: 0;
}
.order-form input,
.order-form select,
.order-form textarea,
.form-grid input,
.form-grid select,
.form-grid textarea,
.filter-grid input,
.filter-grid select,
.modal-card input,
.modal-card select,
.modal-card textarea {
  min-width: 0;
  max-width: 100%;
}

@media (width <= 900px) {
  .login-page {
    grid-template-columns: 1fr;
  }
  .login-visual {
    padding: 22px 20px 18px;
  }
  .login-curve,
  .industrial-scene,
  .login-benefits {
    display: none;
  }
  .login-brand-block h1 {
    margin: 10px 0 4px;
    font-size: 1.5rem;
  }
  .login-brand-block img {
    max-height: 64px;
    width: auto;
  }
  .login-form-panel {
    padding: 18px 14px 28px;
  }

  /* The side menu becomes a compact top bar with horizontally scrollable sections. */
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 15;
    gap: 8px;
    padding: 10px 12px;
    box-shadow: 0 6px 18px #0003;
  }
  .brand {
    padding: 0;
  }
  .brand img {
    max-height: 40px;
    width: auto;
  }
  .sidebar-nav {
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .nav-item {
    flex: none;
    gap: 8px;
    padding: 8px 12px;
    white-space: nowrap;
    scroll-snap-align: start;
  }
  .nav-icon {
    width: 24px;
    height: 24px;
  }
  .sidebar-card {
    display: none;
  }

  .main-panel {
    gap: 14px;
    min-width: 0;
  }
  .topbar {
    padding: 14px 16px;
  }
  .topbar h1 {
    font-size: 1.4rem;
  }
  .topbar-actions {
    width: 100%;
  }
  .search-results {
    left: 12px;
    right: 12px;
  }

  .modal-card {
    width: min(900px, 96vw);
    max-height: 94dvh;
  }
}

@media (width <= 700px) {
  .order-form,
  .form-grid,
  .filter-grid,
  .modal-form,
  .kpi-grid,
  .footer-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .filter-grid > button {
    grid-column: 1 / -1;
  }
  .main-panel {
    padding: 12px;
  }
  .panel {
    padding: 14px 12px;
    border-radius: 16px;
  }
  .panel-header,
  .calendar-toolbar,
  .footer-bar,
  .pagination {
    flex-wrap: wrap;
    gap: 10px;
  }
  .topbar-actions {
    gap: 8px;
  }
  .topbar-actions > * {
    flex: 0 1 auto;
  }
  .topbar-actions > .search-box {
    flex-basis: 100%;
  }
  .topbar-actions > button {
    padding: 8px 12px;
    font-size: .85rem;
  }
  .profile-pill {
    padding: 4px;
  }
  .profile-pill > :not(.avatar) {
    display: none;
  }
  .avatar {
    flex: none;
    width: 32px;
    height: 32px;
  }
  .topbar .eyebrow {
    display: none;
  }
  .topbar h1 {
    margin: 0;
  }
  .sidebar-nav {
    scrollbar-width: none;
    mask-image: linear-gradient(90deg, #000 85%, transparent);
  }
  .sidebar-nav::-webkit-scrollbar {
    display: none;
  }

  /* Prevent iOS from zooming into fields and keep touch targets usable. */
  input,
  select,
  textarea {
    font-size: 16px;
  }
  button,
  .nav-item {
    min-height: 40px;
  }

  .modal-overlay {
    place-items: stretch;
  }
  .modal-card {
    width: 100vw;
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
    padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  }

  th,
  td {
    padding: 10px 8px;
    font-size: .85rem;
    white-space: nowrap;
  }
  td .action-icons,
  td > div {
    flex-wrap: wrap;
  }

  .calendar-grid,
  .machine-schedule-calendar {
    gap: 3px;
  }
  .calendar-day {
    min-height: 64px;
    padding: 4px;
    border-radius: 8px;
    overflow: hidden;
  }
  .calendar-event {
    padding: 2px 3px;
    font-size: .62rem;
    overflow-wrap: anywhere;
  }
  .machine-schedule-day,
  .machine-schedule-empty {
    aspect-ratio: auto;
    min-height: 58px;
    padding: 4px;
    border-radius: 6px;
  }
  .machine-schedule-day select {
    width: 100%;
    font-size: .66rem;
    appearance: none;
    -webkit-appearance: none;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    min-height: 28px;
  }
  .machine-schedule-weekday {
    padding: 0;
    font-size: .62rem;
  }
  .machine-schedule-selected {
    flex-wrap: wrap;
  }

  /* Asset tree: shallower indentation and shrinkable rows for deep branches. */
  .main-panel div[style*="display: grid"][style*="margin-left"] {
    margin-left: 10px !important;
  }
  .main-panel div[style*="display: grid"] > div {
    min-width: 0;
  }
  .main-panel div[style*="display: flex"] > button {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .vertical-bars,
  .order-trend-bars {
    overflow-x: auto;
    justify-content: flex-start;
  }
  .donut-wrap,
  .task-distribution-donut {
    margin-inline: auto;
  }
}
