/* public/css/components.css — the component library (docs/UI-GUIDE.md §5): buttons, cards, KPI tiles, chips,
   segmented control, toggle, tables, forms, toast, confidence meter, skeletons, empty state, dialog, legend, charts.
   Behaviour lives in public/js/ui/*.js; this file only styles the markup those modules produce. */

/* ------------------------------------------------------------------ brand mark */
/* The logo: three rising bars with a trend line breaking out above them. The glyph fills the tile that
   .brand-mark (pages.css) and .login-mark (login.css) paint, and takes the tile's white as currentColor.
   The trend is stroked twice from the same <use>: fat in the tile colour first, so the white line keeps a
   clean gap where it crosses the bars, then thin in white. The halo colour lives here and not in a
   stroke="var(--brand)" attribute — var() inside an SVG presentation attribute is not reliable everywhere. */
.brand-glyph { inline-size: 100%; block-size: 100%; display: block; }
.brand-glyph .glyph-halo { stroke: var(--brand); }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 22px; border-radius: var(--pill);
  font-size: 15px; font-weight: 700; line-height: 1.2; white-space: nowrap;
  color: var(--ink); background: transparent; border: 0;
  transition: background-color 150ms var(--ease-out), color 150ms var(--ease-out), box-shadow 150ms var(--ease-out), transform 100ms var(--ease-out), opacity 150ms;
  -webkit-tap-highlight-color: transparent; user-select: none; position: relative;
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: scale(.975); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-deep); }
.btn-ghost { box-shadow: inset 0 0 0 1.5px var(--hairline); color: var(--ink); background: var(--paper); }
.btn-ghost:hover:not(:disabled) { background: var(--tint); box-shadow: inset 0 0 0 1.5px var(--brand-soft); }
.btn-plain { color: var(--brand-deep); padding-inline: 12px; }
.btn-plain:hover:not(:disabled) { background: var(--tint); }
.btn-danger { background: var(--bad-bg); color: var(--bad-ink); }
.btn-danger:hover:not(:disabled) { background: var(--bad-soft); }
.btn-sm { min-height: 44px; padding: 8px 16px; font-size: 14px; }
.btn-icon { width: 44px; min-width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 44px; min-width: 44px; }
.btn-block { width: 100%; }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading .spinner { position: absolute; inset: 0; margin: auto; }
.btn-primary.is-loading .spinner { border-color: color-mix(in srgb, currentColor 32%, transparent); border-block-start-color: currentColor; }
.btn-group { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none; display: inline-block;
  border: 2px solid var(--hairline); border-block-start-color: var(--brand);
  animation: spin 700ms linear infinite;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--paper); border-radius: var(--radius-xl); box-shadow: var(--shadow-1);
  padding: 24px; min-width: 0; position: relative;
}
.card-sm { border-radius: var(--radius-lg); padding: 16px; }
.card-tint { background: var(--tint); box-shadow: none; }
.card-flat { box-shadow: none; border: 1px solid var(--hairline); }
.card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; margin-block-end: 16px; }
.card-title { font-size: 19px; line-height: 1.3; font-weight: 700; color: var(--ink); }
.card-subtitle { font-size: 13.5px; font-weight: 500; color: var(--soft-text); margin-block-start: 2px; }
/* min-width: 0 is what lets the period selector inside actually obey its own max-width: 100% and scroll: a flex
   item defaults to min-width: auto, so without this the selector forces the whole PAGE wider than a phone screen
   and the body scrolls sideways. */
.card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-inline-start: auto; min-width: 0; max-width: 100%; }
.card-body { min-width: 0; }
.card-footer { margin-block-start: 16px; padding-block-start: 12px; border-block-start: 1px solid var(--hairline); font-size: 13.5px; color: var(--body); }
@media (max-width: 767px) { .card { padding: 16px; border-radius: var(--radius-lg); } }

