/* Material 3 styles for the orders pages. Shared components live in m3.css.
 *
 * Pages: /orders (and /deliveries, /scheduled, /failures, /duplicates, which
 * render the same list), the /orders/table polling fragment and the order
 * detail page /orders/{id}. Every class here starts with m3-ord-.
 *
 * Never put display:flex/grid on a table cell: it drops the implicit
 * display:table-cell and the row collapses into stacked blocks.
 */

/* ---- Live indicator in the page header --------------------------------- */
.m3-ord-live {
  gap: 10px;
  padding: 0 14px 0 12px;
}

.m3-ord-live-dot {
  position: relative;
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--md-success);
}

.m3-ord-live-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--md-success);
  opacity: 0.25;
  animation: m3-ord-pulse 2s ease-out infinite;
}

@keyframes m3-ord-pulse {
  0% { transform: scale(0.6); opacity: 0.35; }
  100% { transform: scale(1.6); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .m3-ord-live-dot::after {
    animation: none;
  }
}

/* ---- Filter toolbar -------------------------------------------------------- */
.m3-ord-filters {
  margin-bottom: 20px;
}

.m3-ord-search {
  flex: 1 1 320px;
}

.m3-ord-select {
  flex: 0 1 220px;
}

/* A hint that appears once the label has floated, as in Material search
   fields. The label float still keys off :placeholder-shown. */
.m3-ord-search .m3-field-input:focus::placeholder,
.m3-ord-hint .m3-field-input:focus::placeholder {
  color: var(--md-on-surface-variant);
  opacity: 0.7;
}

/* Native selects inside an outlined field: the floating label stays up
   (is-static) and a chevron replaces the browser arrow. */
.m3-ord-select select.m3-field-input {
  padding-right: 40px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  text-overflow: ellipsis;
}

.m3-ord-select-icon {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 24px;
  height: 24px;
  color: var(--md-on-surface-variant);
  pointer-events: none;
}

.m3-ord-filter-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

@media (max-width: 760px) {
  .m3-ord-search {
    flex: 1 1 100%;
  }
  /* Two filters a row, so the orders start on the first screen. */
  .m3-ord-select {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }
}

/* ---- Order table ------------------------------------------------------------ */
.m3-ord-table td {
  padding-top: 10px;
  padding-bottom: 10px;
}

/* Two lines per cell: the value, then its context. Stacked by making the
   spans block-level, never by putting flex on the cell. */
.m3-ord-stack > * {
  display: block;
}

.m3-ord-stack > * + * {
  margin-top: 2px;
}

.m3-ord-strong {
  color: var(--md-on-surface);
  font-weight: 500;
}

.m3-ord-sub {
  color: var(--md-on-surface-variant);
  font-size: 0.75rem;
  line-height: 1rem;
  letter-spacing: 0.02em;
}

.m3-ord-code {
  font-family: var(--critical-font);
  font-size: 0.875rem;
  letter-spacing: 0.02em;
}

/* Keep a long address from stretching the row across the screen. */
.m3-ord-address {
  max-width: 42ch;
  overflow-wrap: anywhere;
}

.m3-ord-nowrap {
  white-space: nowrap;
}

.m3-ord-tabular {
  font-variant-numeric: tabular-nums;
}

.m3-ord-col-action {
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

.m3-ord-table td.m3-ord-col-action {
  padding-right: 20px;
}

/* A round chevron rather than a labelled button: the table gained columns
   and the label pushed the button against the card's edge. */
.m3-ord-open {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--md-on-primary-container);
  background: var(--md-primary-container);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.m3-ord-open:hover {
  color: var(--md-on-primary-container);
  transform: translateX(2px);
  box-shadow: var(--md-shadow);
}

.m3-btn.m3-ord-btn-small {
  height: 32px;
  padding: 0 16px;
  border-radius: 16px;
}

/* Trailing icons: m3.css pulls a leading icon toward the edge instead. */
.m3-btn.m3-ord-next .m3-icon {
  margin-left: 0;
  margin-right: -6px;
}

.m3-ord-empty-icon.m3-icon {
  display: block;
  width: 32px;
  height: 32px;
  margin: 0 auto 8px;
  color: var(--md-outline);
}

/* ---- Pagination under the table ------------------------------------------- */
.m3-ord-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.m3-ord-pagination .m3-body-medium {
  margin-right: 8px;
}

.m3-btn.is-disabled {
  color: rgb(25 28 32 / 38%);
  pointer-events: none;
  cursor: default;
}

/* ===== Order detail ========================================================== */
.m3-page.m3-ord-detail {
  max-width: 1200px;
}

.m3-ord-back {
  margin: 0 0 4px -12px;
}

.m3-ord-header-chips {
  align-self: center;
}

.m3-ord-stack-cards {
  display: grid;
  gap: 16px;
}

.m3-ord-card-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.m3-ord-card-title .m3-icon {
  width: 24px;
  height: 24px;
  color: var(--md-primary);
}

.m3-card.m3-ord-card-done {
  border-color: var(--md-success);
  box-shadow: inset 4px 0 0 var(--md-success);
}

/* Banners: a warning tone m3.css does not have. */
.m3-banner.m3-ord-banner-warning {
  color: #261900;
  background: var(--md-warning-container);
}

.m3-ord-banner-gap {
  margin: 16px 0 0;
}

.m3-ord-banner-text {
  margin: 0 0 12px;
}

.m3-ord-issues {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.m3-ord-issues code {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  color: inherit;
  background: rgb(255 255 255 / 55%);
  font-size: 0.8125rem;
}

/* Label/value pairs laid out in columns. */
.m3-ord-facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px 24px;
  margin: 0;
}

.m3-ord-facts dd {
  margin: 0;
}

.m3-ord-facts dt {
  font-weight: 500;
}

.m3-ord-facts.is-compact {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px 24px;
  margin-top: 12px;
}

.m3-ord-facts.is-compact:not(:has(.m3-ord-fact)) {
  display: none;
}

.m3-ord-block-code {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

/* ---- Acceptance trail ------------------------------------------------------ */
.m3-ord-lead {
  margin-bottom: 16px;
}

.m3-ord-timeline {
  margin: 0;
  padding: 0 0 0 6px;
  list-style: none;
}

.m3-ord-timeline-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 0 12px 20px;
  border-left: 2px solid var(--md-outline-variant);
}

.m3-ord-timeline-item:last-child {
  padding-bottom: 0;
  border-left-color: transparent;
}

.m3-ord-timeline-item::before {
  content: "";
  position: absolute;
  top: 7px;
  left: -6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--md-outline-variant);
}

.m3-ord-timeline-item.is-current::before {
  background: var(--md-primary);
  box-shadow: 0 0 0 3px var(--md-primary-container);
}

.m3-ord-timeline-time {
  min-width: 46px;
  color: var(--md-on-surface-variant);
  font: 400 0.75rem/1rem var(--m3-font);
  font-variant-numeric: tabular-nums;
}

/* ---- Address and customer -------------------------------------------------- */
.m3-grid.m3-ord-pair {
  gap: 16px;
  align-items: stretch;
}

.m3-ord-address-line {
  overflow-wrap: anywhere;
}

.m3-ord-geo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 16px;
}

