/* Calendar base refinements. Loaded after design-system.css.
   Keep Calendar's existing DOM, handlers, and scroll model intact. */
/* The form body scrolls; its clipped date card must retain its natural height.
   Otherwise flex shrink collapses the card and hides All day, Starts, and Ends. */
body.workspace-design .cal-pop-body > .cal-card {
  flex-shrink: 0;
}
/* Native date/time segments need the full sheet width to show AM/PM. */
body.workspace-design .cal-pop .cal-when-grid {
  grid-template-columns: 1fr;
}

@media (max-width: 760px) {
  body.workspace-design[data-module="calendar"] .cal-header {
    display: flex;
    align-items: stretch;
    gap: 6px 8px;
    padding: 4px 2px 8px;
  }

  /* Keep date movement first; bring view choice ahead of the action rail. */
  body.workspace-design[data-module="calendar"] .cal-header .cal-hl {
    order: 1;
    flex: 1 0 100%;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
    min-height: 44px;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-nav-arrows,
  body.workspace-design[data-module="calendar"] .cal-header .cal-today {
    flex: 0 0 auto;
    min-height: 44px;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-range {
    flex: 1 1 auto;
    min-width: 0;
    padding-left: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    line-height: 1.3;
  }

  body.workspace-design[data-module="calendar"] .cal-header .cal-hc {
    order: 2;
    flex: 1 0 100%;
    justify-content: flex-start;
    align-content: center;
    align-items: center;
    gap: 5px 7px;
    margin: 0;
    min-width: 0;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-seg {
    flex: 1 0 100%;
    min-height: 44px;
    justify-content: stretch;
    padding: 2px;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-seg-btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 6px 7px;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-rpicker-btn,
  body.workspace-design[data-module="calendar"] .cal-header .cal-mobile-owner,
  body.workspace-design[data-module="calendar"] .cal-header .cal-mobile-owner button {
    min-height: 44px;
  }

  /* Main task tools stay together in one swipeable row. The primary action,
     searchable field, and daily sheet lead; the visible scrollbar signals more. */
  body.workspace-design[data-module="calendar"] .cal-header .cal-hr {
    order: 3;
    flex: 1 0 100%;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    min-width: 0;
    margin: 0;
    padding: 0 0 3px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--ws-muted) transparent;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-hr > * {
    flex: 0 0 auto;
    min-height: 44px;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-new {
    order: 0;
    min-width: 96px;
    padding: 6px 8px;
    font-size: 11.5px;
    white-space: nowrap;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-new span {
    display: inline;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-search {
    order: 1;
    flex: 0 0 142px;
    width: 142px;
    height: 44px;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-daily-sheet {
    order: 2;
    padding-inline: 8px;
    font-size: 11.5px;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-export { order: 3; }
  body.workspace-design[data-module="calendar"] .cal-header .cal-zoom-btns { order: 4; }
  body.workspace-design[data-module="calendar"] .cal-header .cal-kbd-help-btn {
    order: 5;
    display: inline-flex;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-chip { order: 6; }

  body.workspace-design[data-module="calendar"] .cal-header .cal-hr::-webkit-scrollbar {
    height: 4px;
  }
  body.workspace-design[data-module="calendar"] .cal-header .cal-hr::-webkit-scrollbar-thumb {
    background: var(--ws-muted);
    border-radius: 999px;
  }
}