/* ------------------------------------------------------------------ KPI tile */
.kpi { display: flex; flex-direction: column; gap: 6px; padding: 24px; background: var(--paper); border-radius: var(--radius-xl); box-shadow: var(--shadow-1); min-width: 0; }
.kpi-label { font-size: 13px; line-height: 1.3; font-weight: 600; color: var(--soft-text); }
.kpi-value { font-variant-numeric: tabular-nums; color: var(--ink); line-height: 1.1; letter-spacing: -.012em; font-weight: 800; overflow-wrap: normal; }
.kpi-value.size-display { font-size: 44px; letter-spacing: -.015em; line-height: 1.08; }
.kpi-value.size-h1 { font-size: 32px; }
.kpi-value.size-h2 { font-size: 24px; font-weight: 700; }
.kpi-value .num { display: inline; }
.kpi-value.is-negative { color: var(--bad-ink); }
.kpi-value.size-display.is-long { font-size: 36px; }
.kpi-value.size-display.is-xlong { font-size: 30px; }
.kpi-value.size-h1.is-long { font-size: 27px; }
.kpi-value.size-h1.is-xlong { font-size: 23px; }
.kpi-value.size-h2.is-long { font-size: 21px; }
.kpi-value.size-h2.is-xlong { font-size: 18px; }
.kpi-value .unknown { font-size: .6em; }
.kpi-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 22px; }
.kpi-sub { font-size: 13.5px; font-weight: 500; color: var(--body); }
.kpi-hint { font-family: var(--mono); font-size: 12.5px; color: var(--soft-text); direction: ltr; unicode-bidi: isolate; text-align: start; }
@media (max-width: 767px) { .kpi { padding: 16px; border-radius: var(--radius-lg); } .kpi-value.size-display { font-size: 36px; } .kpi-value.size-h1 { font-size: 28px; } .kpi-value.size-display.is-long, .kpi-value.size-display.is-xlong { font-size: 28px; } .kpi-value.size-h1.is-long, .kpi-value.size-h1.is-xlong { font-size: 22px; } }

