/*
 * EatSmart admin: blocks that hold data — sections, tables, badges, stats, modals, record cards.
 * docs/ADMIN-UI.md §2.1–2.3: surfaces on paper with hairlines, no shadows except floating layers,
 * numbers in tabular figures, colour only where something deviates.
 */

/* ---------- Blocks: sections, tables, stats ---------- */

/* One recipe for every block: surface colour + hairline + the app's inner corner. No shadow —
   paper does not cast one; the hairline is enough on the darker page. */
.fi-section:not(.fi-section-not-contained):not(.fi-aside),
.fi-ta-ctn,
.fi-wi-stats-overview-stat {
    background: var(--es-surface);
    border-radius: var(--es-radius-block);
    box-shadow: inset 0 0 0 1px var(--es-hairline);
}

.fi-section-header-heading,
.fi-ta-header-heading {
    font-family: var(--es-font-serif);
    font-size: 17px;
    line-height: 24px;
    font-weight: 600;
    color: var(--es-text);
}
.fi-section-header-description,
.fi-ta-header-description {
    color: var(--es-muted);
    font-size: 13px;
}
/* Lines inside a block: Filament's gray-200 / white-5 % become the hairline token. */
.fi-section:not(.fi-section-not-contained) > .fi-section-content-ctn,
.fi-section:not(.fi-section-not-contained) > .fi-section-content-ctn > .fi-section-footer,
.fi-ta-header-toolbar,
.fi-ta-header {
    border-color: var(--es-hairline);
}

/* ---------- Tables ---------- */

.fi-ta-header-toolbar {
    padding: 10px 16px;
}
/* Column heads: no fill, small muted text — the data is what should catch the eye. */
.fi-ta-table > thead > tr,
.fi-ta-table > thead > tr > th {
    background: transparent;
}
.fi-ta-header-cell {
    padding: 9px 12px;
    font-size: 12.5px;
    line-height: 16px;
    font-weight: 500;
    color: var(--es-muted);
    white-space: nowrap;
}
.fi-ta-header-cell-sorted,
.fi-ta-header-cell-sort-btn:hover {
    color: var(--es-text);
}
.fi-ta-table > thead > :not(:last-child),
.fi-ta-table > tbody > :not(:last-child),
.fi-ta-table > thead {
    border-color: var(--es-hairline);
}
.fi-ta-table > tbody {
    border-top: 1px solid var(--es-hairline);
}
.fi-ta-table > tbody > tr {
    border-color: var(--es-hairline);
}

/* A row is 40 high: 8 + 20 + 8 and a hairline. Filament's 16 px vertical padding made tables
   twice as tall as their content and pushed the totals below the fold. */
.fi-ta-text:not(.fi-inline) {
    padding: 10px 12px;
}
/* Outer columns sit 16 from the block edge, heads and values on one line. Filament pads the
   first and last cell AND the text inside; the cell padding goes, the text keeps it. */
.fi-ta-cell:first-child { padding-inline-start: 0; }
.fi-ta-cell:last-child { padding-inline-end: 0; }
.fi-ta-cell:first-child .fi-ta-text:not(.fi-inline),
.fi-ta-header-cell:first-child { padding-inline-start: 16px; }
.fi-ta-cell:last-child .fi-ta-text:not(.fi-inline),
.fi-ta-header-cell:last-child { padding-inline-end: 16px; }
/* The actions cell had 16 above and below and set the row height to 53. */
.fi-ta-cell:has(> .fi-ta-actions) {
    padding-block: 6px;
    padding-inline-end: 12px;
}
.fi-ta-cell-content,
.fi-ta-text-item {
    font-size: 13.5px;
    line-height: 20px;
    color: var(--es-text);
}
.fi-ta-text-description {
    color: var(--es-muted);
    font-size: 12.5px;
}
/* Hover: a step towards the track colour, not grey. Clickable rows show the pointer. */
.fi-ta-row:hover > .fi-ta-cell {
    background: color-mix(in srgb, var(--es-track) 45%, transparent);
}
.fi-ta-row.fi-clickable,
.fi-ta-row.fi-clickable * {
    cursor: pointer;
}
.fi-ta-row.fi-striped {
    background: transparent;
}

/* Numbers right-aligned in tabular figures (columns ask for it with ->alignEnd()). */
.fi-ta-cell.fi-align-end .fi-ta-text-item,
.fi-ta-header-cell.fi-align-end {
    font-variant-numeric: tabular-nums lining-nums;
}

/* Column widths (docs/ADMIN-UI.md §2.3): one text column per table ->grow()s into the free space,
   the rest keep to their content. Without it Filament spread the width evenly and numbers sat
   300 px apart. Number columns get a wider gap on their left so neighbours do not run together. */
