/* ============================================================================
   components.css — Ant Design's display components, for the workspaces' pages
   (Goals, Analyze, Compare) and the inspector. Built by shell/components.js
   or written straight into a view's markup.

     .page, .page-head      a workspace page and its header (actions)
     .card                  Card: a bordered panel with an optional head
     .stat-cards, .statistic  Statistic: a figure under its title
     .tag                   Tag, in the status colours or a module's role colour
     .progress              Progress (line)
     .switch                Switch
     .alert                 Alert
     .tabs                  Tabs (line)
     .data-table             Table
     .badge-dot             Badge (status dot)
     .list-item             List items with an avatar, words and actions
     .descriptions          Descriptions (vertical)
     .empty                 Empty
   ============================================================================ */

/* ─── Page ──────────────────────────────────────────────────────────────── */
.page {
    flex: 1;
    min-height: 0;
    padding: var(--space-24);
    background: var(--color-bg-layout);
}
.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-12) var(--space-24);
    margin-bottom: var(--space-16);
}
.page-start, .page-extra { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-8) var(--space-12); }
.page-extra { margin-left: auto; }
/* A label before a control in a page's actions ("Over", "Plan"). */
.page-label { color: var(--color-text-secondary); white-space: nowrap; }

/* The open plan, picked from a dropdown that looks like a Select. */
.plan-pick {
    display: inline-flex;
    align-items: center;
    gap: var(--space-8);
    width: 220px;
    max-width: 100%;
    text-align: left;
}
.plan-pick .icon { width: 14px; height: 14px; flex: none; color: var(--color-text-tertiary); }
.plan-pick-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-pick.field-select { background-image: none; padding-right: 11px; }

/* ─── Card ──────────────────────────────────────────────────────────────── */
/* Content flush with a card's edge rounds to the inside of its border, so
   the curves run parallel and no sliver shows at the corners. */
:root { --card-inner-radius: calc(var(--border-radius-lg) - var(--line-width)); }
.card {
    min-width: 0;
    background: var(--color-bg-container);
    border: var(--line-width) solid var(--color-border-secondary);
    border-radius: var(--border-radius-lg);
}
.card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-8) var(--space-16);
    min-height: 56px;
    padding: var(--space-8) var(--space-24);
    border-bottom: var(--line-width) solid var(--color-border-secondary);
}
.card-title {
    margin: 0;
    color: var(--color-text);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-strong);
    line-height: var(--line-height-lg);
}
.card-extra { color: var(--color-text-secondary); font-size: var(--font-size); }
.card-body { padding: var(--space-24); }
.card--sm .card-head { min-height: 38px; padding: var(--space-4) var(--space-12); }
.card--sm .card-title { font-size: var(--font-size); }
.card--sm .card-body { padding: var(--space-12); }
.card-body--flush { padding: 0; }
/* Cards stacked down a page. */
.page > .card + .card { margin-top: var(--space-16); }
/* Cards side by side, stacking when the page runs narrow. */
.card-row {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: var(--space-16);
    margin-top: var(--space-16);
    align-items: start;
}
.card-row > .card { margin-top: 0; height: 100%; }
@media (max-width: 1100px) {
    .card-row { grid-template-columns: minmax(0, 1fr); }
}