.m3-ord-notes {
  margin: 8px 0 0;
  padding-left: 20px;
}

.m3-ord-notes li + li {
  margin-top: 2px;
}

.m3-ord-geo-actions {
  margin-top: 16px;
}

.m3-ord-geo-actions form {
  margin: 0;
}

.m3-expand.m3-ord-coords {
  margin-top: 8px;
}

.m3-expand.m3-ord-coords > summary {
  margin-left: -12px;
}

.m3-ord-coords-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px;
}

.m3-ord-coords-row .m3-field {
  flex: 1 1 150px;
}

.m3-ord-coords-help {
  margin-top: 8px;
}

.m3-ord-coords-help a {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.m3-ord-coords-help .m3-icon {
  width: 16px;
  height: 16px;
}

.m3-subhead.m3-ord-subhead {
  margin: 24px 0 4px;
}

.m3-ord-error-text {
  color: var(--md-error);
}

/* ---- Critical fields: extraction status under each field ----------------- */
.m3-ord-field-status {
  display: flex;
  align-items: center;
  gap: 4px;
}

.m3-ord-field-status .m3-icon {
  width: 14px;
  height: 14px;
}

.m3-ord-field-status.is-done {
  color: var(--md-success);
}

/* ---- Actions --------------------------------------------------------------- */
.m3-ord-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.m3-ord-action-row form,
.m3-ord-dispatch form {
  margin: 0;
}

.m3-ord-dispatch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--md-outline-variant);
}

