/* Material 3 styles for the dashboard pages. Shared components live in m3.css.
 *
 * Covers /dashboard, /setup and /audit-logs. Every rule is either a new
 * m3-dash-* class or an override scoped to .m3-dash-page, because the older
 * chart classes in app.css (trend-*, column-*, chart-*, vienna-*) are also used
 * by other pages. The chart and map geometry (SVG coordinates, plot heights,
 * axis gutters) is left exactly as app.css draws it; only colour, shape and
 * type change here.
 */

/* ---- Page header ---------------------------------------------------------- */
.m3-dash-header-side {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding-top: 8px;
}

/* Filled in by script when there is one; an empty stamp takes no room. */
.m3-dash-refreshed:empty {
  display: none;
}

/* ---- Open on Lieferando now ------------------------------------------------- */
.m3-dash-open {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin: -8px 0 24px;
}

.m3-dash-open-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--md-on-surface-variant);
  font-family: var(--m3-font);
  font-size: 0.875rem;
  font-weight: 500;
}

.m3-dash-open-checked {
  font-weight: 400;
}

.m3-dash-open-label .m3-icon {
  width: 20px;
  height: 20px;
}

/* A long closure ("closed by hand until …") wraps on a phone, not overflow. */
.m3-dash-open-chip {
  height: auto;
  min-height: 32px;
  max-width: 100%;
  padding: 6px 16px 6px 12px;
  white-space: normal;
}

.m3-dash-open-dot {
  flex: none;
}

.m3-dash-open-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--md-outline);
}

.m3-dash-open-chip.is-open {
  color: #0a3a20;
  background: var(--md-success-container);
  border-color: transparent;
}

.m3-dash-open-chip.is-open .m3-dash-open-dot {
  background: #1e8e4a;
}

.m3-dash-open-chip.is-closed {
  color: #410002;
  background: var(--md-error-container);
  border-color: transparent;
}

.m3-dash-open-chip.is-closed .m3-dash-open-dot {
  background: var(--md-error);
}

/* ---- Filter toolbar ---------------------------------------------------------- */
/* The floated labels sit 8px above each field, so the row needs that room. */
.m3-dash-filters {
  padding-top: 8px;
  margin-bottom: 24px;
}

.m3-dash-filters .m3-field {
  flex: 0 1 200px;
}

.m3-dash-filters .m3-dash-filter-wide {
  flex-basis: 260px;
}

.m3-dash-filters .m3-dash-filter-grow {
  flex: 1 1 320px;
  max-width: 520px;
}

.m3-dash-filters .m3-dash-date-field {
  flex: 0 1 180px;
  min-width: 164px;
}

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

/* A select in the outlined field, with the Material dropdown arrow. */
.m3-dash-select {
  padding-inline-end: 44px;
  background: var(--md-surface-bright);
  appearance: none;
  cursor: pointer;
  text-overflow: ellipsis;
}

.m3-dash-select-arrow {
  position: absolute;
  top: 8px;
  inset-inline-end: 12px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: var(--md-on-surface-variant);
  pointer-events: none;
}

.m3-dash-select-arrow .m3-icon {
  width: 24px;
  height: 24px;
}

.m3-dash-date-field .m3-field-input {
  padding-inline-end: 8px;
}

.m3-dash-date-field .m3-field-input::-webkit-calendar-picker-indicator {
  opacity: 0.7;
  cursor: pointer;
}

/* The audit filter keeps its example text visible under the floated label. */
.m3-dash-hint-field .m3-field-input::placeholder {
  color: var(--md-on-surface-variant);
  opacity: 0.7;
}

/* ---- Headline figures --------------------------------------------------------- */
/* Five across when there is room. Narrower, the lead tile takes two columns
   so the rows always fill: 2 + 1, then 3 (or 2, then 2 + 2 on a phone). */
.m3-dash-stats {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 24px;
}

@media (max-width: 1339.98px) {
  .m3-dash-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .m3-dash-stats .m3-dash-stat:first-child {
    grid-column: span 2;
  }
}

@media (max-width: 640px) {
  .m3-dash-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.m3-dash-stat {
  --m3-dash-tile-bg: var(--md-surface-container-low);
  min-width: 0;
  gap: 2px;
  padding: 16px 18px;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-lg);
  background: var(--md-surface-container-low);
}

