/* Responsive layout — FLOWS.md → Responsive rules.
   Breakpoints from Figma "breakpoints": tablet 768 (breakpoint/width/tablet),
   laptop 1024 (breakpoint/width/laptop). @media can't read custom properties, so the
   numbers are repeated here. Desktop-first: these rules adapt down. */

/* ---------- Hidden on Desktop/Laptop ---------- */
.topbar,
.sidebar__toggle,
.nav-scrim,
.cell-label,
.leave-bar__short,
.cal-mobile { display: none; }

/* ---------- Balance cards: react to the space they have (Laptop "if too narrow, 2 + 2") ---------- */
.page-body { container-type: inline-size; }
/* Laptop: number above its label so narrow cards don't wrap mid-phrase */
@container (max-width: 1000px) {
  .balance-card__available { flex-direction: column; gap: 0; }
  .balance-card__head { flex-wrap: wrap; gap: 0 var(--ds-spacing-s); }
}
@container (max-width: 940px) {
  .balance-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container (max-width: 720px) {
  .balance-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container (max-width: 480px) {
  .balance-row,
  .balance-grid { grid-template-columns: minmax(0, 1fr); }
  /* One card per row again: number and label back on one line */
  .balance-card__available { flex-direction: row; gap: var(--ds-spacing-s); }
}

/* Laptop and below (< 1280): Note column hidden — it's in the edit drawer and the decline note */
@media (max-width: 1279px) {
  .th--note,
  .cell--note { display: none; }
}

/* =====================================================================
   Tablet and below: < 1024 (breakpoint/width/laptop)
   ===================================================================== */
@media (max-width: 1023px) {
  /* Sidebar: icons only; ☰ opens the full sidebar over the page */
  .shell { padding-left: 72px; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 15;
    width: 72px;
  }
  .sidebar:not(.is-open) { padding-inline: var(--ds-spacing-s); }
  .sidebar:not(.is-open) .sidebar__logo,
  .sidebar:not(.is-open) .sidebar__company,
  .sidebar:not(.is-open) .nav-link__label,
  .sidebar:not(.is-open) .sidebar__who { display: none; }
  .sidebar:not(.is-open) .sidebar__brand { justify-content: center; padding-inline: 0; }
  .sidebar:not(.is-open) .nav-group__title { padding: var(--ds-spacing-l) 0 var(--ds-spacing-xs); text-align: center; font-size: 0; }
  .sidebar:not(.is-open) .nav-group__title::after { content: ''; display: block; height: var(--ds-border-width-xxs); margin: 0 var(--ds-spacing-s); background: var(--ds-palette-border-low); }
  .sidebar:not(.is-open) .nav-link { justify-content: center; min-height: 44px; }
  .sidebar:not(.is-open) .sidebar__user { justify-content: center; padding-inline: 0; }
  .sidebar:not(.is-open) .sidebar__theme { display: flex; justify-content: center; padding-inline: 0; }
  .sidebar:not(.is-open) .sidebar__theme .segmented { flex-direction: column; } /* 72 px rail: stack the three icons */
  .sidebar:not(.is-open) .sidebar__nav { scrollbar-width: none; } /* rail is 72 px: no room for a scrollbar */
  .sidebar:not(.is-open) .sidebar__nav::-webkit-scrollbar { display: none; }

  .sidebar__toggle { display: inline-flex; margin-left: auto; color: var(--ds-palette-content-secondary); }
  .sidebar__toggle:hover { background: var(--ds-palette-interactive-hover); }
  .sidebar.is-open { width: 216px; box-shadow: var(--ds-shadow-md); }
  .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 14;
    background: var(--ds-ref-colour-transparent-grey-35);
  }

  /* Touch targets ≥ 44px */
  .icon-btn--touch { width: 44px; height: 44px; }
  .row-menu__trigger { position: relative; opacity: 1; }
  .row-menu__trigger::before { content: ''; position: absolute; inset: -10px; }

  .page { padding: var(--ds-spacing-xl); }


  /* Calendar: short bar labels "Annual · Pending" */
  .leave-bar__full { display: none; }
  .leave-bar__short { display: inline; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* =====================================================================
   Mobile: < 768 (breakpoint/width/tablet)
   ===================================================================== */
@media (max-width: 767px) {
  /* Top bar instead of the sidebar; menu opens full-height */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 12;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--ds-spacing-xs) var(--ds-spacing-l);
    border-bottom: var(--ds-border-width-xxs) solid var(--ds-palette-border-low);
    background: var(--ds-palette-background-primary);
    color: var(--ds-palette-content-primary);
  }
  .topbar__brand { display: flex; align-items: center; gap: 10px; }
  .topbar__menu { color: var(--ds-palette-content-secondary); }
  .topbar__menu:hover { background: var(--ds-palette-interactive-hover); }

  .shell { padding-left: 0; }
  .sidebar:not(.is-open) { display: none; }
  .sidebar.is-open { width: 100%; box-shadow: none; }
  .nav-scrim { display: none; }

  /* Page */
  .page { padding: var(--ds-spacing-l); gap: var(--ds-spacing-2xl); }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-title .t-H1 { /* H1 → H2 on Mobile */
    font: var(--ds-font-h2-weight) var(--ds-font-h2-size)/var(--ds-font-h2-line-height) var(--ds-font-h2-family);
  }
  .page-head .btn--primary { width: 100%; }

  /* Requests toolbar: search gets its own row (decision: phone toolbar) */
  .table-toolbar { flex-wrap: wrap; }
  .input--search { width: 100%; }
  .history-head { flex-wrap: wrap; }

  .history { padding: var(--ds-spacing-m); gap: var(--ds-spacing-2xl); }
  .history-head { flex-direction: column; align-items: flex-start; gap: var(--ds-spacing-s); }

  /* Requests table stays a table on phones and scrolls sideways (decision 23 Nov) */
  .requests-table { min-width: 600px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .cell--type,
  .th:first-child { position: sticky; left: 0; z-index: 1; background-color: var(--ds-palette-background-primary); }
  .th:first-child { background-color: var(--ds-palette-background-secondary); }
  /* Decline note stays readable inside the visible width while the table scrolls */
  .decline-note { position: sticky; left: var(--ds-spacing-m); width: calc(100vw - 4 * var(--ds-spacing-l)); flex-wrap: wrap; }
  .decline-note__msg { flex-basis: calc(100% - 32px); }
  .decline-note__action { margin-left: 32px; }
  .row-menu__trigger { width: 44px; height: 44px; }

  /* Balances on phones: Annual + Sick only; the rest live behind "View all 12 types" */
  .balance-card--phone-hidden { display: none; }
  .balance-card__other-desc--wide { display: none; }
  .balance-card__other-desc--phone { display: block; }

  /* Calendar: compact grid with dots + list of the month's leave */
  .cal__grid { display: none; }
  .cal-mobile { display: flex; flex-direction: column; gap: var(--ds-spacing-l); }
  .cal__toolbar { flex-wrap: wrap; }

  /* Dialog → bottom sheet; buttons stacked, danger action first */
  .dialog-root { align-items: flex-end; padding: 0; }
  .dialog {
    width: 100%;
    max-height: 90vh;
    border-radius: var(--ds-border-radius-l) var(--ds-border-radius-l) 0 0;
    padding: var(--ds-spacing-l);
  }
  .dialog__actions { flex-direction: column-reverse; }
  .dialog__actions .btn { width: 100%; }

  /* Toasts: full width at the top */
  .toasts { left: var(--ds-spacing-l); right: var(--ds-spacing-l); width: auto; transform: none; top: var(--ds-spacing-l); }
}

/* ---------- Mobile calendar pieces ---------- */
.cal-mobile__grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  row-gap: var(--ds-spacing-xxs);
  text-align: center;
}
.cal-mobile__wd { padding: var(--ds-spacing-xs) 0; color: var(--ds-palette-content-secondary); }
.cal-mday {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--ds-spacing-xxs);
  min-height: 44px;
  padding: var(--ds-spacing-xs) 0;
  border: 0;
  border-radius: var(--ds-border-radius-m);
  background: none;
  color: var(--ds-palette-content-primary);
}
button.cal-mday { cursor: pointer; }
button.cal-mday:hover { background: var(--ds-palette-interactive-hover); }
.cal-mday.is-outside { color: var(--ds-palette-content-tertiary); }
.cal-mday__num { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; }
.cal-mday__num.is-today { border: var(--ds-border-width-xxs) solid var(--ds-palette-border-brand); border-radius: var(--ds-border-radius-m); }
.cal-mday__dots { display: flex; gap: var(--ds-spacing-xxs); height: 6px; }
.cal-dot { width: 6px; height: 6px; border-radius: var(--ds-border-radius-full); }
.cal-dot--approved { background: var(--ds-palette-content-success); }
.cal-dot--pending { background: var(--ds-palette-content-alert); }
.cal-dot--declined { background: var(--ds-palette-content-error); }