.m3-ord-done {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--md-on-surface-variant);
  font: 400 0.875rem/1.25rem var(--m3-font);
}

.m3-ord-done strong {
  color: var(--md-on-surface);
}

/* Extra button tones. Single-class selectors on purpose, so the shared
   .m3-btn:disabled rule still greys them out. */
.m3-ord-btn-danger {
  color: #fff;
  background: var(--md-error);
}

.m3-ord-btn-danger:not(:disabled):hover {
  box-shadow: var(--md-shadow);
}

.m3-ord-btn-warning {
  color: #261900;
  background: var(--md-warning-container);
}

.m3-ord-btn-warning-strong {
  color: #fff;
  background: #6d4c00;
}

.m3-ord-btn-warning-strong:not(:disabled):hover {
  box-shadow: var(--md-shadow);
}

/* ---- Diagnostics ------------------------------------------------------------ */
.m3-expand.m3-ord-diagnostics {
  margin-top: 24px;
}

.m3-expand.m3-ord-diagnostics > summary {
  margin-left: -12px;
}

.m3-ord-pre-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
}

.m3-ord-pre-title .m3-icon {
  color: var(--md-primary);
}

.m3-ord-pre {
  max-height: 420px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border-radius: var(--md-radius-sm);
  color: var(--md-on-surface);
  background: var(--md-surface-container-low);
  font: 400 0.75rem/1.125rem var(--critical-font);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Codes in the detail page read as data, not as Bootstrap's pink inline code. */
.m3-ord-detail code {
  color: inherit;
  font-family: var(--critical-font);
  font-size: 0.875em;
}

/* A disabled outlined button keeps a faint outline (M3 spec), so the greyed
   "Preview delivery" still reads as a button. */
.m3-ord-dispatch .m3-btn-outlined:disabled {
  border-color: rgb(25 28 32 / 12%);
}

@media (max-width: 600px) {
  .m3-ord-detail .m3-card {
    padding: 16px;
  }
  .m3-ord-detail .m3-ord-card-title .m3-title-large {
    font-size: 1.25rem;
  }
}

/* The RiderX chip sits under the status, on its own line. */
.m3-chip.m3-ord-riderx {
  display: flex;
  width: fit-content;
  margin-top: 6px;
}

/* Who moved the order on Lieferando, under its badge. */
.m3-ord-sub.m3-ord-who {
  display: block;
  margin-top: 4px;
}

/* The phone number is a call link: one tap on a phone. */
.m3-ord-phone {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  text-decoration: none;
}

.m3-ord-phone .m3-icon { width: 16px; height: 16px; color: var(--md-on-surface-variant); }
.m3-ord-phone:hover { color: var(--md-primary); }

/* ---- Phones: one card per order instead of an eight-column table ---------- */
/* The table scrolled sideways and broke names and addresses into one word
   per line. Each row becomes a card: code and time first, then who and
   where, then the badges; the whole card opens the order. */
@media (max-width: 720px) {
  .m3-ord-table thead { display: none; }

  .m3-table-wrap:has(.m3-ord-table) {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .m3-ord-table,
  .m3-ord-table tbody {
    display: block;
    width: 100%;
  }

  .m3-ord-table tr.m3-ord-row {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "code   time"
      "rest   rest"
      "cust   cust"
      "ready  phone"
      "portal status";
    align-items: start;
    gap: 6px 12px;
    margin-bottom: 10px;
    padding: 14px 16px;
    border: 1px solid var(--md-outline-variant);
    border-radius: var(--md-radius-lg);
    background: var(--md-surface-container-low);
  }

  .m3-ord-table tr.m3-ord-row > td {
    display: block;
    height: auto;
    padding: 0;
    border: 0;
    background: none;
    white-space: normal;
  }

  .m3-ord-table .m3-ord-c-code { grid-area: code; }
  .m3-ord-table .m3-ord-c-code .m3-ord-code { font-size: 1rem; }

  .m3-ord-table .m3-ord-c-time { grid-area: time; text-align: end; }

  .m3-ord-table .m3-ord-c-rest {
    grid-area: rest;
    color: var(--md-primary);
    font-size: 0.8125rem;
    font-weight: 600;
  }

  .m3-ord-table .m3-ord-c-cust { grid-area: cust; }
  .m3-ord-table .m3-ord-c-cust .m3-ord-address { max-width: none; }

  .m3-ord-table .m3-ord-c-ready { grid-area: ready; }
  .m3-ord-table .m3-ord-c-ready:has(> .m3-ord-sub:only-child) { display: none; }

  .m3-ord-table .m3-ord-c-phone {
    position: relative;
    z-index: 1;  /* above the card's own link */
    grid-area: phone;
    align-self: center;
    text-align: end;
  }

  /* Lieferando's tab and the RiderX status side by side. */
  .m3-ord-table .m3-ord-c-portal,
  .m3-ord-table .m3-ord-c-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  .m3-ord-table .m3-ord-c-portal { grid-area: portal; margin-top: 4px; }

  .m3-ord-table .m3-ord-c-status {
    grid-area: status;
    justify-content: flex-end;
    margin-top: 4px;
  }

  .m3-ord-table .m3-ord-c-status .m3-chip.m3-ord-riderx,
  .m3-ord-table .m3-ord-c-portal .m3-ord-who { margin-top: 0; }

  /* The chevron goes; the whole card is the link. */
  .m3-ord-table .m3-ord-c-open { position: static; }

  .m3-ord-table .m3-ord-open {
    position: absolute;
    inset: 0;
    width: auto;
    height: auto;
    border-radius: inherit;
    background: transparent;
    color: transparent;
  }

  .m3-ord-table .m3-ord-open .m3-icon { display: none; }
  .m3-ord-table .m3-ord-open:hover { transform: none; box-shadow: none; }
  .m3-ord-table tr.m3-ord-row:active { background: var(--md-surface-container); }

  .m3-ord-table .m3-table-empty { display: block; padding: 32px 16px; text-align: center; }
}

/* Remaining / All on the Scheduled page: a two-way segmented button. */
.m3-ord-segment {
  display: inline-flex;
  flex: 0 0 auto;
  height: 40px;
  border: 1px solid var(--md-outline);
  border-radius: 20px;
  overflow: hidden;
}

.m3-ord-segment-option { display: flex; cursor: pointer; }

.m3-ord-segment-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.m3-ord-segment-option span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  color: var(--md-on-surface);
  font: 500 0.875rem/1.25rem var(--m3-font);
  transition: background-color 150ms;
}

.m3-ord-segment-option + .m3-ord-segment-option span { border-left: 1px solid var(--md-outline); }
.m3-ord-segment-option span .m3-icon { width: 18px; height: 18px; }
.m3-ord-segment-option strong { font-weight: 700; font-variant-numeric: tabular-nums; }
.m3-ord-segment-option:hover span { background: var(--md-surface-container); }

.m3-ord-segment-option input:checked + span {
  color: var(--md-on-secondary-container, var(--md-on-primary-container));
  background: var(--md-secondary-container, var(--md-primary-container));
}

.m3-ord-segment-option input:focus-visible + span {
  outline: 2px solid var(--md-primary);
  outline-offset: -2px;
}

@media (max-width: 760px) {
  .m3-ord-segment { flex: 1 1 100%; }
  .m3-ord-segment-option { flex: 1 1 50%; }
  .m3-ord-segment-option span { flex: 1; justify-content: center; }
}

/* ---- Folding filters on the orders page ---------------------------------- */
.m3-ord-filters-form { margin-bottom: 8px; }

.m3-ord-more-toggle { position: relative; gap: 8px; }

.m3-ord-more-count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  color: var(--md-on-primary);
  background: var(--md-primary);
  font-size: 0.75rem;
  font-weight: 700;
}

