/*
  data-display.css
  ---------------------------------------------------------------------
  Three independent data-presentation patterns bundled in one file:
  .stat-card (a KPI tile with label/value/delta), .kv-list (a
  definition-list key-value table with --wide/--stacked/--total
  variants), and .list-group (a bordered row list, optionally
  interactive as links or buttons). Unrelated to each other
  structurally - use whichever pattern fits, independent of the rest.

  Requires: css/reset.css, css/core.css

  HTML STRUCTURE:
    <dl class="grid" style="--col-count: ...">
      <div class="stat-card">
        <dt class="stat-card__label">Label</dt>
        <dd class="stat-card__value">Value</dd>
        <dd class="stat-card__delta stat-card__delta--up">▲ 12%</dd>
      </div>
      <!-- repeat .stat-card for each additional stat -->
    </dl>

    <dl class="kv-list">
      <div><dt>Key</dt><dd>Value</dd></div>
    </dl>

    <ul class="list-group">
      <li class="list-group__item">Item</li>
    </ul>

  WHY <dl> WRAPS THE GRID, AND <div> STAYS ON .stat-card:
    A label with one or more values under it is exactly the
    relationship <dl> exists for - "Days" is a term, "05" describes
    it, and HTML explicitly allows more than one <dd> per <dt> (a term
    can have several descriptions), which is what lets an optional
    second line - a delta, a sub-caption - sit as a second <dd>.

    But <dt>/<dd> are flat siblings with no way to draw a border
    around "this term and its descriptions" as one box, and each stat
    needs to render as its own bordered card. <dl>'s content model has
    a second, valid form for exactly this: a <dl> can hold <div>s
    instead of bare <dt>/<dd>, each <div> wrapping one term's <dt> and
    its <dd>(s) - the same shape .kv-list already uses one line down.
    The <div> is what .stat-card's border/background/padding apply to;
    <dt>/<dd> and their own classes are otherwise unchanged from a
    plain-<div> version. Net effect: the SAME element count as an
    all-<div> version (the outer .grid wrapper becomes <dl> instead of
    <div> - nothing added), but the collection and each label's
    relationship to its value(s) both have real semantics now, where
    before neither did. The only new CSS needed is zeroing <dd>'s
    browser-default inline-start margin, the same fix .kv-list dd
    already has below for the same reason.
  ---------------------------------------------------------------------
*/

@layer components {
  .stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  /* <dd> carries a 40px inline-start margin in every browser's UA
     stylesheet - reset.css doesn't zero it, and stat-card's own flex
     layout doesn't touch child margins either. Same fix, same
     reasoning as .kv-list dd further down. */
  .stat-card dd {
    margin-inline-start: 0;
  }

  .stat-card__label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-muted);
  }

  .stat-card__value {
    font-size: clamp(1.8rem, 1.4rem + 1.5vw, 2.5rem);
    font-weight: 800;
    line-height: 1;
    color: var(--color-text);
  }

  .stat-card__delta {
    font-size: 0.9rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.2em;
  }

  .stat-card__delta--up   { color: var(--color-success); }
  .stat-card__delta--down { color: var(--color-error); }

  .stat-card__sub {
    color: var(--color-muted);
    font-size: 0.9rem;
  }

  .kv-list {
    display: grid;
    gap: 0;
  }

  .kv-list > div {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: var(--space-4);
    align-items: baseline;
    padding-block: var(--space-4);
    border-block-end: 1px solid var(--color-border);
  }

  .kv-list > div:first-child {
    border-block-start: 1px solid var(--color-border);
  }

  .kv-list--wide > div {
    grid-template-columns: 1fr 3fr;
  }

  .kv-list--stacked > div {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  /* An emphasized row - e.g. a grand total beneath itemized rows in an
     order summary. Apply to the row's own wrapping <div> (not the
     enclosing <dl>), so only that row is bolded. */
  .kv-list--total dt,
  .kv-list--total dd {
    font-weight: 700;
  }

  .kv-list dt {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-muted);
  }

  .kv-list dd {
    margin: 0;
    color: var(--color-text);
    font-size: 0.9rem;
  }

  .list-group {
    list-style: none;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--color-surface);
  }

  .list-group--flush {
    border: none;
    border-radius: 0;
    background: transparent;
  }

  .list-group__item {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-6);
    border-block-end: 1px solid var(--color-border);
    color: var(--color-text);
  }

  .list-group--sm .list-group__item {
    padding: var(--space-2) var(--space-4);
    font-size: 0.9rem;
  }

  .list-group__item:last-child {
    border-block-end: none;
  }

  a.list-group__item,
  button.list-group__item {
    width: 100%;
    text-align: start;
    background: transparent;
    border-inline: none;
    border-block-start: none;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
  }

  a.list-group__item:hover,
  button.list-group__item:hover {
    background: var(--color-hover);
  }

  .list-group__item--active {
    background: color-mix(in oklab, var(--color-accent) 12%, var(--color-surface));
    color: var(--color-accent-text);
    font-weight: 600;
  }

  .list-group__item--active:hover {
    background: color-mix(in oklab, var(--color-accent) 16%, var(--color-surface));
  }

  .list-group__meta {
    margin-inline-start: auto;
    font-size: 0.9rem;
    color: var(--color-muted);
    flex-shrink: 0;
  }

  /* The primary line of a .list-group__item's content when it carries
     a secondary meta line beneath it (a two-line title + due-date/
     status block instead of the single plain-text case elsewhere).
     Pair with the .flex-1 utility on the wrapping element so this
     block grows to fill the row. */
  .list-group__title {
    font-size: 0.9rem;
    font-weight: 500;
  }

  /* For a row that needs a second line (e.g. a message preview under
     a name + timestamp) instead of the default single-line layout. */
  .list-group__item--stacked {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
  }
}
