﻿/*
 * The dashboard: quick actions, sections, cards and the charts on them.
 *
 * Its own file for the same reason it had one before the conversion - it is the only screen in the
 * app with a layout nothing else shares, and folding it into layouts.css would put a third of that
 * file behind one route.
 */

/* ==========================================================================
   Quick actions

   The jobs this role may start. Above every section, because a widget belongs to a section and
   these belong above all of them.
   ========================================================================== */

.quick {
    display: grid;
    gap: var(--space-3);
    /*
     * Wide enough for the longest caption in the catalogue. At 150 the cards fitted seven to a
     * row and truncated four of them - "Add Custo...", "New Quota..." - which is worse than
     * fitting fewer: a card whose verb you cannot read is a card nobody presses.
     */
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.quick__card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--pos-border);
    border-radius: var(--radius-surface);
    background: var(--grad-glass);
    box-shadow: var(--glass-edge);
    color: var(--pos-text);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    min-width: 0;
}

.quick__card {
    transition:
        background var(--motion-fast) var(--ease-out),
        border-color var(--motion-fast) var(--ease-out),
        box-shadow var(--motion-fast) var(--ease-out),
        transform var(--motion-fast) var(--ease-out);
}

/*
 * These are the jobs this role may start, and the strip sits above every section on the
 * dashboard - so they are allowed to be the most expressive surface in the app. Still one
 * pixel of lift and one level of shadow: the same vocabulary as everything else.
 */
.quick__card:hover {
    box-shadow: var(--elev-2);
    border-color: var(--pos-border-strong);
    transform: translateY(-1px); background: var(--pos-surface-hover); border-color: var(--pos-border-strong); }

.quick__card:active { transform: translateY(0); box-shadow: var(--elev-1); }

.quick__icon {
    display: grid;
    place-items: center;
    width: var(--control-height-lg);
    height: var(--control-height-lg);
    flex-shrink: 0;
    border-radius: var(--radius);
    background: var(--pos-primary-soft);
    color: var(--pos-primary);
}

/*
 * Wraps rather than truncating. These are verbs somebody is looking for by name, and two short
 * lines read where one clipped line does not.
 */
.quick__title { min-width: 0; line-height: 1.2; }

/* ==========================================================================
   Sections
   ========================================================================== */

.band { display: grid; gap: var(--space-2); }

.band__head { display: flex; align-items: center; gap: var(--space-2); color: var(--pos-primary); }

.band__blurb { font-size: var(--text-xs); color: var(--pos-text-subtle); }

/*
 * Twelve columns, as the descriptors measure themselves in: a KPI asks for 3, a chart 6, a wide
 * table 12. The server decides the layout and this only honours it, through grid-column: span N
 * on the card itself.
 */
.band__grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-2);
}

/* ==========================================================================
   A card
   ========================================================================== */

.widget {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: var(--space-2);
    padding: var(--card-padding);
    border: 1px solid var(--pos-border);
    border-radius: var(--radius-surface);
    background: var(--grad-glass);
    min-width: 0;
    box-shadow: var(--elev-1), var(--glass-edge);
}

.widget__head { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }

/*
 * An accented tile, for a section asked to read louder than the rest of the page. Driven by two
 * CSS custom properties set inline per tile - --tile-accent and --tile-accent-soft - rather than
 * one modifier class per colour: six sections want six different tints and a class each would be
 * the same three rules copied six times. ReportKpiTile only ever hands this a var() it was given,
 * never a hex, so re-cutting a palette stays tokens.css's job.
 */
.widget--tinted {
    background: var(--tile-accent-soft);
    border-color: var(--tile-accent);
}

.widget--tinted .widget__title { color: var(--tile-accent); }

/* The glyph beside the title, in a neutral tint by default - the same soft-disc treatment a
   report family tile's icon already gets, just sized to sit beside a KPI's title instead of a
   card's. A tinted tile moves the icon onto the surface instead, so the colour reads as a ring
   around the glyph rather than the disc behind it matching the card underneath. A step above
   --icon-size-tile itself - the glyph inside is drawn at Tile size, and a disc the same size as
   its own glyph left it looking cramped. */
