/* data-display.css — Phase 5 opt-in data-display components (tables,
   metric cards, chart containers, live-view tiles). Token-driven.
   Data-slot hooks are orthogonal to JS state classes / IDs which we
   NEVER touch. Loaded AFTER forms.css. Nothing in current markup uses
   these [data-slot] values yet → linking alone = ZERO visual change.
   Logical properties throughout (RTL). */

/* =====================================================================
   Diff 2 — Table foundation
   ===================================================================== */

/* B21 s3 (CODE-13): this sheet is the `components` cascade layer; the order is declared once, in tokens.css. */
@layer components {

[data-slot="table-scroll"] { inline-size: 100%; overflow-x: auto; }
[data-slot="table"] { inline-size: 100%; border-collapse: collapse; font-size: var(--text-sm); color: var(--color-foreground); }
[data-slot="table"] caption { text-align: start; color: var(--color-muted-foreground); font-size: var(--text-sm); padding-block: var(--space-2); }
[data-slot="table-header"] [data-slot="row"] { border-block-end: 1px solid var(--color-border); }
[data-slot="head-cell"] { text-align: start; font-weight: 500; color: var(--color-muted-foreground); padding: var(--space-2) var(--space-3); white-space: nowrap; }
[data-slot="cell"] { padding: var(--space-2) var(--space-3); border-block-end: 1px solid var(--color-border); vertical-align: middle; }
[data-slot="table-footer"] [data-slot="cell"] { font-weight: 500; border-block-end: 0; }

/* =====================================================================
   Diff 3 — Table states (hover / selected / sort / numeric / density / empty / loading)
   ===================================================================== */
[data-slot="table-body"] [data-slot="row"]:hover { background: var(--color-muted); }
[data-slot="row"][data-selected="true"] { background: var(--color-muted); }
[data-slot="row"][aria-disabled="true"] { opacity: .5; }
[data-slot="cell"][data-align="end"], [data-slot="head-cell"][data-align="end"] { text-align: end; font-variant-numeric: tabular-nums; }
[data-slot="head-cell"][aria-sort] { cursor: pointer; user-select: none; }
[data-slot="head-cell"][aria-sort]::after { content: ""; display: inline-block; inline-size: .6em; block-size: .6em; margin-inline-start: var(--space-1); opacity: .4; }
[data-slot="head-cell"][aria-sort="ascending"]::after,
[data-slot="head-cell"][aria-sort="descending"]::after { opacity: 1; }
[data-slot="head-cell"][aria-sort]:focus-visible { outline: none; box-shadow: 0 0 0 var(--ring-width) var(--ring-color); }
[data-slot="row"][data-empty] [data-slot="cell"],
[data-slot="row"][data-loading] [data-slot="cell"] { text-align: center; color: var(--color-muted-foreground); padding-block: var(--space-8); }

/* =====================================================================
   UX-B12 — Compact density for the admin tables (qa/UX-PLAN.md §7 item 5)

   [data-slot="table"][data-density="compact"]: Scheduled, Audit, Approval
   rules and Members. At 768 px and wider each row is 32 px with tabular
   figures on time, count and id cells ([data-numeric]); under 768 px each
   row is one of Atelier's 38 px cards (--h-row), because there the 44 px
   target rule wins and a table does not fit. Atelier's tokens and type stay
   as they are: the rule changes geometry only, never a colour or a font.
   Phone first: the card shape is the base, the table the min-width block.
   The selectors go through [data-slot="table-scroll"] so they outrank a
   page's own frame rule (.adm-table-wrap [data-slot="table"]).
   ===================================================================== */
[data-slot="table-scroll"] > [data-slot="table"][data-density="compact"] {
    --_row-compact: 32px;
    display: block; min-inline-size: 0;
}
[data-slot="table-scroll"]:has(> [data-slot="table"][data-density="compact"]) {
    overflow: visible; border: 0; box-shadow: none; background: transparent; border-radius: 0;
}
[data-slot="table-scroll"] > [data-density="compact"] > [data-slot="table-header"] {
    position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden;
    clip-path: inset(50%); white-space: nowrap;
}
[data-slot="table-scroll"] > [data-density="compact"] > [data-slot="table-body"] {
    display: flex; flex-direction: column; gap: var(--space-2);
}
[data-slot="table-scroll"] > [data-density="compact"] > [data-slot="table-body"] > [data-slot="row"] {
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3);
    min-block-size: var(--h-row);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border); border-radius: var(--radius-lg);
    background: var(--color-card);
}
[data-slot="table-scroll"] > [data-density="compact"] > [data-slot="table-body"] > [data-slot="row"] > [data-slot="cell"] {
    display: block; padding: 0; border: 0; min-inline-size: 0; overflow-wrap: anywhere;
}
/* The row's name takes the card's first line; the rest wrap under it. */
[data-slot="table-scroll"] > [data-density="compact"] [data-slot="cell"][data-primary] {
    flex: 1 1 100%; order: -1; font-weight: 600;
}
/* A cell whose header is not on screen says what it is. */
[data-slot="table-scroll"] > [data-density="compact"] [data-slot="cell"][data-label]::before {
    content: attr(data-label) " "; color: var(--color-muted-foreground); font-weight: 400;
}
[data-slot="table-scroll"] > [data-density="compact"] [data-slot="cell"][data-actions] {
    margin-inline-start: auto;
}
[data-slot="table-scroll"] > [data-density="compact"] [data-slot="cell"][data-actions="menu"] button {
    inline-size: 44px; block-size: 44px;
}
[data-slot="table"][data-density="compact"] [data-numeric] { font-variant-numeric: tabular-nums; }
@media (min-width: 768px) {
    /* A long value keeps the row to one line and says the rest in its title. */
    [data-slot="table"][data-density="compact"] [data-truncate] {
        display: block; max-inline-size: var(--cell-max, 36ch);
        overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    [data-slot="table-scroll"]:has(> [data-slot="table"][data-density="compact"]) { overflow-x: auto; }
    [data-slot="table-scroll"] > [data-slot="table"][data-density="compact"] { display: table; }
    [data-slot="table-scroll"] > [data-density="compact"] > [data-slot="table-header"] {
        position: static; inline-size: auto; block-size: auto; overflow: visible;
        clip-path: none; display: table-header-group;
    }
    [data-slot="table-scroll"] > [data-density="compact"] > [data-slot="table-body"] { display: table-row-group; }
    [data-slot="table-scroll"] > [data-density="compact"] > [data-slot="table-body"] > [data-slot="row"] {
        display: table-row; min-block-size: 0; padding: 0; border: 0; border-radius: 0;
        background: transparent;
    }
    [data-slot="table-scroll"] > [data-density="compact"] > [data-slot="table-body"] > [data-slot="row"] > [data-slot="cell"],
    [data-slot="table-scroll"] > [data-density="compact"] > [data-slot="table-header"] > [data-slot="row"] > [data-slot="head-cell"] {
        display: table-cell; box-sizing: border-box; block-size: var(--_row-compact);
        padding: 0 var(--space-2); white-space: nowrap; vertical-align: middle;
        border-block-end: 1px solid var(--color-border);
    }
    /* The header row sits on the table's own surface (the dark theme's
       `table th { #333 }` would put muted text on grey); a page whose header
       is sticky names its surface in --table-head-bg. */
    [data-slot="table-scroll"] > [data-density="compact"] > [data-slot="table-header"] > [data-slot="row"] > [data-slot="head-cell"] {
        background-color: var(--table-head-bg, transparent); border-color: var(--color-border);
    }
    /* The row's ⋯ fits the 32 px row (a 28 px target; 24 is the floor). */
    [data-slot="table-scroll"] > [data-density="compact"] [data-slot="cell"][data-actions="menu"] button {
        inline-size: 28px; block-size: 28px;
    }
    [data-slot="table-scroll"] > [data-density="compact"] [data-slot="cell"][data-actions] [data-slot="button"] {
        block-size: 28px;
    }
    [data-slot="table-scroll"] > [data-density="compact"] [data-slot="table-body"] [data-slot="row"]:hover {
        background: var(--color-muted);
    }
    [data-slot="table-scroll"] > [data-density="compact"] [data-slot="cell"][data-primary] { font-weight: 500; }
    /* The one cell that takes the width the others leave, cut to fit: the
       table then fits its column instead of scrolling sideways. */
    [data-slot="table-scroll"] > [data-density="compact"] [data-slot="cell"][data-fill] {
        inline-size: 100%; max-inline-size: 0;
    }
    [data-slot="table"][data-density="compact"] [data-fill] > [data-truncate] { max-inline-size: none; }
    /* data-layout="fixed": the header cells name their widths and the first
       column takes the rest, so a narrow page column cuts values instead of
       pushing the row's menu out of sight. */
    [data-slot="table-scroll"] > [data-slot="table"][data-density="compact"][data-layout="fixed"] { table-layout: fixed; }
    [data-slot="table"][data-density="compact"][data-layout="fixed"] [data-truncate] { max-inline-size: none; }
    [data-slot="table-scroll"] > [data-density="compact"] [data-slot="cell"][data-label]::before { content: none; }
    [data-slot="table-scroll"] > [data-density="compact"] [data-slot="cell"][data-actions] { text-align: end; }
}

/* A strip of counts above a table ("2 incidents", "9 Active"): badges,
   one of them a button. Its button is a 24 px target at desktop and the
   44 px one on a phone. */
[data-slot="table-summary"] {
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2);
    margin-block-end: var(--space-3); font-size: var(--text-sm); color: var(--color-muted-foreground);
}
[data-slot="table-summary"] [data-slot="badge"] { font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
[data-slot="table-summary"] button[data-slot="badge"] {
    font-family: inherit; cursor: pointer; min-block-size: 44px; padding-inline: var(--space-3);
}
@media (min-width: 768px) {
    [data-slot="table-summary"] button[data-slot="badge"] { min-block-size: 24px; }
}

/* =====================================================================
   Diff 4 — Metric-card composition (on Phase 2 card)
   ===================================================================== */
[data-slot="metric"] { display: flex; flex-direction: column; gap: var(--space-1); }
[data-slot="metric-label"] { font-size: var(--text-sm); color: var(--color-muted-foreground); }
[data-slot="metric-value"] { font-size: var(--text-2xl); font-weight: 600; line-height: var(--leading-tight); color: var(--color-foreground); }
[data-slot="metric-footer"] { font-size: var(--text-xs); color: var(--color-muted-foreground); }
[data-slot="metric-trend"] { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-xs); font-weight: 500; }
[data-slot="metric-trend"][data-trend="up"]   { color: var(--color-success); }
[data-slot="metric-trend"][data-trend="down"] { color: var(--color-danger); }
[data-slot="metric-trend"][data-trend="flat"] { color: var(--color-muted-foreground); }

