/*
 * The portal's components, over Pico CSS and Rare's tokens (tokens.css).
 *
 * Load order is pico.css, tokens.css, then this file. Section 1 points Pico's own
 * variables at Rare's tokens, so every element Pico styles is already on brand;
 * the sections after it are the portal's own components. Every colour and font
 * comes from a token: a literal colour here is a bug.
 */

/* 1. Pico, themed from Rare's tokens ------------------------------------------ */

/*
 * The selector outranks Pico's own theme blocks (:root:not([data-theme=dark]) and
 * its responsive font-size steps) whatever order they load in.
 */
:root[data-theme="light"] {
  --pico-font-family: var(--rare-font-ui);
  --pico-font-family-sans-serif: var(--rare-font-ui);
  --pico-font-family-monospace: var(--rare-font-mono);
  --pico-font-size: 100%;
  --pico-line-height: var(--rare-leading-body);
  --pico-font-weight: var(--rare-weight-body);
  --pico-border-radius: var(--rare-radius);
  --pico-spacing: var(--rare-space-4);
  --pico-typography-spacing-vertical: var(--rare-space-4);
  --pico-form-element-spacing-vertical: var(--rare-space-2);
  --pico-form-element-spacing-horizontal: var(--rare-space-3);
  --pico-outline-width: 0;

  --pico-background-color: var(--rare-surface-page);
  --pico-color: var(--rare-text);
  --pico-h1-color: var(--rare-text);
  --pico-h2-color: var(--rare-text);
  --pico-muted-color: var(--rare-text-muted);
  --pico-muted-border-color: var(--rare-hairline);
  --pico-primary: var(--rare-accent);
  --pico-primary-background: var(--rare-accent);
  --pico-primary-border: var(--rare-accent);
  --pico-primary-underline: var(--rare-accent);
  --pico-primary-hover: var(--rare-text);
  --pico-primary-hover-background: var(--rare-text);
  --pico-primary-hover-border: var(--rare-text);
  --pico-primary-hover-underline: var(--rare-text);
  --pico-primary-focus: transparent;
  --pico-primary-inverse: var(--rare-on-accent);
  --pico-card-background-color: var(--rare-surface-raised);
  --pico-card-sectioning-background-color: var(--rare-surface-raised);
  --pico-card-box-shadow: none;
  --pico-table-border-color: var(--rare-hairline);
  --pico-form-element-background-color: var(--rare-surface-raised);
  --pico-form-element-border-color: var(--rare-hairline-strong);
  --pico-form-element-color: var(--rare-text);
  --pico-form-element-focus-color: var(--rare-focus);
  --pico-form-element-active-border-color: var(--rare-focus);
  --pico-box-shadow: none;

  /*
   * Pico draws its icons as data: URIs. The policy's img-src 'self' refuses those,
   * so every icon is pointed at a file on this origin or switched off. Only the
   * select chevron is in use.
   */
  --pico-icon-chevron: url("/icons/chevron-down.svg");
  --pico-icon-checkbox: none;
  --pico-icon-minus: none;
  --pico-icon-close: none;
  --pico-icon-date: none;
  --pico-icon-time: none;
  --pico-icon-search: none;
  --pico-icon-loading: none;
  --pico-icon-valid: none;
  --pico-icon-invalid: none;
}

/* 2. Base ---------------------------------------------------------------------- */

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  width: 100%;
  max-width: var(--rare-measure);
  margin: 0 auto;
  padding: var(--rare-space-5) var(--rare-space-4) var(--rare-space-7);
}

main:focus {
  outline: none;
}

:where(a, button, select, input, [tabindex]):focus-visible {
  outline: var(--rare-focus-ring);
  outline-offset: 2px;
  box-shadow: none;
}

a {
  color: var(--rare-accent);
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--rare-text);
}

h1,
h2 {
  font-weight: var(--rare-weight-display);
  letter-spacing: var(--rare-tracking-display);
  line-height: var(--rare-leading-display);
}

h2 {
  font-size: 1.25rem;
}

p {
  margin-bottom: var(--rare-space-3);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* The brand's technical label: mono, small, uppercase, tracked out. */
.label {
  font-family: var(--rare-font-mono);
  font-size: var(--rare-size-label);
  letter-spacing: var(--rare-tracking-label);
  text-transform: uppercase;
  color: var(--rare-text-muted);
}

.note {
  font-size: var(--rare-size-small);
  color: var(--rare-text-muted);
}

/* 3. Buttons ------------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  gap: var(--rare-space-2);
  width: auto;
  margin: 0;
  padding: var(--rare-space-2) var(--rare-space-4);
  border: 1px solid var(--rare-text);
  border-radius: var(--rare-radius);
  background: transparent;
  color: var(--rare-text);
  font-family: var(--rare-font-mono);
  font-size: var(--rare-size-small);
  font-weight: var(--rare-weight-strong);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.2;
  cursor: pointer;
  /* Pico fades colours on state change; a half-faded label fails contrast mid-way. */
  transition: none;
}