/* ------------------------------------------------------------------ chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 700; line-height: 1; white-space: nowrap; vertical-align: middle;
  background: var(--neutral-bg); color: var(--neutral-ink);
}
.chip .icon { width: 14px; height: 14px; stroke-width: 2.2; }
.chip-ok { background: var(--ok-bg); color: var(--ok-ink); }
.chip-warn { background: var(--warn-bg); color: var(--warn-ink); }
.chip-bad { background: var(--bad-bg); color: var(--bad-ink); }
.chip-neutral { background: var(--neutral-bg); color: var(--neutral-ink); }
.chip-brand { background: var(--tint); color: var(--brand-deep); }
.chip-sm { padding: 4px 10px; font-size: 12px; }
.chip-count { background: var(--well); padding: 2px 7px; border-radius: 999px; font-size: 11.5px; margin-inline-start: 2px; }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

/* ------------------------------------------------------------------ segmented control */
.seg {
  position: relative; display: inline-flex; align-items: stretch; gap: 2px; padding: 4px; min-height: 44px;
  border-radius: var(--pill); background: var(--well); isolation: isolate; max-width: 100%;
  overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg-indicator {
  position: absolute; top: 4px; bottom: 4px; left: 0; width: 0; z-index: 0; border-radius: var(--pill);
  background: var(--paper); box-shadow: var(--shadow-1); opacity: 0;
  transition: transform 250ms var(--ease-out), width 250ms var(--ease-out), opacity 150ms;
}
.seg.is-ready .seg-indicator { opacity: 1; }
.seg-btn {
  position: relative; z-index: 1; flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: var(--pill);
  font-size: 14.5px; font-weight: 600; color: var(--body); white-space: nowrap;
  transition: color 150ms var(--ease-out), transform 100ms;
}
.seg-btn:hover:not(:disabled) { color: var(--ink); }
.seg-btn[aria-checked="true"] { color: var(--ink); font-weight: 700; }
.seg-btn:active:not(:disabled) { transform: scale(.975); }
.seg-btn:disabled { opacity: .45; }
.seg-sm { min-height: 46px; padding: 3px; }
.seg-sm .seg-btn { min-height: 40px; padding: 0 12px; font-size: 13.5px; }
.seg-sm .seg-indicator { top: 3px; bottom: 3px; }
.seg-block { display: flex; width: 100%; }

/* ------------------------------------------------------------------ toggle switch */
.toggle { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 4px 6px; border-radius: var(--pill); font-size: 14.5px; font-weight: 600; color: var(--ink); }
.toggle-track { position: relative; width: 44px; height: 26px; border-radius: 13px; background: var(--track); transition: background-color 200ms var(--ease-out); flex: none; }
.toggle-knob { position: absolute; top: 2px; inset-inline-start: 2px; width: 22px; height: 22px; border-radius: 50%; background: var(--knob); box-shadow: 0 1px 3px var(--scrim); transition: transform 200ms var(--ease-out); }
.toggle[aria-checked="true"] .toggle-track { background: var(--brand); }
.toggle[aria-checked="true"] .toggle-knob { transform: translateX(18px); }
[dir=rtl] .toggle[aria-checked="true"] .toggle-knob { transform: translateX(-18px); }
.toggle:disabled { opacity: .5; }
.toggle-label { white-space: nowrap; }
.toggle-hint { font-size: 12.5px; font-weight: 500; color: var(--soft-text); }

/* ------------------------------------------------------------------ tables */
.table-scroll { overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; max-width: 100%; border-radius: var(--radius-md); }
.table-scroll.is-tall { max-height: 70vh; overflow-y: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 15px; }
.table caption { text-align: start; font-size: 13.5px; font-weight: 600; color: var(--soft-text); padding-block-end: 8px; }
.table th {
  position: sticky; top: 0; z-index: 2; background: var(--paper); text-align: start;
  font-size: 13px; font-weight: 700; color: var(--soft-text); padding: 10px 12px; white-space: nowrap;
  border-block-end: 1px solid var(--hairline); vertical-align: bottom;
}
.table td { padding: 12px; border-block-end: 1px solid var(--rule); vertical-align: middle; min-width: 0; }
/* body { overflow-wrap: anywhere } (base.css) would give an auto-layout table's wrapping column a min-content
   width of ONE character while every other column is nowrap — the reason / inputs columns collapsed to ~37px and
   rows grew past 700px. Cells break between words only, and a wrapping column carries a real minimum width; the
   table keeps scrolling inside .table-scroll when the sum no longer fits. */
.table td, .table th { overflow-wrap: normal; }
.table tbody tr { transition: background-color 150ms var(--ease-out); }
.table tbody tr:hover { background: var(--tint); }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-open { background: var(--tint); }
/* the status stripe belongs on the row's INLINE-START edge (the right one in RTL), not the physical left */
.table tbody tr.is-bad { box-shadow: inset 3px 0 0 var(--bad-ink); }
.table tbody tr.is-warn { box-shadow: inset 3px 0 0 var(--warn-ink); }
[dir=rtl] .table tbody tr.is-bad { box-shadow: inset -3px 0 0 var(--bad-ink); }
[dir=rtl] .table tbody tr.is-warn { box-shadow: inset -3px 0 0 var(--warn-ink); }
.table tbody tr.is-total td { font-weight: 800; border-block-start: 2px solid var(--hairline); border-block-end: 0; background: var(--canvas); }
.table th.num, .table td.num-cell { text-align: end; }
.table td.num-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .cell-wrap { white-space: normal; overflow-wrap: break-word; min-width: 22ch; }
.table .cell-clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 42ch; }
.table.is-dense td { padding: 8px 10px; font-size: 14px; }
.table .th-sort { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 10px 6px; margin: -10px -6px; border-radius: 8px; color: inherit; font: inherit; }
.table .th-sort:hover { background: var(--tint); color: var(--ink); }
.table .th-sort .icon { width: 14px; height: 14px; opacity: .55; }
.table th[aria-sort="ascending"] .th-sort, .table th[aria-sort="descending"] .th-sort { color: var(--ink); }
.table th[aria-sort="ascending"] .icon, .table th[aria-sort="descending"] .icon { opacity: 1; color: var(--brand-deep); }
.table th[aria-sort="descending"] .icon { transform: scaleY(-1); }
.table .row-toggle { width: 44px; height: 44px; min-width: 44px; padding: 0; border-radius: 50%; display: inline-grid; place-items: center; color: var(--body); margin: -10px -4px; }
.table .row-toggle:hover { background: var(--well); color: var(--ink); }
.table .row-toggle .icon { transition: transform 200ms var(--ease-out); }
.table .row-toggle[aria-expanded="true"] .icon { transform: rotate(180deg); }
.table tr.row-details > td { background: var(--canvas); padding: 12px 16px 16px; }
.table tr.row-details:hover { background: transparent; }
.table .td-toggle { width: 44px; padding-inline: 6px; }
.table-empty td { padding: 0; }
.table-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding-block-start: 12px; font-size: 13.5px; color: var(--soft-text); }
.pager { display: inline-flex; align-items: center; gap: 4px; }
.pager .btn { min-height: 44px; }

