/* Responsive header protection: keep project, account and status controls separate. */
@media (max-width: 1280px) {
  header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas: "left" "notice" "right" !important;
    align-items: stretch !important;
    width: 100%;
  }

  .header-left {
    grid-area: left;
    min-width: 0;
    width: 100%;
  }

  .retention-notice {
    grid-area: notice;
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .header-right {
    grid-area: right;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    grid-template-areas: "group account" "status status" !important;
    width: 100%;
    min-width: 0;
    margin-left: 0;
    align-items: stretch;
  }

  .group-switcher.active,
  .account-tools.active,
  .status-pill {
    min-width: 0;
    width: 100%;
    max-width: none;
  }

  .group-switcher.active {
    grid-template-columns: minmax(0, 1fr) auto !important;
  }

  .group-custom-select {
    min-width: 0 !important;
    max-width: none !important;
    width: 100%;
  }

  .group-switcher .icon-btn {
    min-width: 64px;
    width: auto;
    height: 38px;
    min-height: 38px;
    padding: 0 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .group-select-btn,
  .account-name,
  .status-pill {
    min-width: 0;
    max-width: 100%;
  }

  .account-tools.active {
    justify-content: flex-end;
  }
}

/* At wider desktop widths, keep the project control from overflowing its grid cell. */
@media (min-width: 1281px) and (max-width: 1450px) {
  .header-right {
    grid-template-columns: minmax(0, 1fr) minmax(160px, auto) !important;
  }

  .group-switcher.active {
    grid-template-columns: minmax(0, 1fr) auto !important;
  }

  .group-custom-select {
    min-width: 0 !important;
    max-width: none !important;
    width: 100%;
  }

  .group-switcher .icon-btn {
    min-width: 64px;
    width: auto;
    min-height: 38px;
    height: 38px;
    padding: 0 8px;
    white-space: nowrap;
  }
}

/* Keep the desktop three-column workspace usable before the mobile breakpoint. */
@media (min-width: 1101px) and (max-width: 1280px) {
  main,
  #generateView,
  #generateView.assets-mode {
    grid-template-columns: minmax(190px, 240px) minmax(0, 520px) minmax(300px, 1fr) !important;
    width: calc(100vw - 32px) !important;
    max-width: none !important;
    min-width: 0 !important;
  }

  #generatePanel,
  #tasksPanel,
  #assetsColumn,
  #videoForm {
    min-width: 0 !important;
    max-width: 100% !important;
  }
}

@media (max-width: 640px) {
  header {
    padding: 12px !important;
    gap: 10px !important;
  }

  .header-left {
    display: grid;
    gap: 10px;
  }

  h1 {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    border-radius: 12px;
  }

  .nav-tabs button {
    min-width: 0;
    padding: 7px 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-right {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas: "group" "account" "status" !important;
  }

  .group-switcher.active,
  .account-tools.active {
    justify-content: stretch;
  }

  .account-tools.active {
    flex-wrap: wrap;
  }

  .account-name {
    flex: 1 1 120px;
  }

  .account-logout-btn {
    flex: 0 0 auto;
  }

  .status-pill {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.4;
  }
}