.button:hover:not(:disabled) {
  background: var(--rare-text);
  border-color: var(--rare-text);
  color: var(--rare-surface-raised);
}

.button:disabled {
  opacity: 1;
  border-color: var(--rare-hairline-strong);
  color: var(--rare-text-muted);
  cursor: not-allowed;
}

.button--primary {
  background: var(--rare-accent);
  border-color: var(--rare-accent);
  color: var(--rare-on-accent);
  letter-spacing: var(--rare-tracking-label);
}

.button--primary:disabled {
  background: var(--rare-hairline);
  border-color: transparent;
  color: var(--rare-text-muted);
}

.button--primary:hover:not(:disabled) {
  background: var(--rare-text);
  border-color: var(--rare-text);
}

.button--small {
  padding: var(--rare-space-1) var(--rare-space-3);
  font-size: var(--rare-size-label);
}

/* Reads as a link: breadcrumbs and folder names. */
.button--link {
  padding: 0;
  border: none;
  background: none;
  color: var(--rare-accent);
  font-family: var(--rare-font-ui);
  font-size: inherit;
  font-weight: var(--rare-weight-strong);
  letter-spacing: normal;
  text-transform: none;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  text-align: left;
}

.button--link:hover:not(:disabled) {
  background: none;
  color: var(--rare-text);
}

/* 4. Notices and status ---------------------------------------------------------- */

.status {
  margin: var(--rare-space-3) 0 0;
  min-height: 1.5em;
  color: var(--rare-text);
  font-size: var(--rare-size-small);
}

.status:empty {
  min-height: 0;
  margin: 0;
}

.notice {
  margin: var(--rare-space-3) 0;
  padding: var(--rare-space-3) var(--rare-space-4);
  border-left: 4px solid currentcolor;
  background: var(--rare-surface-raised);
}

.notice--error {
  /* Signal Red marks the notice; the words stay in ink so they pass WCAG AA. */
  color: var(--rare-text);
  background: var(--rare-red-surface);
  border-left-color: var(--rare-danger);
}

.synthetic-banner {
  margin: 0;
  padding: var(--rare-space-2) var(--rare-space-4);
  background: var(--rare-text);
  color: var(--rare-surface-raised);
  font-family: var(--rare-font-mono);
  font-size: var(--rare-size-label);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
}

/* 5. Splash page ----------------------------------------------------------------- */

.splash {
  min-height: calc(100vh - 8rem);
  display: grid;
  place-items: center;
}

.splash__card {
  width: 100%;
  max-width: 30rem;
  padding: var(--rare-space-7) var(--rare-space-6);
  background: var(--rare-surface-raised);
  border: var(--rare-rule);
  text-align: center;
}

.splash__logo {
  margin: 0 0 var(--rare-space-5);
}

.splash__logo img {
  display: block;
  width: 14.5rem;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.splash__line {
  margin: 0 auto var(--rare-space-6);
  max-width: 22rem;
  font-size: 1.125rem;
}

.splash__action {
  margin: var(--rare-space-5) 0 var(--rare-space-6);
}

.splash__action .button--primary {
  padding: var(--rare-space-3) var(--rare-space-7);
}

.splash__contact {
  margin: 0;
  padding-top: var(--rare-space-5);
  border-top: var(--rare-rule);
  font-size: var(--rare-size-small);
  color: var(--rare-text-muted);
}

.splash .notice {
  text-align: left;
}

.person-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--rare-space-4);
  text-align: left;
}

.person-list li {
  list-style: none;
  margin: 0;
}

.person-list .note {
  margin: var(--rare-space-1) 0 0;
}

/* 6. Site header ------------------------------------------------------------------- */

.site-header {
  background: var(--rare-surface-raised);
  border-bottom: var(--rare-rule);
}

.site-header__inner {
  max-width: var(--rare-measure);
  margin: 0 auto;
  padding: var(--rare-space-3) var(--rare-space-4);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--rare-space-3);
}

.brand {
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--rare-space-3);
}

.brand__logo {
  width: 5.5rem;
  height: auto;
}

.brand__product {
  padding-left: var(--rare-space-3);
  border-left: var(--rare-rule);
  font-family: var(--rare-font-mono);
  font-size: var(--rare-size-label);
  letter-spacing: var(--rare-tracking-label);
  text-transform: uppercase;
}

