/*
 * Responsible for: how the Inbox overview lays out the kit's pieces: its title, the switch and the
 * path above the Map, the Map's box, the colour breakdown, "Add a new folder" and, in its row, the buttons that steer
 * a live reading, the list of folders beside it, and the panels that open from the Map and the breakdown.
 *
 * Must never: restyle a kit piece from here, or give a part of the screen a size that depends on what is inside it.
 * A reading, a change of Map, a change of folder and a switch of tabs all change what a part shows; none of them may
 * move a part.
 */

@layer screens {
  .ia-overview {
    display: flex;
    flex-direction: column;
    gap: var(--s-4);
    padding: var(--s-4);
  }

  .ia-overview__main {
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    min-width: 0;
  }

  .ia-overview__head {
    position: relative;
    padding-bottom: var(--s-2);
  }

  /* A long title ends in "..." on a narrow screen, so it is cut sideways. It is never cut at the bottom: in Palatino Linotype, the
     serif Windows uses, a letter like the g of "sorting" reaches below a 1.25 line, and overflow: hidden cut it off (Grant, 9 Nov 2026). */
  .ia-overview__title {
    overflow-x: clip;
    overflow-y: visible;
    font: 400 var(--t-xl) / 1.25 var(--serif);
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  /* The switch, then the path, then the buttons for the folder on show: one row on a laptop, three rows on a phone. */
  .ia-overview__path {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    min-width: 0;
  }

  .ia-overview__view-actions {
    display: flex;
    flex: 0 0 auto;
    gap: var(--s-1);
    margin-left: auto;
  }

  /* The trail sits directly above the Map at every level: its height never changes, so the Map never moves. */
  .ia-overview__trail {
    min-width: 0;
    margin-bottom: calc(var(--s-2) * -1);
  }

  /* While there is no path, its room says what the Map is for. It takes no room of its own. */
  .ia-overview__hint {
    flex: 0 1 auto;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: var(--t-sm);
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .ia-overview__view-actions[data-shown='false'] {
    visibility: hidden;
  }

  /*
   * At the top there is no folder to change, so the buttons are hidden. On a laptop they keep their height but give up their
   * width, so the hint beside the switch has the room they would take and is never cut short.
   */
  @media (min-width: 601px) {
    .ia-overview__view-actions[data-shown='false'] {
      max-width: 0;
      overflow: hidden;
    }
  }

  /* On a phone the buttons sit under the path: side by side they leave the folder's own name a few pixels. */
  @media (max-width: 600px) {
    .ia-overview__path {
      position: relative;
      flex-direction: column;
      align-items: stretch;
      gap: 0;
    }

    /* On a phone the buttons are a row under the switch: at the top the hint stands in that row instead. */
    .ia-overview__hint {
      position: absolute;
      right: 0;
      bottom: 0;
      left: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      height: var(--tap);
      white-space: normal;
      text-align: center;
    }

    /* Where no change is offered there are no buttons: the row is kept for the hint, so nothing moves. */
    .ia-overview__path[data-actions='false'] {
      padding-bottom: var(--tap);
    }

    .ia-overview__view-actions {
      margin-left: 0;
    }
  }

  .ia-overview__map {
    position: relative;
    height: 360px;
    min-height: 0;
  }

  /* An empty inbox: the Map's box keeps its size and says so in its middle. */
  .ia-overview__empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: var(--s-5);
    color: var(--muted);
    font: 400 var(--t-lg) / 1.4 var(--serif);
    text-align: center;
    pointer-events: none;
  }

  .ia-overview__side {
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    min-width: 0;
  }

  .ia-overview__side-title {
    font: 600 var(--t-md) / 1.4 var(--sans);
  }

  /* While a reading plays, only the Map fills: the parts that describe the finished Map wait, in their places. */
  .ia-overview__breakdown,
  .ia-overview__side,
  .ia-overview__trail,
  .ia-overview__path {
    transition: opacity var(--slow) var(--ease);
  }

  /*
   * On a laptop the colour chips wrap onto rows, and a live reading brings its folders one page after another. Room for
   * three rows (a whole mailbox's areas) is always kept, so the Map's height never changes as folders appear.
   */
  @media (min-width: 601px) {
    .ia-overview__breakdown {
      min-height: calc(var(--s-2) * 3 + (var(--s-5) + var(--s-1)) * 3 + var(--s-1) * 2 + var(--t-sm) * 1.4);
    }
  }

  /* The row keeps its height when the button is not offered (the inbox's Map), so the Map above never moves. */
  .ia-overview__add {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s-2) var(--s-4);
    min-height: var(--tap);
    transition: opacity var(--slow) var(--ease);
  }

  .ia-overview[data-state='reading'] .ia-overview__breakdown,
  .ia-overview[data-state='reading'] .ia-overview__side,
  .ia-overview[data-state='reading'] .ia-overview__add,
  .ia-overview[data-state='reading'] .ia-overview__trail,
  .ia-overview[data-state='reading']:not([data-live='true']) .ia-overview__path,
  .ia-overview[data-live='true'] .ia-overview__path > :not(.ia-overview__steer) {
    visibility: hidden;
    opacity: 0;
  }

  /*
   * Under a laptop's width the parts that describe the finished Map stand below it, in one column: while a reading plays
   * they take no room, so no long empty card hangs under the Map. They come back at its foot when it ends, and nothing
   * above them moves. On a laptop they keep their places: the Map fills the height left to it and would change size.
   */
  @media (max-width: 899px) {
    .ia-overview[data-state='reading'] .ia-overview__breakdown,
    .ia-overview[data-state='reading'] .ia-overview__side,
    .ia-overview[data-state='reading'] .ia-overview__add {
      display: none;
    }
  }

  /* The buttons that steer a live reading stand where the path stands, which a reading keeps empty, so they are in sight at the top and nothing moves. */
  .ia-overview__path {
    position: relative;
  }

  .ia-overview__steer {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    flex-wrap: nowrap;
    gap: var(--s-2);
  }

  /* After a reading was stopped, "Start over" stands beside "Add a new folder". */
  .ia-overview__again {
    margin-left: auto;
  }

  .ia-overview__steer .ia-btn,
  .ia-overview__again .ia-btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* While a mailbox is read, the bar shows it is working: a soft light runs along what has been filled, and the fill glides to each new count. */
  .ia-overview[data-live='true'] .ia-overview__bar-fill {
    position: relative;
    overflow: hidden;
    transition-duration: var(--slow);
  }

  .ia-overview[data-running='true'] .ia-overview__bar-fill::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, var(--pop), transparent);
    opacity: 0.7;
    transform: translateX(-100%);
    animation: ia-bar-life 1.4s linear infinite;
  }

  @keyframes ia-bar-life {
    to {
      transform: translateX(100%);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .ia-overview[data-running='true'] .ia-overview__bar-fill::after {
      animation: none;
      transform: none;
      opacity: 0;
    }
  }

  @media (min-width: 900px) {
    .ia-overview {
      display: grid;
      grid-template-columns: minmax(0, 1fr) 21rem;
      gap: var(--s-5);
      padding: var(--s-4) var(--s-5);
    }

    .ia-overview__main,
    .ia-overview__side {
      min-height: 0;
    }

    .ia-overview__main {
      gap: var(--s-2);
    }

    .ia-overview__head {
      display: flex;
      align-items: center;
      gap: var(--s-5);
    }

    /* One width for all three of its wordings, so the words beside it stand still when a reading ends or the Map changes. 14em
       holds the longest ("Reading and sorting your mail") whole in the widest serif of the stack: Palatino Linotype and Georgia on
       Windows run 10 to 15% wider than the Times-width serif of a build machine, and 12em ended it in "your..." (Grant, 9 Nov 2026).
       min-width: 0 keeps the box at that width whatever the font, so a wider one ends in "..." and never pushes the words beside it. */
    .ia-overview__title {
      flex: 0 0 14em;
      min-width: 0;
      font-size: var(--t-2xl);
    }

    .ia-overview__map {
      flex: 1 1 0;
      height: auto;
      min-height: 180px;
    }

    .ia-overview__list {
      flex: 1 1 0;
      min-height: 0;
    }
  }

  /* In a narrower window the words have too little room beside the title: they go under it, in the same box in every state. */
  @media (min-width: 900px) and (max-width: 1439px) {
    .ia-overview__head {
      display: block;
    }

    .ia-overview__title {
      font-size: var(--t-xl);
    }
  }

  /* The panels of the overview */
  .ia-panel {
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    width: min(20rem, 100%);
    padding: var(--s-4);
  }

  .ia-panel__title {
    padding-left: var(--s-3);
    border-left: 4px solid var(--c, var(--accent));
    font: 600 var(--t-lg) / 1.3 var(--sans);
    overflow-wrap: anywhere;
  }

  .ia-panel__under {
    margin-top: var(--s-1);
    color: var(--muted);
    font-size: var(--t-sm);
    overflow-wrap: anywhere;
  }

  .ia-panel__facts {
    display: grid;
    gap: var(--s-1);
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--t-sm);
  }

  .ia-panel__link {
    color: var(--accent);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
  }

  .ia-panel__said,
  .ia-panel__shows {
    display: block;
    margin-top: var(--s-1);
    color: var(--muted);
  }

  .ia-panel__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
  }
}