.m3-ord-more-chevron { transition: transform 260ms cubic-bezier(0.2, 0, 0, 1); }
.m3-ord-more-toggle.is-open .m3-ord-more-chevron { transform: rotate(180deg); }

/* Height from 0 to its content by animating the grid row, so nothing has to
   know how tall the panel is. */
.m3-ord-more {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 280ms cubic-bezier(0.2, 0, 0, 1);
}

.m3-ord-more.is-open { grid-template-rows: 1fr; }

.m3-ord-more-inner {
  min-height: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 200ms ease, transform 280ms cubic-bezier(0.2, 0, 0, 1);
}

.m3-ord-more.is-open .m3-ord-more-inner {
  opacity: 1;
  transform: none;
}

.m3-ord-more-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px 12px;
  padding: 14px 0 4px;
}

.m3-ord-more-grid .m3-ord-select { flex: none; min-width: 0; }

.m3-ord-when {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 0 6px;
}

.m3-ord-when-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--md-on-surface-variant);
  font: 600 0.8125rem/1.25rem var(--m3-font);
}

.m3-ord-when-label .m3-icon { width: 18px; height: 18px; }

.m3-ord-segment.is-small { height: 36px; }
.m3-ord-segment.is-small .m3-ord-segment-option span { padding: 0 12px; font-size: 0.8125rem; }