.widget__icon {
    display: grid;
    place-items: center;
    width: calc(var(--icon-size-tile) * 1.3);
    height: calc(var(--icon-size-tile) * 1.3);
    flex-shrink: 0;
    border-radius: var(--radius);
    background: var(--pos-primary-soft);
    color: var(--pos-primary);
}

.widget--tinted .widget__icon { background: var(--pos-surface); color: var(--tile-accent); }

/*
 * Every KPI section on Business Analysis is a card of its own rather than tiles loose on the
 * page. .card has no gap between its own children, so without this the heading sits flush against
 * the tile row beneath it.
 */
.summary-section-card { display: grid; gap: var(--space-3); }

/*
 * The amount is the loudest thing on a report's own KPI row, where six or more tiles share one
 * line and --text-2xl is the right size to carry that. On this page each tile has a card of its
 * own and a title above it, so the same size read as heavier than the layout needed - scoped
 * here rather than lowered for every report, which draws these tiles at their original size.
 */
.page--business-analysis .kpi__value { font-size: var(--text-xl); }

/* ==========================================================================
   KPI bar row

   A trial for Sales Summary: a figure as a horizontal bar rather than a tile, for a group where
   how the figures compare to each other matters more than any one of them read alone.

   THE CAPTION ("label: amount") IS DRAWN ACROSS THE WHOLE TRACK, ASKED FOR DIRECTLY - never
   clipped to the filled portion, which for a small share would hide the text on exactly the rows a
   reader most wants to compare against the largest one. .kpi-bar__track is the positioning context
   and .kpi-bar__caption is laid over it at inset: 0, so the text reads at a fixed place regardless
   of how far .kpi-bar__fill reaches under it.
   ========================================================================== */

.kpi-bar { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }

.kpi-bar__icon {
    display: grid;
    place-items: center;
    width: calc(var(--icon-size-tile) * 1.3);
    height: calc(var(--icon-size-tile) * 1.3);
    flex-shrink: 0;
    border-radius: var(--radius);
    background: var(--pos-surface-sunken);
}

.kpi-bar__track {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    height: calc(var(--text-sm) * 1.6);
    border-radius: var(--radius-pill);
    background: var(--pos-surface-sunken);
    overflow: hidden;
}

.kpi-bar__fill {
    display: block;
    height: 100%;
    border-radius: var(--radius-pill);
    /* A real colour by default, in case a caller's inline style is ever dropped - the inline
       background wins whenever one is set, so this only ever shows if that has gone missing. */
    background: var(--pos-primary);
    transition: width var(--motion-base) var(--ease-out);
}

/*
 * THE INK IS A TOKEN PAIR, NOT A COLOUR CHOSEN PER BAR. A fill can be any of the seven chart
 * colours, the brand colour or a status colour, so no single ink reads over all of them - var(
 * --pos-text) haloed in var(--pos-surface) (both already paired with a dark-theme twin) reads over
 * any of them without this component, or whoever calls it, reasoning about which colour a given
 * bar happens to be. The halo is several tight, zero-spread shadows rather than one soft one,
 * which is what keeps it reading as an outline around each letter rather than a blur behind them.
 */
.kpi-bar__caption {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    padding: 0 var(--space-3);
    font-size: var(--text-sm);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--pos-text);
    text-shadow:
        0 0 1px var(--pos-surface),
        0 0 1px var(--pos-surface),
        0 0 2px var(--pos-surface),
        0 0 2px var(--pos-surface);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* The two groups inside the Sales Summary card - what a sale is made of, and what came of it. A
   plain caption rather than a second .section-heading: the card's own heading already named the
   section, and a heading of equal weight for each half would read as two sections stacked in one
   card rather than one card split in two. */
.kpi-bar-group { display: grid; gap: var(--space-2); }
.kpi-bar-group__caption {
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--pos-text-subtle);
}

.widget__title {
    flex: 1;
    min-width: 0;
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--pos-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A chart's own Daily/Weekly/Monthly toggle, sized to its content rather than the field's usual
   full width - it sits beside the title in a header with no room to spare. */
.widget__granularity { flex-shrink: 0; width: auto; }

.widget__body { min-width: 0; }

.widget__busy { display: grid; place-items: center; padding: var(--space-5); }

/* A failing widget is a value, not an exception: one broken query says so in its own card and
   the other nineteen carry on. */
.widget__error {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--pos-warning);
}

.widget__table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }

/* The same filled primary band a data grid's header gets. A table on a card is still a table,
   and the ink is the on-brand token for the same reason it is there: it is white here and a
   near-black in the dark theme, where the primary is a light green. */
.widget__table th {
    padding: var(--space-1) var(--space-2);
    background: var(--pos-grid-header-bg);
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    color: var(--pos-on-brand);
    text-align: left;
    white-space: nowrap;
}

.widget__table td { padding: var(--space-2); border-bottom: 1px solid var(--pos-grid-line); }
.widget__table tbody tr:last-child td { border-bottom: 0; }
.widget__table td:not(:last-child) { border-right: 1px solid var(--pos-grid-cell-line); }
.widget__table th:not(:last-child) { border-right: 1px solid var(--pos-grid-header-divider); }
.widget__table tbody tr:hover td { background: var(--pos-grid-row-hover); }

/* ==========================================================================
   KPI
   ========================================================================== */

.kpi { display: grid; gap: var(--space-1); min-width: 0; }

.kpi__value {
    font-size: var(--text-2xl);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi__caption { font-size: var(--text-xs); color: var(--pos-text-muted); }

.kpi__change { display: flex; align-items: center; gap: var(--space-1); font-size: var(--text-xs); font-weight: 600; }

/*
 * Coloured by whether it is good news, not by its direction. Expenses rising and sales rising are
 * both increases; colouring them alike congratulates the reader on overspending.
 */
.kpi__change--good { color: var(--pos-accent); }
.kpi__change--bad { color: var(--pos-danger); }
.kpi__change--neutral { color: var(--pos-text-muted); }

.kpi__spark { width: 100%; height: var(--space-6); margin-top: var(--space-1); }

/* ==========================================================================
   Charts

   Everything is computed in a fixed 0-100 viewBox and stretched by CSS, so a chart is
   resolution-independent and needs no JavaScript to know how wide it is.
   ========================================================================== */

.chart { display: grid; gap: var(--space-2); min-width: 0; }

.chart__total { font-size: var(--text-xl); font-weight: 700; font-variant-numeric: tabular-nums; }

/*
 * The y axis' own column beside the plot, and the x axis' row beneath it. A grid rather than
 * flex, because the x axis has to line up under the svg alone and not under the numbers beside
 * it - .chart__axis is pinned to column 2 explicitly for exactly that reason.
 */
.chart__plot {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-1) var(--space-2);
}

.chart__yaxis {
    grid-column: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: right;
    font-size: var(--text-xs);
    color: var(--pos-text-subtle);
    font-variant-numeric: tabular-nums;
}

.chart__svg { grid-column: 2; width: 100%; height: 140px; overflow: visible; }

/*
 * Gridlines are scaffolding, and dashing them is what finally makes them read that way. Solid
 * hairlines at this spacing compete with a flat line series for attention - at a glance the eye
 * cannot tell which of the horizontals is data. A dash cannot be mistaken for a reading.
 */
.chart__grid {
    stroke: var(--pos-chart-grid);
    stroke-width: 1;
    stroke-dasharray: 2 4;
}

/* The baseline is not scaffolding - it is zero, and a figure sits on it. Solid. */

.chart__axis {
    grid-column: 2;
    display: flex;
    justify-content: space-between;
    gap: var(--space-2);
    font-size: var(--text-xs);
    color: var(--pos-text-subtle);
}

.chart__legend { display: flex; flex-wrap: wrap; gap: var(--space-3); font-size: var(--text-xs); }
.chart__key { display: inline-flex; align-items: center; gap: var(--space-1); }

.chart__swatch { width: 10px; height: 10px; flex-shrink: 0; border-radius: var(--radius-pill); }

.chart--slices { grid-template-columns: minmax(0, 120px) minmax(0, 1fr); align-items: center; }
.chart__pie { width: 100%; max-width: 120px; }

/* A report's pie - see SliceChart.Roomy. The legend scrolls at the pie's height. */
.chart--roomy { grid-template-columns: minmax(0, var(--report-pie-size)) minmax(0, 1fr); }
.chart--roomy .chart__pie { max-width: var(--report-pie-size); }
.chart--roomy .chart__breakdown {
    max-height: var(--report-pie-size);
    overflow-y: auto;
    align-self: center;
    padding-right: var(--space-2);
}

