.capacity-shell {
  width: min(1520px, 100%);
  display: grid;
  gap: 14px;
}

.mobile-page-header,
.mobile-navigation-menu {
  display: none;
}

.capacity-heading-actions {
  position: relative;
  z-index: 12;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.alert-config-menu {
  position: relative;
  flex: 0 0 auto;
}

.alert-config-button {
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 9px 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 8px 20px rgba(23, 32, 27, 0.06);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.alert-config-button:hover,
.alert-config-button:focus-visible,
.alert-config-menu.is-open .alert-config-button {
  border-color: rgba(47, 113, 101, 0.42);
  background: var(--surface-soft);
  outline: none;
}

.alert-config-count {
  min-width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 10px;
  font-weight: 900;
}

.alert-config-count.is-off {
  background: #a2aaa4;
}

.alert-config-panel {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  z-index: 30;
  width: 182px;
  display: grid;
  gap: 2px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 38px rgba(23, 32, 27, 0.18);
}

.alert-config-panel[hidden] {
  display: none;
}

.alert-config-option {
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.alert-config-option:hover,
.alert-config-option:focus-within {
  background: var(--surface-soft);
}

.alert-config-option input {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.alert-config-option span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alert-config-option.is-muted {
  color: var(--muted);
  opacity: 0.52;
}

.alert-config-off {
  font-weight: 850;
}

.alert-config-divider {
  height: 1px;
  margin: 4px 2px;
  background: var(--line);
}

.capacity-board {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: auto;
  box-shadow: 0 18px 48px rgba(23, 32, 27, 0.08);
}

.capacity-grid {
  --capacity-row-height: 20px;
  --capacity-column-width: 64px;
  --capacity-alert-column-width: 150px;
  --capacity-exclusion-column-width: 70px;
  min-width: 760px;
  display: grid;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.capacity-cell {
  position: relative;
  min-height: var(--capacity-row-height);
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.capacity-cell.header {
  position: sticky;
  top: 0;
  z-index: 4;
  min-height: 42px;
  background: var(--surface-soft);
  color: var(--muted);
  text-transform: uppercase;
}

.capacity-cell.header strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.capacity-cell.header.summary-header {
  color: var(--accent);
  font-size: 13px;
}

.capacity-vehicle-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
}

.capacity-vehicle-toggle input {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.capacity-cell.vehicle-disabled {
  background: #f3f5f3;
  color: #a2aaa4;
}

.capacity-cell.header.vehicle-disabled {
  opacity: 0.58;
}

.capacity-cell.vehicle-disabled:not(.header) {
  background:
    repeating-linear-gradient(
      -45deg,
      #f5f6f5 0,
      #f5f6f5 7px,
      #ecefec 7px,
      #ecefec 8px
    );
}

.capacity-cell.header span {
  display: block;
  margin-top: 2px;
  color: var(--accent);
  font-size: 11px;
  line-height: 1;
}

.capacity-cell.time {
  position: sticky;
  left: var(--capacity-column-width);
  z-index: 3;
  justify-content: end;
  align-content: center;
  padding-right: 8px;
  background: #f8faf8;
  color: var(--muted);
}

.capacity-cell.date {
  position: sticky;
  left: 0;
  z-index: 4;
  align-content: start;
  padding: 9px 6px 0;
  background: #f8faf8;
  color: var(--accent);
  font-size: 11px;
  line-height: 1.1;
  text-align: center;
  text-transform: uppercase;
}

.capacity-cell.time.hour {
  color: var(--ink);
  font-size: 11px;
  font-weight: 400;
}

.capacity-cell.time.hour-block {
  min-height: calc(var(--capacity-row-height) * 2);
}

.capacity-cell.time.hour-block.time-excluded-first {
  background: linear-gradient(to bottom, #fff0f0 0 50%, #f8faf8 50% 100%);
}

.capacity-cell.time.hour-block.time-excluded-second {
  background: linear-gradient(to bottom, #f8faf8 0 50%, #fff0f0 50% 100%);
}

.capacity-cell.time.hour-block.time-excluded-first.time-excluded-second {
  background: #fff0f0;
}

.capacity-cell.day-start {
  border-top: 2px solid var(--accent);
}

.capacity-cell.occupied {
  background: #ffffff;
  color: #17201b;
}

.capacity-cell.overcapacity {
  background: #ffffff;
  color: #8d2424;
}

.capacity-cell.header.overcapacity {
  background: #f9e4e4;
}

.capacity-cell.trip-block::before {
  content: "";
  position: absolute;
  inset: 0 4px;
  z-index: 0;
  background: #d9dada;
}

.capacity-cell.overcapacity.trip-block::before {
  background: #f3d3d3;
}

.capacity-cell.trip-start::before,
.capacity-cell.trip-single::before {
  top: 3px;
  border-radius: 5px 5px 0 0;
}

.capacity-cell.trip-end::before,
.capacity-cell.trip-single::before {
  bottom: 3px;
  border-radius: 0 0 5px 5px;
}

.capacity-cell.trip-single::before {
  border-radius: 5px;
}

.capacity-cell.trip-start::after,
.capacity-cell.trip-single::after {
  content: "";
  position: absolute;
  top: 8px;
  left: 9px;
  z-index: 1;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  opacity: 0.78;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.36);
}

.capacity-cell.route-json::after {
  background: #6f9f83;
}

.capacity-cell.route-haversine::after {
  background: #c7aa54;
}

.capacity-cell.route-default::after {
  background: #d9dada;
}

.capacity-cell.summary {
  font-weight: 500;
}

.capacity-cell.summary.empty {
  color: transparent;
}

.capacity-cell.summary.green {
  background: #55b63a;
  color: #12210f;
}

.capacity-cell.summary.yellow {
  background: #ffc400;
  color: #211b00;
}

.capacity-cell.summary.red {
  background: #ff1f1f;
  color: #ffffff;
}

.capacity-cell.alert {
  justify-content: start;
  padding: 0 10px;
  background: #ffffff;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.capacity-cell.alert.sedan {
  color: #9c6a00;
}

.capacity-cell.alert.van {
  color: var(--danger);
}

.capacity-cell.alert.combined {
  color: #9c6a00;
}

.capacity-cell.alert.overloaded {
  color: #ffffff;
  background: #a03333;
  font-weight: 900;
}

.capacity-cell.exclusion {
  background: #f8faf8;
}

.capacity-cell.header.exclusion {
  background: var(--surface-soft);
}

.capacity-cell.exclusion-header svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.capacity-cell.excluded-row {
  background: #fff0f0;
}

.capacity-cell.vehicle-disabled.excluded-row:not(.header) {
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(255, 255, 255, 0.18) 0,
      rgba(255, 255, 255, 0.18) 7px,
      rgba(237, 202, 202, 0.42) 7px,
      rgba(237, 202, 202, 0.42) 8px
    ),
    #fff0f0;
}

.capacity-cell.excluded-row.trip-block::before {
  background: #edcaca;
}

.capacity-cell.exclusion.selected {
  background: #f3b8b8;
}

.exclusion-toggle {
  width: 100%;
  height: 100%;
  min-height: var(--capacity-row-height);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.exclusion-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  opacity: 0;
  pointer-events: none;
}

.exclusion-toggle svg {
  width: 15px;
  height: 15px;
  color: #9da5a0;
  fill: none;
  opacity: 0.38;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition:
    color 0.15s ease,
    opacity 0.15s ease,
    transform 0.15s ease;
}

.capacity-cell.exclusion:hover .exclusion-toggle svg,
.exclusion-toggle:focus-within svg {
  opacity: 0.62;
}

.capacity-cell.exclusion.selected .exclusion-toggle svg {
  color: #9f2d2d;
  opacity: 1;
  transform: scale(1.06);
}

:root[data-theme="dark"] .capacity-board {
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

:root[data-theme="dark"] .alert-config-button,
:root[data-theme="dark"] .alert-config-panel {
  background: var(--surface);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.34);
}

:root[data-theme="dark"] .alert-config-button:hover,
:root[data-theme="dark"] .alert-config-button:focus-visible,
:root[data-theme="dark"] .alert-config-menu.is-open .alert-config-button,
:root[data-theme="dark"] .alert-config-option:hover,
:root[data-theme="dark"] .alert-config-option:focus-within {
  background: var(--surface-soft);
}

:root[data-theme="dark"] .capacity-cell,
:root[data-theme="dark"] .capacity-cell.occupied,
:root[data-theme="dark"] .capacity-cell.overcapacity,
:root[data-theme="dark"] .capacity-cell.alert {
  background: var(--lane-bg);
  color: var(--ink);
}

:root[data-theme="dark"] .capacity-cell.time,
:root[data-theme="dark"] .capacity-cell.date,
:root[data-theme="dark"] .capacity-cell.vehicle-disabled {
  background: var(--surface-soft);
}

:root[data-theme="dark"] .capacity-cell.time.hour-block.time-excluded-first {
  background: linear-gradient(to bottom, #3a2424 0 50%, var(--surface-soft) 50% 100%);
}

:root[data-theme="dark"] .capacity-cell.time.hour-block.time-excluded-second {
  background: linear-gradient(to bottom, var(--surface-soft) 0 50%, #3a2424 50% 100%);
}

:root[data-theme="dark"] .capacity-cell.time.hour-block.time-excluded-first.time-excluded-second {
  background: #3a2424;
}

:root[data-theme="dark"] .capacity-cell.vehicle-disabled {
  color: var(--muted-soft);
}

:root[data-theme="dark"] .capacity-cell.vehicle-disabled:not(.header) {
  background:
    repeating-linear-gradient(
      -45deg,
      #121c19 0,
      #121c19 7px,
      #1a2622 7px,
      #1a2622 8px
    );
}

:root[data-theme="dark"] .capacity-cell.header.overcapacity {
  background: var(--danger-soft);
}

:root[data-theme="dark"] .capacity-cell.trip-block::before {
  background: #384640;
}

:root[data-theme="dark"] .capacity-cell.overcapacity.trip-block::before {
  background: #5b3034;
}

:root[data-theme="dark"] .capacity-cell.overcapacity,
:root[data-theme="dark"] .capacity-cell.alert.van {
  color: var(--danger);
}

:root[data-theme="dark"] .capacity-cell.alert.sedan {
  color: var(--warn);
}

:root[data-theme="dark"] .capacity-cell.alert.overloaded {
  color: #ffffff;
  background: #8b3034;
}

:root[data-theme="dark"] .capacity-cell.summary.green {
  background: #4f8f3e;
  color: #07120f;
}

:root[data-theme="dark"] .capacity-cell.summary.yellow {
  background: #caa23b;
  color: #151100;
}

:root[data-theme="dark"] .capacity-cell.summary.red {
  background: #b33a35;
  color: #fff4f2;
}

:root[data-theme="dark"] .capacity-cell.alert.overloaded {
  background: #8f3936;
  color: #fff4f2;
}

:root[data-theme="dark"] .capacity-cell.alert.van,
:root[data-theme="dark"] .capacity-cell.alert.sedan {
  background: transparent;
  font-weight: 850;
}

:root[data-theme="dark"] .capacity-cell.exclusion {
  background: var(--surface-soft);
}

:root[data-theme="dark"] .capacity-cell.header.exclusion {
  background: var(--surface-soft);
}

:root[data-theme="dark"] .capacity-cell.excluded-row {
  background: #3a2424;
}

:root[data-theme="dark"] .capacity-cell.vehicle-disabled.excluded-row:not(.header) {
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(255, 255, 255, 0.04) 0,
      rgba(255, 255, 255, 0.04) 7px,
      rgba(99, 66, 66, 0.36) 7px,
      rgba(99, 66, 66, 0.36) 8px
    ),
    #3a2424;
}

:root[data-theme="dark"] .capacity-cell.excluded-row.trip-block::before {
  background: #634242;
}

:root[data-theme="dark"] .capacity-cell.exclusion.selected {
  background: #6b3a3a;
}

:root[data-theme="dark"] .exclusion-toggle svg {
  color: #87918b;
}

:root[data-theme="dark"] .capacity-cell.exclusion.selected .exclusion-toggle svg {
  color: #ffd7d7;
}

@media (max-width: 900px) {
  .capacity-grid {
    --capacity-column-width: 58px;
    min-width: 750px;
  }

}

@media (max-width: 900px) and (orientation: portrait) {
  body {
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .drivers-page {
    height: auto;
    min-height: 100svh;
    padding: 0;
    display: grid;
    grid-template-rows: auto auto;
    gap: 0;
    overflow: visible;
  }

  .drivers-topbar {
    display: none;
  }

  .mobile-page-header {
    width: 100%;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border: 0;
    border-radius: 0;
    background: var(--surface);
    box-shadow: 0 5px 14px rgba(23, 32, 27, 0.05);
  }

  .mobile-page-brand {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: var(--ink);
    font-size: 15px;
    font-weight: 850;
    line-height: 1.1;
    text-decoration: none;
  }

  .mobile-page-brand .brand-icon {
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
  }

  .mobile-page-brand .brand-icon svg {
    width: 18px;
    height: 18px;
  }

  .mobile-page-brand span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-menu-button {
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    display: grid;
    place-content: center;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
  }

  .mobile-menu-button span {
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
  }

  .mobile-navigation-menu {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--surface);
    color: var(--ink);
  }

  .mobile-navigation-menu:not([hidden]) {
    display: block;
  }

  .mobile-menu-panel {
    min-height: 100%;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    padding: max(18px, env(safe-area-inset-top)) 18px max(22px, env(safe-area-inset-bottom));
  }

  .mobile-menu-top {
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    color: var(--ink);
    font-size: 14px;
    font-weight: 900;
  }

  .mobile-menu-close {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
  }

  .mobile-menu-close svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .mobile-menu-links {
    display: grid;
    align-content: start;
    gap: 8px;
  }

  .mobile-menu-links a {
    display: flex;
    align-items: center;
    min-height: 52px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--ink);
    font-size: 22px;
    font-weight: 850;
    line-height: 1;
    text-decoration: none;
  }

  .mobile-menu-links a:focus-visible,
  .mobile-menu-links a:hover {
    border-color: var(--line);
    background: var(--surface-soft);
    outline: none;
  }

  .mobile-menu-links a.active {
    border-color: transparent;
    background: var(--accent-soft);
    color: var(--accent);
  }

  .capacity-shell {
    width: 100%;
    min-height: 0;
    gap: 6px;
    padding: 14px 8px 8px;
  }

  .drivers-heading {
    min-height: 22px;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .drivers-heading h2 {
    font-size: 18px;
  }

  .drivers-save-status {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10px;
    white-space: nowrap;
  }

  .capacity-heading-actions {
    max-width: min(68vw, 360px);
    gap: 6px;
  }

  .alert-config-button {
    height: 26px;
    gap: 4px;
    padding: 0 7px;
    border-radius: 6px;
    font-size: 10px;
  }

  .alert-config-count {
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 9px;
  }

  .alert-config-panel {
    width: 170px;
    max-width: calc(100vw - 16px);
  }

  .capacity-board {
    width: 100%;
    max-width: 100%;
    border: 0;
    border-radius: 6px;
    overflow: visible;
    box-shadow: none;
  }

  .capacity-grid {
    --capacity-row-height: 14px;
    --capacity-date-column-width: 22px;
    --capacity-time-column-width: 34px;
    --capacity-alert-column-width: clamp(59px, 16.5vw, 69px);
    --capacity-exclusion-column-width: 42px;
    --capacity-column-width: calc(var(--capacity-row-height) + 2px);
    min-width: 0;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
    font-size: 8px;
    font-weight: 800;
  }

  .capacity-cell {
    border-right-width: 0.5px;
    border-bottom-width: 0.5px;
  }

  .capacity-cell.header {
    min-height: 25px;
  }

  .capacity-cell.header strong {
    font-size: 9px;
  }

  .capacity-cell.header.summary-header {
    place-items: center;
    align-content: center;
    font-size: 10px;
    line-height: 1;
  }

  .capacity-cell.exclusion-header svg {
    width: 12px;
    height: 12px;
    color: var(--muted);
  }

  .exclusion-toggle svg {
    width: 12px;
    height: 12px;
  }

  .capacity-cell.exclusion,
  .exclusion-toggle {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
  }

  .capacity-cell.exclusion:active,
  .exclusion-toggle:active {
    background: transparent;
  }

  .capacity-vehicle-toggle {
    gap: 0;
    cursor: default;
  }

  .capacity-vehicle-toggle input {
    display: none;
  }

  .capacity-cell.date {
    padding: 5px 2px 0;
    font-size: 9px;
    line-height: 1;
  }

  .capacity-cell.time {
    padding-right: 3px;
  }

  .capacity-cell.time.hour {
    font-size: 8px;
  }

  .capacity-cell.trip-block::before {
    inset-inline: 2px;
  }

  .capacity-cell.trip-start::before,
  .capacity-cell.trip-single::before {
    top: 2px;
    border-radius: 3px 3px 0 0;
  }

  .capacity-cell.trip-end::before,
  .capacity-cell.trip-single::before {
    bottom: 2px;
    border-radius: 0 0 3px 3px;
  }

  .capacity-cell.trip-single::before {
    border-radius: 3px;
  }

  .capacity-cell.trip-start::after,
  .capacity-cell.trip-single::after {
    top: 4px;
    left: 5px;
    width: 5px;
    height: 5px;
  }

  .capacity-cell.alert {
    padding: 0 2px;
    font-size: 7px;
    line-height: 1;
    white-space: nowrap;
  }
}