.fi-ta-cell.fi-align-end .fi-ta-text:not(.fi-inline),
.fi-ta-header-cell.fi-align-end {
    padding-inline-start: 24px;
}
/* A row whose only action is the hidden «view» (opened by clicking the row) has no actions
   column to show: its empty cell took 40 px at the right edge. */
.fi-ta-cell:has(> .fi-ta-actions > .es-hidden:only-child) {
    padding: 0;
    width: 0;
}

/* A dash for «nothing» — zero money, no date — muted so a column reads at a glance. */
.es-nil {
    color: var(--es-muted);
}

/* Long values (e-mails) end with an ellipsis instead of widening the whole table. */
.es-truncate {
    display: inline-block;
    vertical-align: bottom;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Row actions: one quiet «⋯» button. */
.fi-ta-actions .fi-icon-btn {
    color: var(--es-muted);
}
.fi-ta-actions .fi-icon-btn:hover {
    color: var(--es-text);
    background: var(--es-track);
}

/* Pagination: the same quiet controls as the table head. */
.fi-pagination {
    padding: 10px 16px;
    border-color: var(--es-hairline);
}
.fi-pagination-overview {
    color: var(--es-muted);
    font-size: 12.5px;
}
.fi-pagination-item-btn {
    background: transparent;
}
.fi-pagination-items,
.fi-pagination-records-per-page-select .fi-input-wrp {
    box-shadow: inset 0 0 0 1px var(--es-hairline);
    background: var(--es-raised);
}

/* Empty table: a sentence and what to do, without the big grey icon disc. */
.fi-ta-empty-state {
    padding-block: 40px;
}
.fi-ta-empty-state-icon-bg {
    background: var(--es-track);
}
.fi-ta-empty-state-heading {
    font-family: var(--es-font-serif);
    font-size: 17px;
    color: var(--es-text);
}
.fi-ta-empty-state-description {
    color: var(--es-muted);
}

/* Tabs above a table: left-aligned with the table, no box around them — pills on the page like
   the active menu item. Filament centres them in a white box. */
.fi-tabs:not(.fi-contained) {
    margin-inline: 0;
    padding: 0;
    background: transparent;
    box-shadow: none;
}
.fi-tabs-item {
    border-radius: var(--es-radius-control);
    color: var(--es-muted);
}
.fi-tabs-item.fi-active {
    background: var(--es-surface);
    box-shadow: inset 0 0 0 1px var(--es-hairline);
    color: var(--es-accent-ink);
}
.fi-tabs-item.fi-active .fi-tabs-item-label {
    color: var(--es-accent-ink);
}

/* ---------- Badges ---------- */

/* Only deviations get a badge (docs/ADMIN-UI.md §2.1); it is a soft pill, not a boxed tag. */
.fi-badge {
    border-radius: 999px;
    padding: 1px 8px;
    min-width: 0;
    font-size: 12px;
    line-height: 18px;
    font-weight: 500;
    --tw-ring-shadow: 0 0 #0000;
    box-shadow: none;
}

/* A sage dot before «normal» states, instead of a coloured badge. */
.es-dot {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
.es-dot::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--es-accent);
    flex: none;
}
.es-dot--muted::before { background: var(--es-hairline); }
.es-dot--warn::before { background: var(--es-warn); }
.es-dot--over::before { background: var(--es-over); }

/* ---------- Stats ---------- */

.fi-wi-stats-overview-stat {
    padding: 18px 20px;
}
.fi-wi-stats-overview-stat-label {
    font-size: 13px;
    font-weight: 450;
    color: var(--es-muted);
}
.fi-wi-stats-overview-stat-value {
    font-family: var(--es-font-serif);
    font-size: 30px;
    line-height: 36px;
    font-weight: 500;
    letter-spacing: 0;
    color: var(--es-text);
}
.fi-wi-stats-overview-stat-description {
    font-size: 12.5px;
}

/* ---------- Floating layers: modals, slide-overs, dropdowns ---------- */

/* These float over content, so here — and only here — there is a shadow. */
.fi-modal-window,
.fi-dropdown-panel {
    background: var(--es-raised);
    box-shadow: var(--es-shadow-float), inset 0 0 0 1px var(--es-hairline);
}
.fi-modal-window {
    border-radius: var(--es-radius-block);
}
.fi-modal-slide-over .fi-modal-window {
    border-radius: 0;
}
.fi-modal-heading {
    font-family: var(--es-font-serif);
    font-size: 19px;
    line-height: 26px;
    font-weight: 600;
    color: var(--es-text);
}
.fi-modal-description {
    color: var(--es-muted);
}
.fi-modal-close-overlay {
    background: rgb(28 27 25 / 0.35);
}
.fi-modal-footer,
.fi-modal-header {
    border-color: var(--es-hairline);
}