.account {
  display: flex;
  align-items: center;
  gap: var(--rare-space-3);
  font-size: var(--rare-size-small);
  color: var(--rare-text-muted);
}

.skip-link {
  position: absolute;
  left: var(--rare-space-4);
  top: -10rem;
  padding: var(--rare-space-2) var(--rare-space-4);
  background: var(--rare-accent);
  color: var(--rare-on-accent);
  z-index: 10;
}

.skip-link:focus {
  top: var(--rare-space-2);
}

/* 7. Workspace ---------------------------------------------------------------------- */

.page__title {
  margin: 0;
  font-size: var(--rare-size-title);
}

.panel {
  background: var(--rare-surface-raised);
  border: var(--rare-rule);
  padding: var(--rare-space-5);
}

.context-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--rare-space-4);
  margin-bottom: var(--rare-space-5);
}

.viewing {
  margin: var(--rare-space-2) 0 0;
  display: flex;
  align-items: baseline;
  gap: var(--rare-space-2);
}

.viewing strong {
  font-weight: var(--rare-weight-strong);
}

.context-bar__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--rare-space-4);
}

.switcher {
  display: flex;
  flex-direction: column;
  gap: var(--rare-space-1);
}

.switcher label {
  margin: 0;
}

.switcher select {
  margin: 0;
  min-width: 16rem;
}

/* The slot grid: the browser now, and an access panel beside it later. */
.workspace-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--rare-space-5);
}

.workspace-layout:has(> .access-panel:not([hidden])) {
  grid-template-columns: minmax(0, 1fr) 20rem;
}

/* Pico spreads a nav's lists apart with negative margins; a breadcrumb trail sits left. */
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: var(--rare-space-3);
  margin-bottom: var(--rare-space-4);
}

.crumbs ol,
.crumbs ol:first-of-type,
.crumbs ol:last-of-type {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  margin: 0;
  padding: 0;
  list-style: none;
}

.crumbs li {
  margin: 0;
  padding: 0;
  word-break: break-word;
  list-style: none;
}

.crumbs li + li::before {
  content: "/";
  padding: 0 var(--rare-space-2);
  color: var(--rare-text-muted);
}

.crumbs li[aria-current="true"] {
  font-weight: var(--rare-weight-strong);
}

.folder-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--rare-space-3);
  padding-bottom: var(--rare-space-3);
  border-bottom: 2px solid var(--rare-text);
}

.folder-head__title {
  margin: 0;
  font-size: 1.5rem;
}

.folder-head__title:focus {
  outline: none;
}

.folder-head__title:focus-visible {
  outline: var(--rare-focus-ring);
}

.folder-head__actions {
  display: flex;
  gap: var(--rare-space-2);
}

/* 8. File table ------------------------------------------------------------------------ */

.table-wrap {
  overflow-x: auto;
}

.file-table {
  width: 100%;
  margin: 0;
  font-size: var(--rare-size-small);
}

.file-table caption {
  caption-side: bottom;
  padding-top: var(--rare-space-3);
  text-align: left;
  font-size: var(--rare-size-label);
  color: var(--rare-text-muted);
}

.file-table th {
  font-family: var(--rare-font-mono);
  font-size: var(--rare-size-label);
  font-weight: var(--rare-weight-strong);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--rare-text-muted);
  background: transparent;
}

.file-table td,
.file-table th {
  padding: var(--rare-space-3) var(--rare-space-3) var(--rare-space-3) 0;
  vertical-align: middle;
  background: transparent;
  border-bottom: var(--rare-rule);
}

@media (hover: hover) {
  .file-table tbody tr:hover td {
    background: var(--rare-surface-page);
  }
}

.file-table__name {
  font-size: var(--rare-size-body);
  word-break: break-word;
}

.file-name,
.folder-link {
  display: inline-flex;
  align-items: center;
  gap: var(--rare-space-2);
}

.icon {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentcolor;
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.icon--folder {
  stroke: var(--rare-accent);
}

td.actions {
  white-space: nowrap;
  text-align: right;
}

td.actions > * + * {
  margin-left: var(--rare-space-2);
}

.download-only {
  font-size: var(--rare-size-label);
  color: var(--rare-text-muted);
}

.empty {
  margin: var(--rare-space-4) 0;
  padding: var(--rare-space-5);
  border: 1px dashed var(--rare-hairline-strong);
  color: var(--rare-text-muted);
  text-align: center;
}

#more {
  margin-top: var(--rare-space-4);
}

/* 9. Preview ------------------------------------------------------------------------- */

.preview {
  margin-top: var(--rare-space-6);
  padding-top: var(--rare-space-4);
  border-top: 2px solid var(--rare-text);
}

.preview__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--rare-space-3);
}

.preview__head h2 {
  margin: 0;
}