.cal-mobile__list { display: flex; flex-direction: column; gap: var(--ds-spacing-s); margin: 0; padding: 0; list-style: none; }
.cal-mobile__empty { color: var(--ds-palette-content-tertiary); }
.cal-item {
  display: flex;
  flex-direction: column;
  gap: var(--ds-spacing-xxs);
  width: 100%;
  padding: var(--ds-spacing-m);
  border: var(--ds-border-width-xxs) solid transparent;
  border-radius: var(--ds-border-radius-m);
  color: var(--ds-palette-content-primary);
  text-align: left;
}
button.cal-item { cursor: pointer; font: inherit; }
.cal-item__head { display: flex; align-items: center; gap: var(--ds-spacing-xs); }
.cal-item__hint { color: var(--ds-palette-content-tertiary); }
.cal-item--approved { background: var(--ds-palette-background-success-low); }
.cal-item--approved .cal-item__head { color: var(--ds-palette-content-success); }
.cal-item--pending { background: var(--ds-palette-background-alert-low); }
.cal-item--pending .cal-item__head { color: var(--ds-palette-content-alert); }
.cal-item--declined { background: var(--ds-palette-background-error-low); }
.cal-item--declined .cal-item__head { color: var(--ds-palette-content-error); }
@keyframes item-flash { from { box-shadow: 0 0 0 var(--ds-border-width-xs) var(--ds-palette-border-brand); } }
.cal-item.is-flash,
li.is-flash > .cal-item { animation: item-flash 1.5s ease-out; }

/* ---------- Feedback 23 Nov (phones) ---------- */
@media (max-width: 767px) {
  /* Annual + Sick + Other fit in one row on larger phones */
  .balance-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }

  /* Scrolling table: fixed pixel widths so headers keep room for their filter / sort icons */
  .requests-table { min-width: 760px; }
  .th--type { width: 160px; }
  .th--status { width: 150px; }
  .th--dates { width: 180px; }
  .th--duration { width: 130px; }
  .th--updated { width: 140px; }
  .th__filter { width: 32px; height: 32px; margin: -6px 0; }
}
@container (max-width: 460px) {
  .balance-row { grid-template-columns: minmax(0, 1fr); }
}