/* =====================================================================
   Diff 5 — Data-card compat bridge (geometry)
   ===================================================================== */
/* Compat bridges — REMOVE in Phase 9. Geometry only; feature tokens intact. */
.summary-card { border-radius: var(--radius-xl); box-shadow: var(--shadow-xs); }
/* .stat-card already carries [data-slot=card][data-variant=metric] from Phase 2 */

/* =====================================================================
   Diff 6 — Chart-container composition
   ===================================================================== */
[data-slot="chart"] { display: flex; flex-direction: column; }
[data-slot="chart-header"] { display: flex; align-items: start; justify-content: space-between; gap: var(--space-2); }
[data-slot="chart-title"] { margin: 0; font-size: var(--text-lg); font-weight: 600; }
[data-slot="chart-body"] { position: relative; inline-size: 100%; min-block-size: 240px; }
[data-slot="chart-body"] > canvas { max-inline-size: 100%; }
[data-slot="chart-legend"] { display: flex; flex-wrap: wrap; gap: var(--space-3); font-size: var(--text-xs); color: var(--color-muted-foreground); }
[data-slot="chart-summary"] { font-size: var(--text-sm); color: var(--color-muted-foreground); }
[data-slot="chart"][data-empty="true"] [data-slot="chart-body"],
[data-slot="chart"][data-loading="true"] [data-slot="chart-body"] { display: grid; place-items: center; color: var(--color-muted-foreground); }