.m3-dash-stat .m3-stat-label {
  margin-bottom: 6px;
  font-weight: 600;
}

.m3-dash-stat .m3-stat-label .m3-icon {
  width: 20px;
  height: 20px;
  color: var(--md-primary);
}

.m3-dash-stat .m3-stat-value {
  font: 600 2rem/2.5rem var(--m3-font);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.m3-dash-unit {
  margin-inline-start: 3px;
  color: var(--md-on-surface-variant);
  font-size: 1.125rem;
  font-weight: 500;
}

.m3-dash-unit.is-lead { margin-inline: 0 2px; }

/* What the number counts, in words. */
.m3-dash-stat-line {
  color: var(--md-on-surface);
  font: 500 0.8125rem/1.25rem var(--m3-font);
}

.m3-dash-stat-hint {
  color: var(--md-on-surface-variant);
  font: 400 0.75rem/1.125rem var(--m3-font);
}

/* The period before, at the foot of the tile so every tile lines up. */
.m3-dash-compare {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: auto;
  padding-top: 10px;
  color: var(--md-on-surface-variant);
  font: 400 0.75rem/1rem var(--m3-font);
}

.m3-dash-compare .m3-icon { width: 16px; height: 16px; flex: 0 0 auto; }

/* How each dispatched order got through, as one bar: untouched, repaired by
   the bridge, needed a person. A 2px gap in the tile colour separates them. */
.m3-dash-split {
  display: flex;
  height: 8px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--md-surface-container-high);
}

.m3-dash-split-seg {
  display: block;
  height: 100%;
}

.m3-dash-split-seg + .m3-dash-split-seg {
  box-shadow: inset 2px 0 0 var(--m3-dash-tile-bg);
}

.m3-dash-split-seg.is-clean { background: var(--md-success); }
.m3-dash-split-seg.is-fixed { background: var(--md-primary); }
.m3-dash-split-seg.is-human { background: #d99a00; }

.m3-dash-split-key {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  color: var(--md-on-surface-variant);
  font: 400 0.75rem/1.125rem var(--m3-font);
}

.m3-dash-split-key li {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.m3-dash-split-key li::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--seg);
}

.m3-dash-split-key .is-fixed { --seg: var(--md-primary); }
.m3-dash-split-key .is-human { --seg: #d99a00; }

/* ---- Card grid ------------------------------------------------------------------ */
.m3-dash-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.m3-dash-span-12 { grid-column: span 12; }
.m3-dash-span-7 { grid-column: span 7; }
.m3-dash-span-6 { grid-column: span 6; }
.m3-dash-span-5 { grid-column: span 5; }

/* The map and its ranked list stack first; the half-width charts keep two
   across until a card would be too narrow to read 24 hourly columns. */
@media (max-width: 1199.98px) {
  .m3-dash-span-7,
  .m3-dash-span-5 {
    grid-column: span 12;
  }
}

@media (max-width: 859.98px) {
  .m3-dash-grid > * {
    grid-column: span 12;
  }
}

.m3-dash-card {
  display: flex;
  flex-direction: column;
  padding: 20px 24px 24px;
}

.m3-dash-card .m3-card-head {
  align-items: center;
  margin-bottom: 16px;
}

.m3-dash-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--md-on-surface);
  font: 500 1rem/1.5rem var(--m3-font);
  letter-spacing: 0.009em;
}

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

/* The supporting line lines up with the title text, not the icon. */
.m3-dash-card .m3-card-head .m3-body-medium {
  margin-top: 2px;
  padding-inline-start: 28px;
}

.m3-dash-section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
}

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

.m3-dash-page .m3-section {
  margin-top: 32px;
}

.m3-dash-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  padding: 32px 8px;
  color: var(--md-on-surface-variant);
  font: 400 0.875rem/1.25rem var(--m3-font);
  letter-spacing: 0.018em;
  text-align: center;
}

.m3-dash-empty .m3-icon {
  width: 32px;
  height: 32px;
  opacity: 0.6;
}

.m3-dash-empty.is-good .m3-icon {
  color: var(--md-success);
  opacity: 1;
}

.m3-dash-legend-text {
  color: var(--md-on-surface-variant);
  font: 400 0.75rem/1rem var(--m3-font);
  letter-spacing: 0.033em;
  white-space: nowrap;
}

