/*
 * The activity template: the layout and look the activities packaged with
 * Refract share. Every instance serves it at /activities/refract-activity.css,
 * beside refract-activity.js (docs/activities.md). A page hosted elsewhere
 * copies it into its own repository, as it does the JS: it can't know which
 * instance it is running in, and a copy keeps the version it was built with.
 *
 *   <link rel="stylesheet" href="./refract-activity.css" />
 *
 * The frame contract: a page fills its frame exactly, and the document never
 * scrolls, whatever is in it. The body is three rows, `header`, `main` and
 * `footer`; the main one takes what the others leave, and clips what doesn't
 * fit it. Only a region marked `.scroll` scrolls, and media fits the box it is
 * given rather than growing it.
 *
 * Everything is in the `refract` layer, so a page's own rules win over these
 * without fighting their specificity.
 */
@layer refract {
  /* ---- colours: Refract's own, dark unless the page sets data-theme="light" ---- */

  :root {
    color-scheme: dark;
    --bg: #080d18;
    --surface: #101a2a;
    --raised: #182740;
    --fg: #eef5ff;
    --muted: #9fb2cc;
    --accent: #70e3ff;
    --accent-fg: #081522;
    --border: #2b3c55;
    --danger: #ff8a9b;
    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  }

  :root[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f7fb;
    --surface: #ffffff;
    --raised: #e6edf6;
    --fg: #0d1626;
    --muted: #52637b;
    --accent: #0b7ea3;
    --accent-fg: #ffffff;
    --border: #d2dbe7;
    --danger: #c0283f;
  }

  /* ---- the frame contract ---- */

  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html,
  body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-columns: minmax(0, 1fr);
    background: var(--bg);
    color: var(--fg);
    font: 14px/1.45 var(--font);
    -webkit-font-smoothing: antialiased;
  }

  /* each in its own row, whichever of them a page has */
  body > header {
    grid-row: 1;
  }
  body > main {
    grid-row: 2;
    position: relative;
    min-height: 0;
    overflow: hidden;
  }
  body > footer {
    grid-row: 3;
  }

  img,
  video,
  canvas,
  svg,
  iframe {
    display: block;
    max-width: 100%;
    max-height: 100%;
  }

  [hidden] {
    display: none !important;
  }

  .scroll {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }

  /* ---- pieces ---- */

  .bar {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 8px 12px;
    background: var(--surface);
  }
  header.bar {
    border-bottom: 1px solid var(--border);
  }
  footer.bar {
    border-top: 1px solid var(--border);
  }

  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
  }

  .button {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--raised);
    color: var(--fg);
    font: inherit;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition:
      background-color 0.15s,
      border-color 0.15s,
      color 0.15s,
      opacity 0.15s,
      transform 0.1s;
  }
  .button:hover:not(:disabled) {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  }
  .button:active:not(:disabled) {
    transform: translateY(1px);
  }
  .button:disabled {
    opacity: 0.45;
    cursor: default;
  }
  .button.primary {
    border-color: transparent;
    background: var(--accent);
    color: var(--accent-fg);
  }
  .button.primary:hover:not(:disabled) {
    border-color: transparent;
    background: color-mix(in srgb, var(--accent) 85%, var(--fg));
  }
  .button.ghost {
    border-color: transparent;
    background: transparent;
    color: var(--muted);
  }
  .button.ghost:hover:not(:disabled) {
    background: var(--raised);
    color: var(--fg);
  }
  .button.icon {
    width: 34px;
    padding: 0;
  }
  .button svg {
    width: 18px;
    height: 18px;
  }

  :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .input {
    min-width: 0;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--fg);
    font: inherit;
  }
  .input::placeholder {
    color: var(--muted);
  }
  .input:focus-visible {
    border-color: var(--accent);
    outline-offset: 0;
  }

  /* a slider; set --fill to how much of it is filled ("40%"), as WebKit can't draw that itself */
  .range {
    --fill: 0%;
    min-width: 0;
    height: 20px;
    margin: 0;
    background: transparent;
    cursor: pointer;
    appearance: none;
  }
  .range:disabled {
    opacity: 0.4;
    cursor: default;
  }
  .range:focus-visible {
    outline-offset: 0;
  }
  .range::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(
      to right,
      var(--accent) var(--fill),
      color-mix(in srgb, var(--fg) 20%, transparent) var(--fill)
    );
  }
  .range::-webkit-slider-thumb {
    width: 14px;
    height: 14px;
    margin-top: -5px;
    border: 0;
    border-radius: 50%;
    background: var(--fg);
    box-shadow: 0 1px 4px rgb(0 0 0 / 0.4);
    -webkit-appearance: none;
    appearance: none;
    transition: transform 0.1s;
  }
  .range:hover:not(:disabled)::-webkit-slider-thumb {
    transform: scale(1.2);
  }
  .range::-moz-range-track {
    height: 4px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--fg) 20%, transparent);
  }
  .range::-moz-range-progress {
    height: 4px;
    border-radius: 999px;
    background: var(--accent);
  }
  .range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 0;
    border-radius: 50%;
    background: var(--fg);
    box-shadow: 0 1px 4px rgb(0 0 0 / 0.4);
  }

  /* someone's picture, over the first letter of their name (data-initial) for when there is none */
  .avatar {
    position: relative;
    display: grid;
    flex: none;
    place-items: center;
    width: 28px;
    height: 28px;
    overflow: hidden;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 25%, var(--raised));
    color: var(--fg);
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
  }
  .avatar::before {
    content: attr(data-initial);
  }
  .avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    object-fit: cover;
  }

  /* people as named pills */
  .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .chips > li {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 2px 10px 2px 2px;
    border-radius: 999px;
    background: var(--raised);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
  }
  .chips .avatar {
    width: 22px;
    height: 22px;
    font-size: 10px;
  }

  .muted {
    color: var(--muted);
  }
  .status {
    color: var(--muted);
    font-size: 13px;
  }
  .status[data-tone="error"] {
    color: var(--danger);
  }

  /* what a part of the page shows before there is anything to show */
  .empty {
    display: grid;
    justify-items: center;
    gap: 8px;
    max-width: 360px;
    max-height: 100%;
    padding: 20px;
    overflow: hidden;
    color: var(--muted);
    text-align: center;
  }
  .empty h2 {
    margin: 0;
    color: var(--fg);
    font-size: 16px;
  }
  .empty p {
    margin: 0;
  }
  .empty svg {
    width: 36px;
    height: 36px;
    color: var(--accent);
  }

  .visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}