/* ------------------------------------------------------------------ forms */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); align-items: start; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 14.5px; font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.field-label .req { color: var(--bad-ink); }
.field-help { font-size: 13px; line-height: 1.4; color: var(--soft-text); }
.field-error { display: none; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--bad-ink); }
.field-error .icon { width: 15px; height: 15px; }
.field.is-invalid .field-error { display: inline-flex; }
.input, .select, .textarea {
  min-height: 44px; width: 100%; padding: 10px 14px; border: 1.5px solid var(--hairline); border-radius: var(--radius-md);
  background: var(--paper); color: var(--ink); font-size: 16px; line-height: 1.3; transition: border-color 150ms, box-shadow 150ms;
}
.textarea { min-height: 88px; resize: vertical; }
.select { appearance: none; -webkit-appearance: none; padding-inline-end: 40px; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2355555a' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 12px center; background-size: 18px; }
[dir=ltr] .select { background-position: right 12px center; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--field-line); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus-ring); }
.input::placeholder, .textarea::placeholder { color: var(--soft-text); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--canvas); color: var(--soft-text); }
.input.num, .input[type=number], .input[type=date], .input[type=time] { direction: ltr; text-align: end; font-variant-numeric: tabular-nums; }
.input[type=date], .input[type=time] { text-align: start; }
.input-affix { position: relative; display: flex; align-items: center; }
.input-affix .input { padding-inline-end: 44px; }
.input-affix .affix { position: absolute; inset-inline-end: 14px; color: var(--soft-text); font-weight: 600; pointer-events: none; }
.field.is-invalid .input, .field.is-invalid .select, .field.is-invalid .textarea { border-color: var(--bad-ink); }
.field.is-invalid .input:focus-visible { box-shadow: 0 0 0 3px var(--focus-bad); }
.checkbox { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; cursor: pointer; }
.checkbox input { width: 20px; height: 20px; accent-color: var(--brand); margin: 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-start; padding-block-start: 4px; }
.form-note { font-size: 13.5px; color: var(--body); display: flex; gap: 8px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-md); background: var(--canvas); }
.form-note .icon { flex: none; margin-block-start: 2px; color: var(--soft-text); }

/* ------------------------------------------------------------------ toast */
.toasts {
  position: fixed; inset-block-end: 24px; inset-inline-start: 24px; z-index: 80;
  display: flex; flex-direction: column-reverse; gap: 8px; pointer-events: none; max-width: min(440px, calc(100vw - 48px));
}
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
  background: var(--inverse-bg); color: var(--inverse-ink); border-radius: var(--radius-md); box-shadow: var(--shadow-2);
  font-size: 14.5px; font-weight: 500; line-height: 1.4;
  opacity: 0; transform: translateY(8px); transition: opacity 250ms var(--ease-out), transform 250ms var(--ease-out);
}
.toast.is-in { opacity: 1; transform: none; }
.toast.is-out { opacity: 0; transform: translateY(8px); transition-duration: 180ms; transition-timing-function: var(--ease-in); }
.toast .icon { flex: none; margin-block-start: 1px; }
.toast-ok .icon { color: var(--inverse-ok); }
.toast-warn .icon { color: var(--inverse-warn); }
.toast-bad .icon { color: var(--inverse-bad); }
.toast-info .icon { color: var(--inverse-info); }
.toast-text { flex: 1 1 auto; min-width: 0; }
.toast-title { font-weight: 700; display: block; }
.toast .btn { min-height: 32px; padding: 4px 10px; font-size: 13.5px; color: var(--inverse-ink); }
.toast .btn-plain:hover { background: var(--inverse-well); }
.toast-close { width: 44px; height: 44px; min-width: 44px; border-radius: 50%; display: inline-grid; place-items: center; color: var(--inverse-soft); margin: -10px; margin-inline-start: 0; }
.toast-close:hover { background: var(--inverse-well); color: var(--inverse-ink); }
@media (max-width: 767px) { .toasts { inset-block-end: calc(var(--bottom-nav-h) + 12px + env(safe-area-inset-bottom)); inset-inline: 12px; max-width: none; } }