.m3-ord-date { flex: 0 0 170px; }

/* The filters in force, each removable on its own. */
.m3-ord-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 4px 0 16px;
}

.m3-ord-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 8px 0 12px;
  border-radius: 8px;
  color: var(--md-on-secondary-container, var(--md-on-primary-container));
  background: var(--md-secondary-container, var(--md-primary-container));
  font: 500 0.8125rem/1rem var(--m3-font);
  text-decoration: none;
  animation: ord-chip-in 220ms cubic-bezier(0.2, 0, 0, 1) both;
  transition: filter 150ms;
}

.m3-ord-chip .m3-icon { width: 16px; height: 16px; opacity: 0.75; }
.m3-ord-chip:hover { filter: brightness(0.95); color: inherit; }

.m3-ord-chip-clear {
  color: var(--md-primary);
  font: 500 0.8125rem/1rem var(--m3-font);
  text-decoration: none;
}

@keyframes ord-chip-in {
  from { opacity: 0; transform: scale(0.9); }
}

@media (max-width: 760px) {
  .m3-ord-more-toggle { flex: 1 1 auto; justify-content: center; }
  .m3-ord-more-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .m3-ord-when .m3-ord-segment { flex: 1 1 100%; overflow-x: auto; }
  .m3-ord-date { flex: 1 1 calc(50% - 6px); }
}

@media (prefers-reduced-motion: reduce) {
  .m3-ord-more, .m3-ord-more-inner, .m3-ord-more-chevron, .m3-ord-chip { transition: none; animation: none; }
}

.m3-ord-segment-option span { white-space: nowrap; }
@media (max-width: 760px) {
  .m3-dash-filters .m3-ord-segment-option { flex: 1 0 auto; }
  .m3-dash-filters .m3-ord-segment-option span { padding: 0 9px; font-size: 0.8125rem; }
}

/* The delivery time the restaurant promised, under the food time. */
.m3-ord-promise { display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: tabular-nums; }
.m3-ord-promise .m3-icon { width: 14px; height: 14px; }