/* ---- Orders per day: one line, drawn on load ------------------------------------ */
/* The plot box is the SVG box: dots, guides and hover cells are placed with
   the same percentages the line's points were computed from. */
.dline {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 8px;
  height: 240px;
  margin-top: 12px;
}

.dline-axis-y,
.dline-axis-x {
  position: relative;
  color: var(--md-on-surface-variant);
  font: 400 0.6875rem/1rem var(--m3-font);
  font-variant-numeric: tabular-nums;
}

.dline-axis-y span {
  position: absolute;
  right: 0;
  transform: translateY(50%);
}

.dline-plot {
  position: relative;
  min-width: 0;
}

.dline-grid {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--md-outline-variant);
  opacity: 0.7;
}

.dline-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  /* Drawn from left to right once, on load. */
  animation: dline-draw 1400ms cubic-bezier(0.2, 0, 0, 1) 150ms both;
}

@keyframes dline-draw {
  from { clip-path: inset(-10px 100% -10px 0); }
  to { clip-path: inset(-10px 0 -10px 0); }
}

.dline-line {
  fill: none;
  stroke: var(--md-primary);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

/* Today is not over: its piece is dashed, not a fall. */
.dline-line.is-today { stroke-dasharray: 4 4; opacity: 0.7; }

.dline-area { stroke: none; }
.dline-fill-top { stop-color: var(--md-primary); stop-opacity: 0.18; }
.dline-fill-bottom { stop-color: var(--md-primary); stop-opacity: 0.01; }

/* The busiest day, marked once the line has reached it. */
.dline-peak {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid var(--md-primary);
  border-radius: 50%;
  background: var(--md-surface-bright);
  transform: translate(-50%, 50%);
  pointer-events: none;
  animation: dline-pop 360ms cubic-bezier(0.2, 0, 0, 1) both;
  animation-delay: 1500ms;
}

.dline-peak-label {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--md-primary);
  font: 600 0.75rem/1rem var(--m3-font);
}

@keyframes dline-pop {
  from { opacity: 0; transform: translate(-50%, 50%) scale(0.3); }
}

/* One hover target per day, centred on its point. */
.dline-cell {
  position: absolute;
  top: 0;
  bottom: 0;
  outline: none;
}

.dline-guide,
.dline-dot,
.dline-tip {
  position: absolute;
  left: var(--at);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms;
}

.dline-guide {
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--md-primary);
  opacity: 0;
}

.dline-dot {
  width: 10px;
  height: 10px;
  border: 2px solid var(--md-primary);
  border-radius: 50%;
  background: var(--md-surface-bright);
  transform: translate(-50%, 50%);
}

.dline-tip {
  bottom: calc(100% + 6px);
  z-index: 2;
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--m3-inverse-on-surface);
  background: var(--m3-inverse-surface);
  box-shadow: var(--md-shadow-raised);
  font: 400 0.75rem/1rem var(--m3-font);
  white-space: nowrap;
  transform: translateX(-50%);
}

.dline-tip strong { font-weight: 600; }
.dline-tip-date { display: block; opacity: 0.8; }

.dline-cell:first-of-type .dline-tip { transform: none; }
.dline-cell:last-of-type .dline-tip { transform: translateX(-100%); }

.dline-cell:hover .dline-guide,
.dline-cell:focus-visible .dline-guide { opacity: 0.35; }

.dline-cell:hover .dline-dot,
.dline-cell:hover .dline-tip,
.dline-cell:focus-visible .dline-dot,
.dline-cell:focus-visible .dline-tip { opacity: 1; }

.dline-axis-x {
  height: 18px;
  margin: 6px 0 0 40px;
}

.dline-axis-x span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.dline-axis-x span:first-child { transform: none; }
.dline-axis-x span:last-child { transform: translateX(-100%); }

@media (prefers-reduced-motion: reduce) {
  .dline-svg, .dline-peak { animation: none; }
}

/* ---- Charts: type and colour only ---------------------------------------------- */
/* Axis labels in Material's label-small. The line height stays one line, so
   the tick labels still sit on the gridlines they name. */
.m3-dash-page .trend-axis-y,
.m3-dash-page .column-axis-y,
.m3-dash-page .trend-axis-x,
.m3-dash-page .chart-axis {
  color: var(--md-on-surface-variant);
  font: 400 0.6875rem/1rem var(--m3-font);
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
}