/* ─── Statistic ─────────────────────────────────────────────────────────── */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
    gap: var(--space-16);
    margin-bottom: var(--space-16);
}
.stat-cards > .card { padding: var(--space-16) var(--space-20); }
.statistic-title {
    margin-bottom: var(--space-4);
    color: var(--color-text-tertiary);
    font-size: var(--font-size);
}
.statistic-value {
    display: flex;
    align-items: baseline;
    gap: var(--space-4);
    color: var(--color-text);
    font-size: var(--font-size-heading-3);
    font-weight: var(--font-weight-normal);
    line-height: 1.3333;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.statistic-value .icon { width: 20px; height: 20px; align-self: center; }
.statistic-suffix { color: var(--color-text-tertiary); font-size: var(--font-size-lg); }
.statistic-value.is-up { color: var(--color-success-text); }
.statistic-value.is-down { color: var(--color-error-text); }
.statistic-value.is-warn { color: var(--color-warning-text); }
.statistic-value.is-muted { color: var(--color-text-tertiary); }

/* ─── Tag ───────────────────────────────────────────────────────────────── */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 22px;
    max-width: 100%;
    padding: 0 7px;
    border: var(--line-width) solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: var(--color-fill-quaternary);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    line-height: 20px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    vertical-align: middle;
}
.tag .icon { width: 12px; height: 12px; }
.tag > span { overflow: hidden; text-overflow: ellipsis; }
.tag--success { background: var(--color-success-bg); border-color: var(--color-success-border); color: var(--color-success-text); }
.tag--warning { background: var(--color-warning-bg); border-color: var(--color-warning-border); color: var(--color-warning-text); }
.tag--error { background: var(--color-error-bg); border-color: var(--color-error-border); color: var(--color-error-text); }
.tag--processing { background: var(--color-info-bg); border-color: var(--color-info-border); color: var(--color-info-text); }
/* Ant's borderless tag. */
.tag--plain { border-color: transparent; }

/* ─── Progress (line) ───────────────────────────────────────────────────── */
.progress {
    display: flex;
    align-items: center;
    gap: var(--space-8);
    min-width: 0;
}
.progress-track {
    position: relative;
    flex: 1;
    min-width: 0;
    height: 8px;
    border-radius: 100px;
    background: var(--color-fill-secondary);
    overflow: hidden;
}
.progress-fill {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: 100px;
    background: var(--color-info);
    transition: width var(--motion-duration-slow) var(--motion-ease-in-out);
}
.progress-text {
    flex: none;
    min-width: 2.6em;
    color: var(--color-text);
    font-size: var(--font-size);
    font-variant-numeric: tabular-nums;
    text-align: left;
}
.progress-text .icon { width: 16px; height: 16px; }
.progress--success .progress-fill { background: var(--color-success); }
.progress--success .progress-text { color: var(--color-success); }
.progress--warning .progress-fill { background: var(--color-warning); }
.progress--warning .progress-text { color: var(--color-warning-text); }
.progress--exception .progress-fill { background: var(--color-error); }
.progress--exception .progress-text { color: var(--color-error); }
.progress--sm .progress-track { height: 6px; }
.progress--sm .progress-text { font-size: var(--font-size-sm); }

/* ─── Switch ────────────────────────────────────────────────────────────── */
.switch {
    position: relative;
    display: inline-block;
    flex: none;
    min-width: 44px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 100px;
    background: var(--color-text-quaternary);
    cursor: pointer;
    vertical-align: middle;
    transition: background-color var(--motion-duration-mid);
}
.switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 4px 0 rgba(0, 35, 11, 0.2);
    transition: left var(--motion-duration-mid) var(--motion-ease-in-out);
}
.switch:hover { background: var(--color-text-tertiary); }
.switch[aria-checked="true"] { background: var(--color-primary); }
.switch[aria-checked="true"]:hover { background: var(--color-primary-hover); }
.switch[aria-checked="true"]::after { left: calc(100% - 20px); }
.switch:focus-visible { outline: 4px solid var(--color-primary-border); outline-offset: 1px; }
.switch:disabled { opacity: 0.65; cursor: not-allowed; }
.switch--sm { min-width: 28px; height: 16px; }
.switch--sm::after { width: 12px; height: 12px; }
.switch--sm[aria-checked="true"]::after { left: calc(100% - 14px); }
/* A switch with its words beside it, all one control to press. */
.switch-field {
    display: inline-flex;
    align-items: center;
    gap: var(--space-8);
    color: var(--color-text);
    cursor: pointer;
    white-space: nowrap;
}

