@layer components {
  /* Info tiles — key-value display cards used in detail page sidebars. */
  .app-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: calc(var(--app-spacing) * 1);
    margin-bottom: calc(var(--app-spacing) * 2);
  }

  .app-stats-table {
    overflow: auto;
    border: 1px solid var(--app-border);
    border-radius: var(--app-border-radius);
    margin-bottom: calc(var(--app-spacing) * 1);
  }

  .app-stats-table th {
    border-top: 0;
  }

  .app-stats-table table {
    margin: 0;
  }

  .app-stats-table table tr:last-child td {
    border-bottom: 0;
  }

  .app-stats-table-empty {
    padding: var(--app-spacing);
  }

  .app-stats-table-explanation {
    padding: var(--app-spacing);
  }

  /* Tone palette — single hue per tone, bg + icon-color derived via color-mix
     so dark-mode automatically produces a subtle dark-tinted bg + bright icon. */
  .app-tile {
    --tile-tone: hsl(220 12% 50%);
    --tile-icon-bg: color-mix(in oklab, var(--tile-tone) 14%, white);
    --tile-icon-color: var(--tile-tone);
    --tile-count-color: var(--app-tile-count-color);
    --tile-label-color: var(--app-tile-label-color);
    --tile-link-color: var(--app-tile-link-color);
    position: relative;
    display: block;
    padding: calc(var(--app-spacing) * 1);
    border: 1px solid var(--app-tile-border);
    border-radius: calc(var(--app-border-radius) * 1.1);
    background: var(--app-tile-bg);
    color: var(--app-tile-label-color);
    text-decoration: none;
    transition:
      transform var(--app-transition),
      box-shadow var(--app-transition),
      border-color var(--app-transition);
  }

  .app-tile:hover {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
  }

  .app-tile-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--tile-icon-bg);
    color: var(--tile-icon-color);
    font-size: var(--text-lg);
  }

  /* Per-tone hues — pick one base color, light/dark blocks derive bg + icon. */
  .app-tile[data-tone="blue"]    { --tile-tone: hsl(217 91% 55%); }
  .app-tile[data-tone="violet"]  { --tile-tone: hsl(263 80% 58%); }
  .app-tile[data-tone="red"]     { --tile-tone: hsl(0 75% 55%); }
  .app-tile[data-tone="orange"]  { --tile-tone: hsl(20 90% 55%); }
  .app-tile[data-tone="amber"]   { --tile-tone: hsl(38 95% 55%); }
  .app-tile[data-tone="emerald"] { --tile-tone: hsl(160 75% 40%); }
  .app-tile[data-tone="cyan"]    { --tile-tone: hsl(190 85% 45%); }
  .app-tile[data-tone="pink"]    { --tile-tone: hsl(330 80% 58%); }
  .app-tile[data-tone="green"]   { --tile-tone: hsl(142 70% 45%); }
  .app-tile[data-tone="neutral"] { --tile-tone: hsl(220 10% 55%); }

  /* Dark-mode tone derivation: subtle dark-tinted bg + brighter icon for contrast.
     Mirrors the existing :root/[data-theme] split used in variables.base.css. */
  @media only screen and (prefers-color-scheme: dark) {
    :root:not([data-theme]) .app-tile {
      --tile-icon-bg: color-mix(in oklab, var(--tile-tone) 22%, var(--app-background-color));
      --tile-icon-color: color-mix(in oklab, var(--tile-tone) 80%, white);
    }
  }
  [data-theme="dark"] .app-tile {
    --tile-icon-bg: color-mix(in oklab, var(--tile-tone) 22%, var(--app-background-color));
    --tile-icon-color: color-mix(in oklab, var(--tile-tone) 80%, white);
  }

  .app-tile-count {
    position: absolute;
    top: calc(var(--app-spacing) * 1);
    right: calc(var(--app-spacing) * 1);
    font-weight: var(--font-bold);
    color: var(--tile-count-color);
  }

  .app-tile-label {
    display: block;
    margin-top: calc(var(--app-spacing) * 1);
    color: var(--tile-label-color);
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    max-width: 191px;
  }

  .app-tile-link {
    position: absolute;
    right: calc(var(--app-spacing) * 1);
    bottom: calc(var(--app-spacing) * 1);
    color: var(--tile-link-color);
    font-size: var(--text-sm);
  }

  .app-tile.is-small {
    padding: 10px;
    display: flex;
    align-items: center;
    min-height: 50px;
  }
  .app-tile.is-small span.app-tile-icon {
    width: 25px;
    height: 25px;
    border-radius: 6px;
    font-size: 12px; /* icon-font metric — intentional px */
    margin-right: 10px;
  }

  .app-tile.is-small .app-tile-link {
    bottom: 14px;
  }

  .app-tile.is-small .app-tile-count {
    position: static;
    margin-right: 5px;
    display: block;
  }
  .app-tile.is-small .app-tile-label {
    margin-top: 0;
    font-weight: var(--font-regular);
  }

  .app-stats-table-header {
    border-bottom: 1px solid var(--app-border);
    padding: 4px 10px 4px 10px;
    text-transform: uppercase;
    font-size: var(--text-sm);
    letter-spacing: var(--tracking-wide);
    background: var(--app-blockquote-background-color);
  }

  @media (max-width: 640px) {
    .app-tiles {
      grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
  }
}