/* Recessive hairline grid; the data is the only loud thing. */
.m3-dash-page .trend-grid {
  stroke: var(--md-outline-variant);
  stroke-opacity: 0.7;
}

.m3-dash-page .trend-line {
  stroke: var(--md-primary);
  stroke-width: 2;
}

.m3-dash-page .trend-fill-top { stop-color: var(--md-primary); stop-opacity: 0.16; }
.m3-dash-page .trend-fill-bottom { stop-color: var(--md-primary); stop-opacity: 0.01; }

.m3-dash-page .trend-hover-cell {
  border-radius: 4px;
}

.m3-dash-page .trend-hover-cell:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: -2px;
}

/* Plain tooltips, Material style: inverse surface, 4px corners. */
.m3-dash-page .trend-tip,
.m3-dash-page .column-tip {
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--m3-inverse-on-surface);
  background: var(--m3-inverse-surface);
  box-shadow: var(--md-shadow-raised);
  font: 400 0.75rem/1rem var(--m3-font);
  letter-spacing: 0.033em;
}

/* Count and unit on one line, the date under them. The app.css flex column
   put "3" and "orders" on separate lines. */
.m3-dash-page .trend-hover-cell:hover .trend-tip,
.m3-dash-page .trend-hover-cell:focus-visible .trend-tip,
.m3-dash-page .chart-column:hover .column-tip {
  display: block;
}

.m3-dash-page .trend-tip-date {
  display: block;
  opacity: 0.8;
}

.m3-dash-page .trend-tip strong,
.m3-dash-page .column-tip strong {
  font-weight: 500;
}

/* Columns: thin, a 4px rounded cap, square on the baseline. The column slot
   keeps its full width, so the hover target stays the whole slot. */
.m3-dash-page .chart-column {
  justify-content: center;
}

.m3-dash-page .chart-column-fill {
  max-width: 24px;
  border-radius: 4px 4px 0 0;
  background: var(--md-primary);
  opacity: 1;
  transition: filter 120ms ease;
}

.m3-dash-page .chart-columns-wide .chart-column-fill {
  max-width: 32px;
}

.m3-dash-page .chart-column:hover .chart-column-fill {
  filter: brightness(0.82);
}

.m3-dash-page .chart-column-empty .chart-column-fill {
  background: var(--md-outline-variant);
  opacity: 0.7;
}

/* Weekday ticks centred under their bars: seven equal slots with the same
   gap as the columns above them. */
.m3-dash-page .chart-axis-spread {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  text-align: center;
}

/* Horizontal bars: ranked districts, address issues and outcomes. */
.m3-dash-page .chart-rows {
  gap: 4px;
}

.m3-dash-page .chart-rows-stacked {
  gap: 16px;
}

.m3-dash-page .chart-row-label {
  color: var(--md-on-surface);
  font: 500 0.875rem/1.25rem var(--m3-font);
  letter-spacing: 0.007em;
}

.m3-dash-page .chart-row-value {
  color: var(--md-on-surface-variant);
  font: 400 0.8125rem/1.25rem var(--m3-font);
  font-variant-numeric: tabular-nums;
}

.m3-dash-page .chart-row-head .chart-row-value {
  color: var(--md-on-surface);
  font-weight: 500;
}

.m3-dash-page .chart-track {
  height: 12px;
  border-radius: 6px;
  background: var(--md-surface-container);
}

.m3-dash-page .chart-row-stacked .chart-track {
  height: 8px;
  border-radius: 4px;
}

.m3-dash-page .chart-track-fill {
  border-radius: inherit;
}

/* A district row is a link into the filtered orders list: give it a full
   Material list-item hover without moving the bars. */
.m3-dash-page .chart-row-link {
  margin: 0 -8px;
  padding: 6px 8px;
  border-radius: 8px;
}

.m3-dash-page .chart-row-link:hover,
.m3-dash-page .chart-row-link:focus-visible {
  background: rgb(25 28 32 / 6%);
}

.m3-dash-page .chart-row-link:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: 0;
}

.m3-dash-status-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.m3-dash-status-icon {
  display: inline-grid;
  place-items: center;
}

.m3-dash-status-icon .m3-icon {
  width: 16px;
  height: 16px;
}