/* ------------------------------------------------------------------ confidence meter */
.meter { display: flex; flex-direction: column; gap: 10px; }
.meter-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.meter-label { font-size: 13px; font-weight: 600; color: var(--soft-text); }
.meter-value { font-size: 32px; line-height: 1; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.012em; }
.meter-value.is-met { color: var(--ok-ink); }
.meter-track { position: relative; height: 14px; border-radius: 999px; background: var(--neutral-bg); overflow: visible; }
.meter-fill { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: 999px; background: var(--brand); transition: width 600ms var(--ease-out); min-width: 0; }
.meter-fill.is-met { background: var(--ok-ink); }
.meter-tick { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--ink); border-radius: 2px; transform: translateX(50%); }
[dir=ltr] .meter-tick { transform: translateX(-50%); }
.meter-tick-label { position: absolute; top: 100%; margin-block-start: 6px; font-size: 12px; font-weight: 600; color: var(--body); transform: translateX(50%); white-space: nowrap; }
[dir=ltr] .meter-tick-label { transform: translateX(-50%); }
.meter-text { font-size: 14.5px; line-height: 1.45; color: var(--body); padding-block-start: 14px; }
.meter-text strong { color: var(--ink); }

/* ------------------------------------------------------------------ skeleton (loading) */
.skeleton {
  position: relative; overflow: hidden; color: transparent !important; border-radius: 8px; pointer-events: none; user-select: none;
  background: linear-gradient(90deg, var(--neutral-bg) 25%, var(--sheen) 37%, var(--neutral-bg) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
}
.skeleton * { visibility: hidden; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.sk-text { height: 14px; margin-block: 6px; }
.sk-text.w-60 { width: 60%; } .sk-text.w-40 { width: 40%; } .sk-text.w-80 { width: 80%; }
.sk-title { height: 28px; width: 40%; margin-block-end: 12px; }
.sk-kpi { height: 132px; border-radius: var(--radius-xl); }
.sk-chart { height: 260px; border-radius: var(--radius-lg); }
.sk-row { height: 44px; margin-block: 6px; }
.sk-block { height: 180px; border-radius: var(--radius-lg); }
.sk-pill { height: 44px; width: 240px; border-radius: var(--pill); }

/* ------------------------------------------------------------------ empty state */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 40px 20px; color: var(--body); }
.empty-icon { width: 56px; height: 56px; border-radius: 50%; background: var(--tint); color: var(--brand-deep); display: grid; place-items: center; margin-block-end: 6px; }
.empty-title { font-size: 19px; font-weight: 700; color: var(--ink); }
.empty-text { max-width: 46ch; font-size: 15px; line-height: 1.5; }
.empty .btn { margin-block-start: 8px; }
.empty-sm { padding: 24px 16px; }

/* ------------------------------------------------------------------ error card */
.error-card { border: 1px solid var(--bad-edge); background: var(--bad-bg); color: var(--bad-ink); border-radius: var(--radius-lg); padding: 16px 20px; display: flex; gap: 12px; align-items: flex-start; }
.error-card .icon { flex: none; margin-block-start: 2px; }
.error-card-title { font-weight: 700; }
.error-card-text { font-size: 14.5px; margin-block-start: 2px; color: var(--bad-ink); overflow-wrap: anywhere; }
.error-card .btn { margin-inline-start: auto; align-self: center; }

/* ------------------------------------------------------------------ dialog */
.dialog {
  border: 0; padding: 0; margin: auto; background: var(--paper); color: var(--ink);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-2); width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  overflow: auto;
}
.dialog::backdrop { background: var(--scrim); animation: fade-in 250ms var(--ease-out); }
.dialog[open] { animation: dialog-in 250ms var(--ease-out); }
.dialog.is-closing { animation: dialog-out 180ms var(--ease-in) forwards; }
.dialog.is-closing::backdrop { animation: fade-out 180ms var(--ease-in) forwards; }
@keyframes dialog-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes dialog-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: scale(.96); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
.dialog-inner { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dialog-title { font-size: 19px; font-weight: 700; line-height: 1.3; }
.dialog-body { font-size: 15.5px; line-height: 1.5; color: var(--body); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; padding-block-start: 6px; }
.dialog-actions .btn:first-child { order: -1; }

/* ------------------------------------------------------------------ legend, charts */
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13.5px; font-weight: 600; color: var(--body); }
.legend-item { display: inline-flex; align-items: center; gap: 8px; min-height: 24px; }
/* The hairline is not decoration: the profit remainder is drawn in --ok-bg, a very pale green, and at 14px that
   swatch was invisible against the card — the one entry in the key that mattered most had no mark beside it. */
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; background: var(--swatch, var(--brand)); box-shadow: inset 0 0 0 1px var(--rule); }
.legend-swatch.is-line { height: 0; width: 18px; border-radius: 0; border-block-start: 3px solid var(--swatch, var(--brand)); background: none; }
.legend-swatch.is-dashed { border-block-start-style: dashed; }
.legend-value { color: var(--soft-text); font-weight: 500; }