/* ─── Alert ─────────────────────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-8);
    width: 100%;
    margin: 0;
    padding: var(--space-8) var(--space-12);
    border: var(--line-width) solid var(--color-border-secondary);
    border-radius: var(--border-radius-lg);
    background: var(--color-fill-alter);
    color: var(--color-text);
    font-size: var(--font-size);
    line-height: var(--line-height);
    text-align: left;
}
.alert > .icon { width: 16px; height: 16px; margin-top: 3px; color: var(--color-text-tertiary); }
.alert--success { background: var(--color-success-bg); border-color: var(--color-success-border); }
.alert--success > .icon { color: var(--color-success); }
.alert--info { background: var(--color-info-bg); border-color: var(--color-info-border); }
.alert--info > .icon { color: var(--color-info); }
.alert--warning { background: var(--color-warning-bg); border-color: var(--color-warning-border); }
.alert--warning > .icon { color: var(--color-warning); }
.alert--error { background: var(--color-error-bg); border-color: var(--color-error-border); }
.alert--error > .icon { color: var(--color-error); }
button.alert { font: inherit; cursor: pointer; transition: box-shadow var(--motion-duration-mid); }
button.alert:hover { box-shadow: 0 0 0 2px var(--control-outline); }
button.alert:focus-visible { outline: 4px solid var(--color-primary-border); outline-offset: 1px; }

/* ─── Tabs (line) ───────────────────────────────────────────────────────── */
.tabs-nav {
    display: flex;
    align-items: stretch;
    gap: var(--space-32);
    border-bottom: var(--line-width) solid var(--color-border-secondary);
    overflow-x: auto;
    scrollbar-width: none;
}
.tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-8);
    padding: var(--space-12) 0;
    border: 0;
    background: none;
    color: var(--color-text);
    font-size: var(--font-size);
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--motion-duration-slow) var(--motion-ease-in-out);
}
.tab .icon { width: 16px; height: 16px; }
.tab:hover { color: var(--color-primary-hover); }
.tab:active { color: var(--color-primary-active); }
.tab[aria-selected="true"] { color: var(--color-primary-text); text-shadow: 0 0 0.25px currentColor; }
.tab[aria-selected="true"]::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--color-primary);
}
.tab:focus-visible { outline: 4px solid var(--color-primary-border); outline-offset: -4px; border-radius: var(--border-radius-sm); }

/* ─── Table ─────────────────────────────────────────────────────────────── */
:root { --table-header-bg: #f5f2ea; --table-row-hover-bg: #f5f2ea; --table-sort-bg: #f5f2ea; }
html[data-theme="dark"] { --table-header-bg: #1f1d19; --table-row-hover-bg: #292621; --table-sort-bg: #292621; }

.table-wrap { width: 100%; overflow: auto; }
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--color-text);
    font-size: var(--font-size);
    font-variant-numeric: tabular-nums;
}
.data-table th,
.data-table td {
    position: relative;
    padding: var(--space-16);
    border-bottom: var(--line-width) solid var(--color-border-secondary);
    text-align: left;
    white-space: nowrap;
    overflow-wrap: break-word;
}
.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--table-header-bg);
    color: var(--color-text);
    font-weight: var(--font-weight-strong);
}
/* The short rule between header cells. */
.data-table thead th:not(:last-child)::before {
    content: '';
    position: absolute;
    top: 50%;
    right: 0;
    width: 1px;
    height: 1.6em;
    background: var(--color-split);
    transform: translateY(-50%);
}
.data-table tbody tr > * { background: var(--color-bg-container); transition: background-color var(--motion-duration-mid); }
.data-table tbody tr:hover > * { background: var(--table-row-hover-bg); }
.data-table tbody th { font-weight: var(--font-weight-normal); }
.data-table .is-num { text-align: right; }
.data-table .is-negative { color: var(--color-error-text); }
.data-table .is-muted { color: var(--color-text-tertiary); }
.data-table tr.is-total > * { font-weight: var(--font-weight-strong); }
/* A first column that stays put while the rest scroll sideways. */
.data-table .is-sticky { position: sticky; left: 0; z-index: 1; }
.data-table thead .is-sticky { z-index: 3; }
.table--sm th,
.table--sm td { padding: var(--space-8); }
.table--md th,
.table--md td { padding: var(--space-12) var(--space-8); }
/* A table flush in a card keeps the card's edge padding on its outer columns. */
.card-body--flush .data-table th:first-child,
.card-body--flush .data-table td:first-child { padding-left: var(--space-24); }
.card-body--flush .data-table th:last-child,
.card-body--flush .data-table td:last-child { padding-right: var(--space-24); }
/* At the foot of a card the card's own border closes the table: the last
   row drops its rule, and the cells keep inside the card's rounded corners. */