.preview__head h2:focus {
  outline: none;
}

.preview__frame iframe {
  display: block;
  width: 100%;
  height: 32rem;
  border: var(--rare-rule);
  background: var(--rare-white);
}

/* 10. Narrow screens ---------------------------------------------------------------------- */

@media (max-width: 40rem) {
  main {
    padding: var(--rare-space-4) var(--rare-space-3) var(--rare-space-6);
  }

  .splash__card {
    padding: var(--rare-space-6) var(--rare-space-4);
    border: none;
    background: transparent;
  }

  .panel {
    padding: var(--rare-space-4);
  }

  .switcher select {
    min-width: 0;
    width: 100%;
  }

  .context-bar__tools,
  .switcher {
    width: 100%;
  }

  .workspace-layout:has(> .access-panel:not([hidden])) {
    grid-template-columns: minmax(0, 1fr);
  }

  /* The table becomes a stack of cards, each cell labelled from its data-label. */
  .file-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .file-table caption {
    display: block;
  }

  .file-table,
  .file-table tbody,
  .file-table tr,
  .file-table td {
    display: block;
    width: 100%;
  }

  .file-table tr {
    padding: var(--rare-space-3) 0;
    border-bottom: var(--rare-rule);
  }

  .file-table td {
    padding: var(--rare-space-1) 0;
    border: none;
  }

  .file-table td:empty {
    display: none;
  }

  .file-table td:not(.file-table__name, .actions)::before {
    content: attr(data-label) ": ";
    color: var(--rare-text-muted);
  }

  td.actions {
    text-align: left;
    white-space: normal;
    padding-top: var(--rare-space-2);
  }

  .preview__frame iframe {
    height: 24rem;
  }
}

/* 12. Admin controls --------------------------------------------------------------------- */
/* Mounted by admin.js into the slots above, only for an admin the file API accepts. */

.button--danger {
  background: var(--rare-surface-raised);
  border-color: var(--rare-danger);
  color: var(--rare-text);
}

.button--danger:hover:not(:disabled) {
  background: var(--rare-danger);
  border-color: var(--rare-danger);
  color: var(--rare-white);
}

.folder-head__actions {
  flex-wrap: wrap;
  align-items: center;
}

.drop-hint {
  margin: 0;
}

/* The whole browser panel takes dropped files; this is how it says so. */
.browser--drop {
  outline: 3px dashed var(--rare-accent);
  outline-offset: -3px;
}

.upload-queue {
  flex-basis: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--rare-size-small);
}

.upload-queue li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 10rem;
  gap: var(--rare-space-2);
  align-items: center;
  margin: 0 0 var(--rare-space-1);
  list-style: none;
}

.upload-queue__name {
  word-break: break-word;
}

.upload-queue progress {
  margin: 0;
  height: 0.5rem;
}

.upload-queue__outcome:empty {
  display: none;
}

.upload-queue__outcome {
  grid-column: 1 / -1;
}

.upload-queue__item--failed .upload-queue__name {
  color: var(--rare-text);
  text-decoration: line-through;
}

.access {
  font-size: var(--rare-size-small);
}

.access h2 {
  margin-bottom: var(--rare-space-2);
}

.access h3 {
  margin: var(--rare-space-4) 0 var(--rare-space-2);
  font-size: var(--rare-size-body);
}

.access__list {
  margin: 0;
  padding: 0;
}

.access__list li {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--rare-space-2);
  padding: var(--rare-space-2) 0;
  border-bottom: var(--rare-rule);
  list-style: none;
}

.access__who {
  display: flex;
  flex-direction: column;
  min-width: 0;
  word-break: break-all;
}

.access__who code {
  padding: 0;
  background: none;
  color: var(--rare-text-muted);
  font-family: var(--rare-font-mono);
  font-size: var(--rare-size-label);
}

.admin-field {
  display: block;
  margin-bottom: var(--rare-space-3);
  font-weight: var(--rare-weight-strong);
}

.admin-field input {
  margin: var(--rare-space-1) 0 0;
  font-weight: var(--rare-weight-body);
}

.admin-field .note {
  display: block;
  font-weight: var(--rare-weight-body);
}

.admin-dialog article {
  max-width: 32rem;
}

.admin-dialog footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--rare-space-2);
}

/* An admin's rows carry more controls; let them wrap so the name keeps its width. */
.is-admin td.actions {
  white-space: normal;
  min-width: 12rem;
}

.is-admin td.actions > * {
  margin: var(--rare-space-1) 0 var(--rare-space-1) var(--rare-space-2);
}

.is-admin .file-table__name {
  min-width: 12rem;
}

.admin-field input + small {
  margin-top: var(--rare-space-1);
}