/* =====================================================================
   Diff 9 — Live-view tile styling hooks (style-only)
   ===================================================================== */
[data-slot="tile-grid"] { display: grid; gap: var(--space-4); }
[data-slot="tile"] { position: relative; border-radius: var(--radius-lg); overflow: hidden; background: var(--color-foreground); }
[data-slot="tile-header"] { position: absolute; inset-block-start: 0; inset-inline: 0; padding: var(--space-2) var(--space-3); display: flex; justify-content: space-between; z-index: 2; background: linear-gradient(to bottom, color-mix(in srgb, var(--color-shadow) 70%, transparent), transparent); color: var(--color-background); }
[data-slot="tile-status"] { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-xs); }
[data-slot="tile-controls"] { position: absolute; inset-block-end: 0; inset-inline: 0; padding: var(--space-2) var(--space-3); z-index: 2; }
[data-slot="tile"][data-state="offline"] { opacity: .6; }
[data-slot="tile"][data-selected="true"] { outline: 2px solid var(--color-ring); outline-offset: -2px; }

/* =====================================================================
   Diff 10 — Data-display skeleton + empty placeholders (structure only)
   ===================================================================== */
[data-slot="skeleton"] { background: var(--color-muted); border-radius: var(--radius-sm); animation: dd-pulse 1.5s ease-in-out infinite; }
@keyframes dd-pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { [data-slot="skeleton"] { animation: none; } }
[data-slot="data-empty"] { display: grid; place-items: center; gap: var(--space-2); padding: var(--space-8); color: var(--color-muted-foreground); text-align: center; }

/* =====================================================================
   Diff 11 — Compatibility selectors (legacy → canonical geometry)

   Style-only bridges; JS state classes / IDs are never modified.
   Token-neutral classes only — feature cards keep their own layout.
   REMOVE in Phase 9.
   ===================================================================== */