.chart__breakdown { display: grid; gap: var(--space-1); margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); }

.chart__breakdown li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: var(--space-2);
}

.chart__empty { grid-column: 1 / -1; padding: var(--space-5); text-align: center; }

/* ==========================================================================
   Activity feed
   ========================================================================== */

.feed { display: grid; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }

.feed__item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
    border-radius: var(--radius);
    transition: background var(--motion-instant) var(--ease-standard);
}

.feed__item:hover { background: var(--pos-surface-hover); }

.feed__icon {
    display: grid;
    place-items: center;
    width: var(--control-height-sm);
    height: var(--control-height-sm);
    border-radius: var(--radius-sm);
    background: var(--pos-surface-sunken);
    color: var(--pos-text-muted);
}

.feed__body { display: grid; gap: 1px; min-width: 0; }
.feed__title { font-size: var(--text-sm); font-weight: 600; }
.feed__detail { font-size: var(--text-xs); color: var(--pos-text-muted); }
.feed__when { font-size: var(--text-xs); color: var(--pos-text-subtle); white-space: nowrap; }

/* ==========================================================================
   Alerts

   Each carries the route to the screen that fixes it. An alert with no way through to it trains
   people to ignore the panel.
   ========================================================================== */

.alerts { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }

/*
 * An alert carries a bar down its leading edge in its own severity colour. The tinted fill alone
 * made three severities read as one list of grey rows, and a panel nobody can triage at a glance
 * is a panel people stop looking at - which is the failure the alerts feature exists to avoid.
 */
.alerts__item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    background: var(--pos-surface-sunken);
    border-left: 3px solid currentColor;
    transition: box-shadow var(--motion-fast) var(--ease-out);
}

.alerts__item--info { background: var(--pos-info-soft); color: var(--pos-info); }
.alerts__item--warning { background: var(--pos-warning-soft); color: var(--pos-warning); }
.alerts__item--critical { background: var(--pos-danger-soft); color: var(--pos-danger); }

/*
 * Hover lifts rather than recolouring. Every alert already carries its severity as its fill, and
 * a hover that painted over it would tell somebody a critical alert had stopped being one for as
 * long as the pointer sat on it.
 */
.alerts__item:hover { box-shadow: var(--elev-1); }

.alerts__body { display: grid; gap: 1px; min-width: 0; }
.alerts__title { font-size: var(--text-sm); font-weight: 650; }
.alerts__detail { font-size: var(--text-xs); opacity: 0.85; }

.alerts__count {
    padding: 1px var(--space-2);
    border-radius: var(--radius-pill);
    background: var(--pos-surface);
    font-size: var(--text-xs);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.alerts__clear {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--pos-accent);
}

/* ==========================================================================
   Responsive

   A twelve-column band on a narrow window is twelve unreadable slivers. The cards keep their
   relative weight in pairs, then stack.
   ========================================================================== */

/*
 * The widget grid collapses on ITS OWN width, not the window's.
 *
 * These were media queries at 1280 and 860, which is the fault CONVERSION.md records: the grid
 * sits to the right of a 224px rail, so at a 1280px window it only ever had ~1050px to lay out
 * in and collapsed a breakpoint early. The two heads disagreed by exactly --rail-width, and the
 * figure a media query names here is never the figure the grid actually gets.
 *
 * A container query asks the right question, and the thresholds below are content widths rather
 * than window widths for that reason.
 *
 * WHY THE CONTAINER IS HERE AND NOT ON .page. container-type implies contain: layout, which makes
 * the element a containing block for every position:fixed descendant. .lookup__list is fixed and
 * placed by pos.place against a rectangle read off the viewport - putting a container anywhere
 * above it would silently re-base those coordinates and drop every result list in the wrong
 * place, which is the keyboard path on New Sale. .band__grid contains charts and tables and no
 * fixed positioning at all, so it is safe; forms and pages are not, and stay on media queries.
 */
.band__grid { container-type: inline-size; container-name: band; }

@container band (max-width: 1050px) {
    .band__grid > .widget { grid-column: span 6 !important; }
}

@container band (max-width: 640px) {
    .band__grid > .widget { grid-column: span 12 !important; }
    .chart--slices { grid-template-columns: minmax(0, 1fr); justify-items: center; }
}
