/* Lecture files: a subject's Files section for its staff and the "Add files"
   panel of a lecture's pages (owner, 2026-11-13; boards F2-LecturerFiles,
   F2-LectureAddFiles).

   Loaded after subjects.css (templates/base.html). Only rules in the declared
   layers, only tokens, only logical properties (tests/test_css_stylesheets.py,
   tests/test_css_rules.py, tests/ui/test_css_logical.py). */

@layer components {
  /* ------------------------------------------------------ The drop zone
     A dashed box: the words, then "Add files". Files can be dropped on it
     with a mouse; on a phone it is simply where the button is. */
  .file-page {
    margin-block-start: var(--space-5);
  }

  .file-drop {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-4) var(--space-5);
    padding: var(--space-5) var(--space-6);
    border: 2px dashed var(--attend-border-strong);
    border-radius: var(--r-lg);
    background: var(--attend-surface);
  }

  .file-drop[data-over] {
    border-color: var(--attend-brand-text);
    background: var(--attend-brand-tint);
  }

  .file-drop__icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    inline-size: 48px;
    block-size: 48px;
    border-radius: 50%;
    background: var(--attend-brand-tint);
    color: var(--attend-brand-text);
  }

  .file-drop__text {
    flex: 1 1 360px;
    min-inline-size: 0;
  }

  .file-drop__title {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

  /* The week new files go to: its own line under the words and the button. */
  .file-drop__week {
    flex: 1 1 100%;
    max-inline-size: 28rem;
    margin: 0;
  }

  /* What went wrong with a file, one line each. */
  .file-errors {
    display: grid;
    gap: var(--space-1);
    margin-block-start: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--r-md);
    background: var(--attend-danger-bg);
    color: var(--attend-danger-text);
    font-size: var(--text-small);
    list-style: none;
    overflow-wrap: anywhere;
  }

  /* ------------------------------------------- The list and its space line */
  .file-section {
    margin-block-start: var(--space-6);
  }

  .file-section__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-5);
    margin-block-end: var(--space-3);
  }

  .file-section__title {
    font-size: var(--text-body);
  }

  .file-usage {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .file-usage__bar {
    flex: none;
    inline-size: 160px;
  }

  /* ---------------------------------------------------------- A file's row */
  .file-table td {
    padding-block: var(--space-3);
  }

  .file-table__status {
    inline-size: 210px;
  }

  .file-table__link {
    inline-size: 250px;
  }

  .file-table__actions {
    inline-size: 240px;
  }

  .file-cell {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-inline-size: 0;
  }

  .file-cell__text {
    min-inline-size: 0;
  }

  .file-cell__name {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
    overflow-wrap: anywhere;
  }

  .file-tile {
    min-inline-size: 44px;
    font-size: var(--text-label);
  }

  .file-status__bar {
    display: block;
    margin-block-start: var(--space-2);
  }

  .file-status__detail {
    margin-block-start: var(--space-1);
  }

  /* "Checking…": the ring turns (reduced motion stops it, app.css). */
  .status[data-status="file_checking"] .icon {
    animation: attend-spin 0.9s linear infinite;
  }

  .file-link {
    inline-size: 100%;
    font-size: var(--text-small);
  }

  .file-actions {
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: var(--space-1);
  }

  .file-actions .btn--plain {
    flex: none;
    padding-inline: var(--space-2);
    white-space: nowrap;
  }

  /* ------------------------------------- "Add files" on a lecture's pages
     The tool's buttons sit in the page's row of tools; its panel is a dialog. */
  .file-tool {
    display: contents;
  }

  .file-panel {
    width: min(520px, calc(100vw - 2 * var(--space-4)));
  }

  .file-panel__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .file-panel .file-errors {
    margin-block-start: 0;
  }

  .file-row {
    flex-wrap: nowrap;
    align-items: flex-start;
    justify-content: flex-start;
  }

  .file-row__body {
    flex: 1 1 0;
    min-inline-size: 0;
  }

  .file-row .file-status {
    margin-block-start: var(--space-2);
  }

  @media (max-width: 640px) {
    .file-drop {
      padding: var(--space-4);
    }

    .file-usage {
      flex-wrap: wrap;
    }

    .file-actions {
      flex-wrap: wrap;
    }
  }

  /* ------------------------------- A subject's Files section for the student
     (boards F2-TabsIcons, F2-FilesSelect): files by week; the whole row is the
     file's download, or, in Select mode, its tick box. */
  .file-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .file-head .section-label {
    margin: 0;
  }

  .file-head__tools {
    display: flex;
    flex: none;
    align-items: center;
    gap: var(--space-2);
  }

  .file-head__picked {
    color: var(--attend-text-strong);
    font-size: var(--text-small);
    font-weight: var(--weight-strong);
  }

  .file-select {
    flex: none;
    padding-inline: var(--space-3);
    margin-inline-end: calc(var(--space-3) * -1);
    white-space: nowrap;
  }

  .file-progress {
    margin-block-end: var(--space-2);
  }

  /* Cancel and "Share now" under the status line, on iPhone and iPad (ios-save.js). */
  .file-progress__button {
    margin-block-end: var(--space-3);
  }

  .file-group + .file-group {
    margin-block-start: var(--space-5);
  }

  .file-group__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-block-end: var(--space-2);
  }

  .file-group__text {
    min-inline-size: 0;
  }

  .file-group__head .history-course {
    margin: 0;
  }

  .file-group__meta {
    color: var(--attend-text-muted);
    font-size: var(--text-small);
    line-height: var(--leading-small);
  }

  /* "Download all": a link in look, a button in kind (it starts downloads). */
  .file-all {
    flex: none;
    gap: var(--space-1);
    padding: 0;
    border: 0;
    background: none;
    font-family: inherit;
    cursor: pointer;
  }

  .file-pick-all {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: var(--space-2);
    min-block-size: var(--touch);
    color: var(--attend-brand-text);
    font-size: var(--text-small);
    font-weight: var(--weight-strong);
    cursor: pointer;
  }

  .file-list {
    margin-block: 0;
  }

  .student-file {
    align-items: center;
  }

  .student-file .file-tile,
  .class-files .file-tile {
    min-inline-size: 48px;
  }

  .file-row__name {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
    overflow-wrap: anywhere;
  }

  .file-row__name a {
    color: inherit;
    text-decoration: none;
  }

  .file-row__name label {
    cursor: pointer;
  }

  /* The whole row is the target (the row is positioned: components.css). */
  .file-row__name a::after,
  .file-row__name label::after {
    content: "";
    position: absolute;
    inset: 0;
  }

  .file-row__pick {
    display: grid;
    flex: none;
    place-items: center;
    inline-size: var(--touch);
    block-size: var(--touch);
    margin-inline: calc(var(--space-3) * -1);
  }

  .file-row__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
  }

  .file-mark {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-block-size: 24px;
    padding-inline: var(--space-2);
    border-radius: var(--r-pill);
    background: var(--attend-info-bg);
    color: var(--attend-info-text);
    font-size: var(--text-label);
    font-weight: var(--weight-strong);
    line-height: var(--leading-label);
    white-space: nowrap;
  }

  .file-mark .icon {
    inline-size: 14px;
    block-size: 14px;
  }

  .file-row__get {
    flex: none;
    color: var(--attend-brand-text);
  }

  /* Share (owner, 2026-11-15): built by static/js/materials/share.js only
     where the phone can share the file. The holder adds no box: its buttons
     sit in the row beside the download (above the whole-row link), and its
     line of news takes a line of its own under them, so "Preparing the
     file…" never squeezes the file's name. Hidden in Select mode. */
  .file-share {
    display: contents;
  }

  .file-share .btn--plain {
    position: relative;
    z-index: 1;
    flex: none;
    padding-inline: var(--space-2);
    white-space: nowrap;
  }

  .file-share__note {
    flex-basis: 100%;
    order: 1;
    color: var(--attend-text-muted);
    font-size: var(--text-meta);
    line-height: var(--leading-label);
    text-align: end;
  }

  .student-file,
  .class-files__row,
  .file-actions:has(.file-share__note:not(:empty)) {
    flex-wrap: wrap;
  }

  .file-share__note:empty,
  [data-selecting] .file-share {
    display: none;
  }

  /* A student's phone: Share is its icon beside the download icon (its name,
     "Share <file>", stays for screen readers), so the file's name keeps the room. */
  @media (max-width: 480px) {
    .student-file .file-share [data-share-text],
    .class-files__row .file-share [data-share-text] {
      position: absolute;
      inline-size: 1px;
      block-size: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }

    .student-file .file-share .btn--plain,
    .class-files__row .file-share .btn--plain {
      justify-content: center;
      min-inline-size: var(--touch);
      padding-inline: 0;
    }
  }

  /* Select mode's bar: stays in sight above the phone's tab bar. */
  .file-bar {
    position: sticky;
    inset-block-end: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-block-start: var(--space-5);
    margin-inline: calc(var(--space-5) * -1);
    padding: var(--space-3) var(--space-5);
    border-block-start: 1px solid var(--attend-border);
    background: var(--attend-surface);
  }

  /* Phones: the tab bar is fixed over the page's end (app.css, below 768px). */
  @media (max-width: 767px) {
    .shell--bottom-nav .file-bar {
      inset-block-end: var(--bottom-nav-room);
    }
  }

  .file-bar__text {
    min-inline-size: 0;
  }

  .file-bar__total {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

  .file-bar__note {
    color: var(--attend-text-muted);
    font-size: var(--text-meta);
    line-height: var(--leading-label);
  }

  .file-bar .btn {
    flex: none;
  }

  /* --------------------------- A lecture's files on its class card of Today
     (board F2-TodayFilesA): one line, open on the current class. */
  .class-files {
    margin-block-start: var(--space-4);
    border-block-start: 1px solid var(--attend-hero-border);
  }

  .class-files__summary {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

  .class-files__summary > .icon {
    color: var(--attend-brand-text);
  }

  .class-files__summary > span {
    flex: 1 1 auto;
  }

  .class-files__list {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .class-files__row {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-block-size: 56px;
    padding-block: var(--space-2);
    border-block-start: 1px solid var(--attend-hero-border);
  }

  .class-files .file-tile {
    background: var(--attend-surface);
  }

  /* "Update the app to open files" (board F2-UpdateApp): the Android app
     before 1.2.4 cannot save a file. A bottom sheet on phones, as every dialog. */
  .update-app__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .update-app__actions {
    flex-direction: column;
    align-items: stretch;
    margin-block-start: var(--space-2);
  }

  /* "The download did not start. Try again." after Download with Chrome;
     takes no room while it says nothing. */
  .update-app__note {
    margin: 0;
    color: var(--attend-danger-text);
  }

  .update-app__note:empty {
    display: none;
  }

  /* Saved on this phone (owner, 2026-11-16/17; static/js/materials/kept-rows.js):
     the mark is positive text with its icon, no pill; the line of news
     ("Saving… 40%") takes a line of its own under the row, as Share's does;
     Cancel sits beside Share. The hint is one line for a Safari tab. */
  .file-kept {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--attend-positive-text);
    font-size: var(--text-label);
    font-weight: var(--weight-strong);
    line-height: var(--leading-label);
    white-space: nowrap;
  }

  .file-kept .icon {
    inline-size: 14px;
    block-size: 14px;
  }

  .file-kept__cancel {
    position: relative;
    z-index: 1;
    flex: none;
    padding-inline: var(--space-2);
    white-space: nowrap;
  }

  .file-kept__news {
    flex-basis: 100%;
    order: 1;
    margin: 0;
    color: var(--attend-text-muted);
    font-size: var(--text-meta);
    line-height: var(--leading-label);
    text-align: end;
  }

  .file-kept-hint {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  [data-selecting] .file-kept__cancel,
  [data-selecting] .file-kept__news {
    display: none;
  }
  /* Saved files (/s/files/saved/) and the offline list (owner, 2026-11-16/17;
     static/js/materials/kept-page.js, kept-offline.js, kept-render.js): the
     totals with a bar on the progress track, a group per subject as the Files
     section's weeks, the name as the row's button (the whole row opens it),
     Remove beside it, and the chips as the row's other marks. */
  .file-kept-link {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    margin-block: 0 var(--space-3);
  }

  .file-kept-link a {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-block-size: var(--touch);
    font-weight: var(--weight-strong);
  }

  .kept-summary {
    display: grid;
    gap: var(--space-2);
    margin-block-end: var(--space-5);
  }

  .kept-summary p {
    margin: 0;
  }

  .kept-summary__total {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

  .kept-summary__bar {
    display: block;
    inline-size: 100%;
    block-size: 8px;
    border: 0;
    border-radius: var(--r-pill);
    background: var(--attend-progress-track);
    overflow: hidden;
    appearance: none;
  }

  .kept-summary__bar::-webkit-progress-bar {
    border-radius: var(--r-pill);
    background: var(--attend-progress-track);
  }

  .kept-summary__bar::-webkit-progress-value {
    border-radius: var(--r-pill);
    background: var(--attend-accent);
  }

  .kept-summary__bar::-moz-progress-bar {
    border-radius: var(--r-pill);
    background: var(--attend-accent);
  }

  .kept-page__status:empty {
    display: none;
  }

  .kept-group + .kept-group {
    margin-block-start: var(--space-5);
  }

  .kept-row {
    align-items: center;
  }

  .kept-row .file-tile {
    min-inline-size: 48px;
  }

  .kept-row__open {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
  }

  .kept-row__open::after {
    content: "";
    position: absolute;
    inset: 0;
  }

  .kept-row__remove {
    position: relative;
    z-index: 1;
    flex: none;
    padding-inline: var(--space-2);
  }

  .kept-chip {
    display: inline-flex;
    align-items: center;
    min-block-size: 24px;
    padding-inline: var(--space-2);
    border-radius: var(--r-pill);
    background: var(--attend-info-bg);
    color: var(--attend-info-text);
    font-size: var(--text-label);
    font-weight: var(--weight-strong);
    line-height: var(--leading-label);
    white-space: nowrap;
  }

  .kept-chip--locked {
    background: var(--attend-warning-bg);
    color: var(--attend-warning-text);
  }

  .kept-undo {
    position: sticky;
    inset-block-end: var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-block-start: var(--space-4);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--attend-border);
    border-radius: var(--r-sm);
    background: var(--attend-surface);
  }

  .kept-undo[hidden] {
    display: none;
  }

  .kept-offline {
    display: grid;
    gap: var(--space-2);
    inline-size: 100%;
    text-align: start;
  }

  .kept-offline[hidden] {
    display: none;
  }

  .kept-offline p {
    margin: 0;
  }

  .kept-offline__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .kept-offline .kept-group + .kept-group {
    margin-block-start: var(--space-3);
  }
}