.m3-dash-status-icon.is-bad { color: var(--md-error); }
.m3-dash-status-icon.is-good { color: var(--md-success); }

/* ---- Vienna map -------------------------------------------------------------------- */
/* Volume is one hue, light to dark: the primary colour at the strength the
   template already computes. Restaurants are dark ink pins on a light halo, so
   they read on any district shade. */
/* Links inside the SVG must not underline the district numbers. */
.m3-dash-page .vienna-district {
  text-decoration: none;
}

.m3-dash-page .vienna-shape {
  fill: var(--md-primary);
  stroke: var(--md-surface-bright);
}

.m3-dash-page .vienna-shape-quiet {
  fill: var(--md-surface-container);
  fill-opacity: 1;
  stroke: var(--md-outline-variant);
}

.m3-dash-page .vienna-district:hover .vienna-shape,
.m3-dash-page .vienna-district:focus-visible .vienna-shape {
  stroke: var(--md-on-surface);
  stroke-width: 2.5;
}

.m3-dash-page .vienna-district:focus-visible {
  outline: none;
}

.m3-dash-page .vienna-label {
  fill: var(--md-on-surface-variant);
  font-family: var(--m3-font);
  font-weight: 500;
}

.m3-dash-page .vienna-label-on-dark {
  fill: var(--md-on-primary);
}

.m3-dash-page .vienna-pin-dot {
  fill: var(--md-on-surface);
}

.m3-dash-page .vienna-pin-name {
  fill: var(--md-on-surface);
  font-family: var(--m3-font);
  font-weight: 500;
}

/* The scale shows exactly the fill strengths the map uses: 0.12 to 0.90. */
.m3-dash-page .vienna-scale {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(
    to right,
    color-mix(in srgb, var(--md-primary) 12%, var(--md-surface-bright)),
    color-mix(in srgb, var(--md-primary) 90%, var(--md-surface-bright))
  );
}

.m3-dash-page .vienna-legend {
  margin-top: 16px;
}

/* ---- Live status lists ----------------------------------------------------------- */
.m3-dash-list-primary {
  display: block;
  color: var(--md-on-surface);
  font: 400 0.875rem/1.25rem var(--m3-font);
  letter-spacing: 0.018em;
  overflow-wrap: anywhere;
}

.m3-dash-alerts .m3-chip {
  margin-top: 2px;
}

.m3-dash-services .m3-list-item {
  align-items: center;
}

.m3-dash-services .m3-list-item > .m3-icon {
  width: 20px;
  height: 20px;
  margin-top: 0;
}

.m3-dash-services .m3-dash-list-primary {
  flex: 1;
  min-width: 0;
}

/* ---- Tables --------------------------------------------------------------------- */
.m3-dash-link {
  color: var(--md-primary);
  font-weight: 500;
  text-decoration: none;
}

.m3-dash-link:hover {
  color: var(--md-primary);
  text-decoration: underline;
}

.m3-dash-cell-strong {
  font-weight: 500;
  white-space: nowrap;
}

.m3-dash-cell-wrap {
  min-width: 180px;
  overflow-wrap: anywhere;
}

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

.m3-dash-code {
  font-family: var(--critical-font);
  font-size: 0.8125rem;
}

/* Long JSON must not push the table sideways forever. */
.m3-dash-audit-data {
  display: inline-block;
  max-width: 380px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.m3-dash-page .m3-table-empty .m3-icon {
  width: 20px;
  height: 20px;
  margin-inline-end: 8px;
  vertical-align: middle;
}

/* ---- Narrow screens --------------------------------------------------------------- */
@media (max-width: 640px) {
  .m3-dash-filters .m3-field {
    flex-grow: 1;
  }
}

/* ---- Filters, as on the orders page --------------------------------------- */
.m3-dash-filter-form { margin-bottom: 20px; }
.m3-dash-filter-form .m3-dash-filters { margin-bottom: 0; }
.m3-dash-filters .m3-dash-export { margin-inline-start: auto; }
.m3-dash-filter-form .m3-ord-more-count { min-width: 26px; }

@media (max-width: 760px) {
  .m3-dash-filters .m3-ord-segment { flex: 1 1 100%; overflow-x: auto; }
  .m3-dash-filters .m3-dash-export { flex: 1 1 auto; justify-content: center; margin-inline-start: 0; }
}