/* ---------- Record cards (infolists) ---------- */

/* Label above value, small and muted, the value in body text: reads like a filled-in form. */
.fi-in-entry-label {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--es-muted);
}
.fi-in-entry-content,
.fi-in-text-item {
    font-size: 14px;
    color: var(--es-text);
}

/* Codes, request numbers, JSON. */
.fi-in-code,
.es-mono {
    font-family: var(--es-font-mono);
    font-size: 12.5px;
}

/* ---------- Small tables inside cards (last requests of a person, components of a dish) ---------- */

.es-muted-text {
    color: var(--es-muted);
    font-size: 13px;
}
.es-mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
.es-mini-table td,
.es-mini-table th {
    /* Addresses have no spaces: on a phone they may break anywhere rather than widen the card. */
    overflow-wrap: anywhere;
    padding: 6px 0;
    border-bottom: 1px solid var(--es-hairline);
    vertical-align: baseline;
    text-align: left;
}
.es-mini-table th {
    color: var(--es-muted);
    font-size: 12.5px;
    font-weight: 500;
}
.es-mini-table tr:last-child td {
    border-bottom: none;
}
.es-mini-table td + td,
.es-mini-table th + th {
    padding-left: 12px;
}
.es-mini-table__when {
    width: 1%;
    white-space: nowrap;
    color: var(--es-muted);
}
.es-mini-table__num {
    text-align: right !important;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.es-mini-table a,
.es-mini-table__more a,
.fi-in-entry a {
    color: var(--es-text);
    text-decoration: none;
    border-bottom: 1px dotted var(--es-muted);
}
.es-mini-table a:hover,
.es-mini-table__more a:hover {
    color: var(--es-accent-ink);
    border-bottom-color: var(--es-accent-ink);
}
.es-mini-table__more {
    margin-top: 10px;
    font-size: 13px;
}
.es-mini-badge {
    margin-left: 6px;
    padding: 0 7px;
    border-radius: 999px;
    font-size: 11.5px;
    line-height: 18px;
    background: var(--es-track);
    color: var(--es-muted);
}
.es-mini-badge--over { background: var(--es-over-wash); color: var(--es-over-ink); }
.es-mini-badge--warn { background: var(--es-warn-wash); color: var(--es-warn-ink); }

/* The «view» action exists for row clicks and links; its button would only repeat the row. */
.es-hidden {
    display: none;
}

/* Card sections in the slide-over: heading, content, a hairline before the next one. */
/* Each section sits in its own grid column wrapper, so the siblings are the wrappers. */
.fi-grid-col:has(.es-card-section) ~ .fi-grid-col > .fi-sc-component > .es-card-section {
    border-top: 1px solid var(--es-hairline);
    padding-top: 20px;
}
.es-card-section .fi-section-header-heading {
    font-size: 15px;
    line-height: 22px;
}
.es-card-section .fi-section-content-ctn {
    padding-top: 4px;
}
.es-mini-badge {
    display: inline-block;
}

/* «6 из 10» with a thin bar: track colour for the rest, sage for the used part. */
.es-meter-cell {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-variant-numeric: tabular-nums;
}
.es-meter {
    display: inline-block;
    width: 56px;
    height: 4px;
    border-radius: 2px;
    background: var(--es-track);
    overflow: hidden;
}
.es-meter > span {
    display: block;
    height: 100%;
    background: var(--es-accent);
}
.es-meter--warn > span { background: var(--es-warn); }
.es-meter--over > span { background: var(--es-over); }
/* In a stat the bar spans the tile. */
.fi-wi-stats-overview-stat .es-meter-cell { display: flex; width: 100%; }
.fi-wi-stats-overview-stat .es-meter { flex: 1; max-width: 160px; }

/* ---------- Claude's answer in a request card ---------- */

.es-answer-title {
    font-family: var(--es-font-serif);
    font-size: 17px;
    line-height: 24px;
    font-weight: 600;
    margin: 0 0 8px;
}
.es-answer-table td:first-child {
    width: 100%;
}
.es-answer-label {
    margin: 14px 0 4px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--es-muted);
}
.es-answer-list {
    margin: 0;
    padding-left: 18px;
    font-size: 13.5px;
    line-height: 20px;
}
.es-answer-note {
    margin-top: 10px;
    color: var(--es-muted);
    font-size: 13px;
}
.es-answer-facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 16px;
    margin: 0 0 12px;
    font-size: 13.5px;
}
.es-answer-facts dt { color: var(--es-muted); }
.es-answer-facts dd { margin: 0; }