.chart { position: relative; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.chart-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.chart-body { position: relative; min-width: 0; }
.chart-svg { width: 100%; height: auto; display: block; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart-svg text { font-size: 12px; fill: var(--body); }
.chart-svg .axis-label { font-size: 12px; fill: var(--soft-text); }
.chart-svg .grid line { stroke: var(--hairline); stroke-opacity: .4; }
.chart-svg .axis line, .chart-svg .axis path { stroke: var(--hairline); }
.chart-svg .chart-bar { transform-box: fill-box; transform-origin: bottom; animation: bar-grow 500ms var(--ease-out) both; animation-delay: calc(var(--i, 0) * 20ms); }
.chart-svg .chart-bar.is-negative { transform-origin: top; }
.chart-svg .chart-bar:hover, .chart-svg .chart-bar:focus-visible, .chart-svg .chart-segment:hover, .chart-svg .chart-segment:focus-visible { filter: brightness(.92); outline: none; }
.chart-svg .chart-bar:focus-visible, .chart-svg .chart-segment:focus-visible, .chart-svg .chart-point:focus-visible { stroke: var(--ink); stroke-width: 2; }
.chart-svg .chart-line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .chart-line.is-draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: line-draw 700ms var(--ease-out) forwards; }
.chart-svg .chart-line.is-dashed { animation: fade-in 700ms var(--ease-out) both; }
.chart-svg .chart-point { transition: r 120ms var(--ease-out); }
.chart-svg .chart-point:hover { r: 5.5; }
.chart-svg .chart-value { font-size: 11.5px; fill: var(--body); font-weight: 600; }
.chart-svg .chart-segment-label { font-size: 12px; font-weight: 700; fill: var(--on-accent); pointer-events: none; }
.chart-svg .zero-line { stroke: var(--soft-text); stroke-width: 1; }
@keyframes bar-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes line-draw { to { stroke-dashoffset: 0; } }
.chart.no-anim .chart-bar, .chart.no-anim .chart-line { animation: none; stroke-dashoffset: 0; transform: none; }
.chart-tooltip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 120px; max-width: 260px;
  background: var(--inverse-bg); color: var(--inverse-ink); padding: 8px 12px; border-radius: 10px; font-size: 13px; line-height: 1.4; box-shadow: var(--shadow-2);
  opacity: 0; transition: opacity 120ms var(--ease-out); transform: translate(-50%, calc(-100% - 10px));
}
.chart-tooltip.is-visible { opacity: 1; }
.chart-tooltip.is-below { transform: translate(-50%, 12px); }
.chart-tooltip-title { font-weight: 700; margin-block-end: 2px; display: block; }
.chart-tooltip-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.chart-tooltip-row .num { font-weight: 600; }
.chart-tooltip .legend-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-inline-end: 6px; vertical-align: middle; }
.chart-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.chart-table { margin-block-start: 4px; }
.chart-note { font-size: 13px; color: var(--soft-text); }

/* ------------------------------------------------------------------ reveal on first paint */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity 600ms var(--ease-out), transform 600ms var(--ease-out); transition-delay: calc(var(--i, 0) * 40ms); will-change: opacity, transform; }
.reveal.is-in { opacity: 1; transform: none; }