/* Compat bridges — REMOVE in Phase 9. Geometry only. */
.insights-card { border-radius: var(--radius-xl); }
.cameras-grid, .recordings-list { gap: var(--space-6); }
/* .event-card / .recording-card keep their own feature layout for now */

/* =====================================================================
   Diff 12 — Code-block and result-item primitives

   Both come up across multiple surfaces (activity panel, citation
   chips, debug logs, future agent responses). They live here as
   slot-based primitives so any consumer gets the same shape, the
   same dark-mode parity, and the same logical-property RTL handling.

   The existing .markdown-body pre in chat_enhanced.css is markdown-
   specific and sets padding: 1rem; this primitive is the data-display
   answer — narrower padding, clamped height, optional language strip
   and copy affordance, dir="ltr" by convention. The activity panel
   adopts this in Group 5; the existing .step-detail-code block can be
   retired once consumers migrate.

   Token-driven throughout. Dark mode: no companion block needed —
   --color-muted, --color-border, and --color-muted-foreground all
   flip at tokens.css:179, so the primitives inherit dark-mode parity
   for free. The chat_enhanced.css @media (prefers-color-scheme: dark)
   block at the bottom is the wrong mechanism and should be deleted.
   ===================================================================== */
[data-slot="code-block"] {
    --_code-block-lines: 6;              /* the 5–7 line clamp, one place */
    border-radius: var(--radius-md);  /* hub card radius */
    background: var(--color-muted);
    overflow: hidden;
}
/* Strip is the LIGHTER surface; the body below is --color-muted. Separation
   by surface step, no border — --color-card is lighter than --color-muted in
   both themes (#fff/#f5f5f5, #2d2d30/#2a2a2a), so this holds on the flip. */
[data-slot="code-block"] > [data-slot="code-block-bar"] {
    display: flex;
    align-items: center;
    justify-content: space-between;   /* copy lands on the trailing edge, RTL included */
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    background: var(--color-card);
    font-size: var(--text-sm);
}
/* CHILD OF THE BAR, not of the block — this combinator is the whole defect. */
[data-slot="code-block-bar"] > [data-slot="code-block-lang"] {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1_5);
    font-size: var(--text-sm);
    font-weight: 400;                /* not a label chip */
    text-transform: none;            /* `Python`, not `PYTHON` */
    letter-spacing: normal;
    color: var(--color-foreground);
}
[data-slot="code-block-bar"] > [data-slot="code-block-lang"] > svg {
    color: var(--color-muted-foreground);
}
/* Borderless, transparent, glyph-sized. The !important-free way to beat
   style.css:192 `button {…}` is specificity, which this now has (0,2,0 > 0,0,1). */
[data-slot="code-block-bar"] > [data-slot="code-block-copy"] {
    appearance: none;
    -webkit-appearance: none;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 22px;
    block-size: 22px;
    padding: 0;
    margin: 0;
    background: transparent;
    background-image: none;
    border: 0;
    box-shadow: none;
    border-radius: var(--radius-sm);
    color: var(--color-muted-foreground);
    cursor: pointer;
    transition: background-color var(--dur-base) var(--ease-standard),
                color var(--dur-base) var(--ease-standard);
}
[data-slot="code-block-bar"] > [data-slot="code-block-copy"]:hover,
[data-slot="code-block-bar"] > [data-slot="code-block-copy"]:focus-visible {
    color: var(--color-foreground);
    background: var(--color-muted);
}
/* Each <pre> is its own scroll region — a block with a command line and a
   file body gets two, per the reference, and the clamp applies to each. */
[data-slot="code-block"] > pre {
    margin: 0;
    padding: var(--space-2);
    max-block-size: calc(var(--_code-block-lines) * 1.5em + 2 * var(--space-2));
    overflow: auto;
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--color-foreground);
    /* (Scrollbar styling removed — hidden app-wide, style.css.) */
}
[data-slot="code-block"] > pre + pre {
    border-block-start: 1px solid color-mix(in srgb, var(--color-foreground) 8%, transparent);
}
/* The <pre> child of a code-block never mirrors in an RTL document —
   code is LTR by convention. The [dir="ltr"] attribute is mandatory in
   the markup; this is a defensive CSS hint. */
[data-slot="code-block"] > pre[dir="ltr"] { direction: ltr; text-align: start; }

[data-slot="result-list"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}
[data-slot="result-item"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: 0;
    background: transparent;
    border: 0;
}
[data-slot="result-item-meta"] {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-xs);
    color: var(--color-muted-foreground);
}
[data-slot="result-item-title"] {
    margin: 0;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-foreground);
    line-height: var(--leading-tight, 1.3);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
[data-slot="result-item-snippet"] {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--color-muted-foreground);
    line-height: var(--leading-tight, 1.3);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

} /* end @layer components */