.card-body--flush:last-child { overflow: hidden; border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg); }
.card-body--flush:last-child .data-table tbody tr:last-child > * { border-bottom: 0; }

/* A sortable column's header: the whole cell is the button. */
.th-sort {
    display: inline-flex;
    align-items: center;
    gap: var(--space-4);
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    font-weight: var(--font-weight-strong);
    cursor: pointer;
}
.th-sort .sort-caret { display: inline-flex; flex-direction: column; color: var(--color-text-quaternary); }
.th-sort .sort-caret .icon { width: 10px; height: 10px; margin: -2px 0; }
.th-sort[data-dir="asc"] .sort-caret .icon:first-child,
.th-sort[data-dir="desc"] .sort-caret .icon:last-child { color: var(--color-primary); }
/* The hover fill is translucent, so it is laid over the header's own opaque
   background: the header is sticky, and rows scrolled beneath it must not
   show through. */
.data-table thead th:has(> .th-sort):hover {
    background: linear-gradient(var(--color-fill-secondary), var(--color-fill-secondary)), var(--table-header-bg);
}
.data-table td.is-sorted { background: var(--table-sort-bg); }
.th-sort:focus-visible { outline: 4px solid var(--color-primary-border); outline-offset: 2px; border-radius: var(--border-radius-sm); }

/* ─── Badge (status dot) ────────────────────────────────────────────────── */
.badge-dot { display: inline-flex; align-items: center; gap: var(--space-8); min-width: 0; }
.badge-dot::before {
    content: '';
    flex: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--dot, var(--color-text-quaternary));
}
.badge-dot--success { --dot: var(--color-success); }
.badge-dot--processing { --dot: var(--color-primary); }
.badge-dot--warning { --dot: var(--color-warning); }
.badge-dot--error { --dot: var(--color-error); }

/* ─── List ──────────────────────────────────────────────────────────────── */
.list { margin: 0; padding: 0; list-style: none; }
.list-item {
    display: flex;
    align-items: center;
    gap: var(--space-16);
    padding: var(--space-12) 0;
    border-bottom: var(--line-width) solid var(--color-split);
}
.list-item:last-child { border-bottom: 0; }
.list-item-meta { display: flex; align-items: center; gap: var(--space-16); flex: 1 1 260px; min-width: 0; }
.list-item-title { margin: 0; color: var(--color-text); font-weight: var(--font-weight-strong); }
.list-item-desc { margin: 0; color: var(--color-text-secondary); }
.list-item-actions { display: flex; align-items: center; gap: var(--space-4); flex: none; }

/* ─── Descriptions (vertical) ───────────────────────────────────────────── */
.descriptions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-12) var(--space-16);
    margin: 0;
}
.desc-label { color: var(--color-text-tertiary); font-size: var(--font-size); }
.desc-value {
    margin: 0;
    color: var(--color-text);
    font-size: var(--font-size);
    font-weight: var(--font-weight-medium);
    font-variant-numeric: tabular-nums;
}
.desc-value.is-up { color: var(--color-success-text); }
.desc-value.is-down { color: var(--color-error-text); }
.desc-value.is-warn { color: var(--color-warning-text); }
.desc-wide { grid-column: 1 / -1; }

/* ─── Empty ─────────────────────────────────────────────────────────────── */
.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-8);
    padding: var(--space-32) var(--space-16);
    color: var(--color-text-tertiary);
    text-align: center;
}
.empty > .icon { width: 48px; height: 48px; color: var(--color-text-quaternary); }
.empty-title { margin: 0; color: var(--color-text); font-weight: var(--font-weight-strong); }
.empty-desc { margin: 0; max-width: 52ch; }
.empty .button-primary { margin-top: var(--space-8); }

@media (prefers-reduced-motion: reduce) {
    .progress-fill, .switch, .switch::after, .tab, .data-table tbody tr > * { transition: none; }
}