/* ------------------------------------------------------------------ misc blocks */
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 14px; color: var(--body); padding: 10px 14px; border-radius: var(--radius-md); background: var(--warn-bg); color: var(--warn-ink); }
.status-line.is-clean { background: var(--ok-bg); color: var(--ok-ink); }
.status-line .icon { flex: none; }
.status-line a { color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14.5px; align-items: baseline; }
.kv dt { color: var(--soft-text); font-weight: 600; }
.kv dd { color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.divider { height: 1px; background: var(--hairline); margin-block: 16px; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.note { font-size: 13.5px; color: var(--soft-text); }
.callout { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: var(--radius-md); background: var(--tint); color: var(--ink); font-size: 14.5px; line-height: 1.5; }
.callout .icon { flex: none; margin-block-start: 2px; color: var(--brand-deep); }
.callout-warn { background: var(--warn-bg); color: var(--warn-ink); } .callout-warn .icon { color: var(--warn-ink); }
.callout-bad { background: var(--bad-bg); color: var(--bad-ink); } .callout-bad .icon { color: var(--bad-ink); }
.callout-ok { background: var(--ok-bg); color: var(--ok-ink); } .callout-ok .icon { color: var(--ok-ink); }

/* ── Profitability alarm (docs/UI-GUIDE.md §5) ─────────────────────────────────────────────────────────────────
   A blocking alert is pinned under the top bar on every page and cannot be hidden while it is true; a warning is
   the same component in a quieter palette. Colour never carries the meaning on its own: every row has an icon and
   the words "מה לעשות". */
.alert-bar { position: sticky; top: var(--topbar-h); z-index: 40; border-block-end: 1px solid var(--hairline); }
.alert-bar[hidden] { display: none !important; }
.alert-bar.is-blocking { background: var(--bad-bg); border-block-end-color: var(--bad-edge); }
.alert-bar.is-warning { background: var(--warn-bg); border-block-end-color: var(--warn-edge); }
.alert-details { max-width: 1200px; margin-inline: auto; padding-inline: var(--space-4); }
@media (min-width: 990px) { .alert-details { padding-inline: var(--space-6); } }
.alert-details > summary {
  display: flex; align-items: center; gap: var(--space-2); list-style: none; cursor: pointer;
  padding-block: var(--space-3); font-size: 15px; font-weight: 700; min-height: 44px;
}
.alert-details > summary::-webkit-details-marker { display: none; }
.alert-bar.is-blocking > .alert-details > summary { color: var(--bad-ink); }
.alert-bar.is-warning > .alert-details > summary { color: var(--warn-ink); }
.alert-summary-text { flex: 1 1 auto; }
.alert-expand { font-weight: 600; font-size: 13.5px; text-decoration: underline; }
.alert-details[open] > summary .alert-expand::after { content: ' (סגור)'; }
.alert-money { font-variant-numeric: tabular-nums; font-weight: 700; direction: ltr; unicode-bidi: isolate; }
.alert-list { display: grid; gap: var(--space-3); padding: 0 0 var(--space-4); margin: 0; list-style: none; }
.alert-row { background: var(--paper); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); box-shadow: var(--shadow-1); }
.alert-row-head { display: flex; align-items: center; gap: var(--space-2); font-size: 15px; }
.alert-row.alert-blocking .alert-row-head { color: var(--bad-ink); }
.alert-row.alert-warning .alert-row-head { color: var(--warn-ink); }
.alert-detail { margin-block-start: var(--space-1); font-size: 14.5px; color: var(--body); }
.alert-action { margin-block-start: var(--space-1); font-size: 14.5px; font-weight: 600; color: var(--ink); }
.alert-items { margin-block-start: var(--space-1); font-size: 13px; color: var(--soft-text); direction: ltr; unicode-bidi: isolate; text-align: start; }
.alert-row-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-block-start: var(--space-3); }
.dialog-alert .alert-list { padding-block-end: 0; }
.dialog-alert .alert-row { box-shadow: none; border: 1px solid var(--hairline); }

/* the "fetching fresh data" pill in the top bar */
.freshness-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: var(--pill);
  background: var(--tint); color: var(--brand-deep); font-size: 13px; font-weight: 700;
}
.freshness-pill[hidden] { display: none !important; }
.freshness-pill .icon { width: 15px; height: 15px; }
@media (prefers-reduced-motion: no-preference) {
  .freshness-pill.is-busy .icon { animation: agd-spin 1.1s linear infinite; }
  @keyframes agd-spin { to { transform: rotate(360deg); } }
}

/* The advertising row in the cost breakdown wears Meta blue, matching its segment in the bar; the gross row is the
   header the percentages below are a share of. */
.table tr.is-meta td:first-child { box-shadow: inset 2px 0 0 var(--meta); }
[dir="rtl"] .table tr.is-meta td:first-child { box-shadow: inset -2px 0 0 var(--meta); }
.table tr.is-meta td { color: var(--meta-text); font-weight: 600; }
.table tr.is-head td { background: var(--tint); font-weight: 700; }
.table tr.is-head td:first-child { border-start-start-radius: var(--radius-md); }
.table tr.is-head td:last-child { border-start-end-radius: var(--radius-md); }