/* An error explained above the numbers of a failed request. */
.es-alert {
    padding: 12px 14px;
    border-radius: var(--es-radius-control);
    background: var(--es-over-wash);
    color: var(--es-over-ink);
    font-size: 13.5px;
    line-height: 20px;
}
.es-alert--warn {
    background: var(--es-warn-wash);
    color: var(--es-warn-ink);
}
.es-alert small {
    display: block;
    margin-top: 6px;
    font-family: var(--es-font-mono);
    font-size: 12px;
    opacity: 0.85;
}

/* Totals under a table: one line for the whole selection. Filament adds a «Сводка» heading row
   and a separate line for the current page; the page subtotal only makes people add twice. */
.fi-ta-summary-header-row,
.fi-ta-summary-row:has(+ .fi-ta-summary-row) {
    display: none;
}
.fi-ta-summary-row > .fi-ta-cell {
    background: var(--es-page);
    border-top: 1px solid var(--es-hairline);
}
.fi-ta-summary-row > .fi-ta-cell.fi-ta-summary-row-heading-cell:first-child {
    padding-inline-start: 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--es-muted);
}
.fi-ta-text-summary {
    padding: 10px 12px;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}
.fi-ta-text-summary-label {
    display: none;
}

/* ---------- Tables on a phone ---------- */

/* Filament stacks every cell under its own label: a request took 340 px, a page of 25 — 8500.
   Here a row folds into two tiers instead: the first column is the line's title, the rest follow
   in small muted text, «⋯» sits in the corner. `display` of the cells is left to Filament —
   it hides the columns marked visibleFrom(); unlayered rules here would override that. */
@media (max-width: 639.98px) {
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        column-gap: 12px;
        row-gap: 2px;
        padding: 10px 44px 10px 16px;
        /* Padding inside the width, or the row ends up 4 px wider than the block. */
        box-sizing: border-box;
        width: 100%;
    }
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > .fi-ta-cell {
        min-width: 0;
        max-width: 100%;
    }
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > .fi-ta-cell {
        padding: 0;
    }
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > .fi-ta-cell > .fi-ta-cell-label {
        display: none;
    }
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row .fi-ta-text:not(.fi-inline),
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > .fi-ta-cell:first-child .fi-ta-text:not(.fi-inline) {
        padding: 0;
    }
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > .fi-ta-cell:first-child {
        flex-basis: 100%;
    }
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > .fi-ta-cell:first-child .fi-ta-text-item {
        font-size: 14.5px;
        font-weight: 500;
    }
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > .fi-ta-cell:not(:first-child) .fi-ta-text-item {
        font-size: 12.5px;
        color: var(--es-muted);
    }
    /* The «⋯» button is wider than its cell: 8 from the edge keeps it inside the block. */
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > .fi-ta-cell:has(> .fi-ta-actions) {
        position: absolute;
        top: 6px;
        right: 8px;
        padding: 0;
    }
    /* The row is as wide as the screen minus its padding and the «⋯» corner. */
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row .es-truncate {
        max-width: calc(100vw - 32px - 60px - 16px);
    }
    /* Totals fold badly into the stack; on a phone they are left to the desktop and «Расходы». */
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-summary-row,
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-summary-header-row,
    .fi-ta-table.fi-ta-table-stacked-on-mobile > tfoot {
        display: none;
    }
}

/* «Обзор»: funnel and retention side by side on a wide screen. */
.es-engagement {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}
/* On a phone the retention table scrolls inside its card, not the page. */
.es-engagement .fi-section-content { overflow-x: auto; }
@media (min-width: 1280px) {
    .es-engagement { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); align-items: start; }
}

/* Journals and JSON in a card: monospace, wrapped, scrolls inside itself when long. */
.es-code {
    margin: 0;
    max-height: 60vh;
    overflow: auto;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--es-page);
    border: 1px solid var(--es-hairline);
    color: var(--es-text);
    font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.es-nowrap { white-space: nowrap; }

/* Support chat in a ticket card: the person on the left, answers indented on the right. */
.es-chat { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.es-chat__line { padding: 10px 12px; border-radius: 10px; background: var(--es-page); border: 1px solid var(--es-hairline); max-width: 88%; }
.es-chat__line--assistant, .es-chat__line--owner { justify-self: end; background: var(--es-raised); }
.es-chat__line--owner { border-color: var(--es-accent); }
.es-chat__meta { font-size: 12px; color: var(--es-muted); margin-bottom: 4px; }
.es-chat__text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--es-text); }

/* Filter button: Filament always shows the active-filter count, «0» included, half outside the
   card. The count sits on the button's corner inside the card, and a zero is hidden (runtime). */
.fi-ta-header-toolbar .fi-icon-btn > .fi-icon-btn-badge-ctn {
    top: -2px;
    inset-inline-start: auto;
    inset-inline-end: -6px;
    transform: none;
    background: transparent;
}
.fi-ta-header-toolbar .fi-icon-btn > .fi-icon-btn-badge-ctn.es-zero { display: none; }
