/* Components: cards, page head, nav, tables, badges, chips, deltas, sparklines, toolbar. */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-1); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head.sub-head { margin-top: 20px; }
.meta { font-size: 12px; color: var(--text-3); }
.sec > * + * { margin-top: 12px; }
.stack { display: grid; gap: 8px; margin: 12px 0; }
.empty { display: grid; justify-items: start; gap: 12px; padding: 24px 8px; color: var(--text-2); }

/* Page head */
.page-head { display: grid; gap: 4px; }
.crumb a { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin-top: -8px; color: var(--text-2); text-decoration: none; font-weight: 500; }
.crumb a:hover { color: var(--text); }
.ph-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.ph-text { min-width: 0; display: grid; gap: 4px; }
.ph-sub { color: var(--text-2); max-width: 70ch; }
.ph-sub .mks { margin-inline-start: 8px; vertical-align: middle; }
.ph-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Nav */
.nav { display: grid; gap: 2px; }
.nav-a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 8px; color: var(--text-2); text-decoration: none; font-weight: 500; transition: background-color 150ms ease; }
.nav-a:hover { background: var(--surface-2); color: var(--text); }
.nav-a[aria-current="page"] { background: var(--surface-3); color: var(--text); }

/* Tables */
.table-wrap { position: relative; overflow-x: auto; overflow-y: hidden; max-width: 100%; border-radius: 8px; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; background-color: var(--surface);
  /* Scroll cue: an edge shadow appears on whichever side still has content to reveal (symmetric, so RTL needs no change) */
  background-image:
    linear-gradient(to right, var(--surface) 30%, transparent),
    linear-gradient(to left, var(--surface) 30%, transparent),
    radial-gradient(farthest-side at 0 50%, color-mix(in srgb, var(--text) 22%, transparent), transparent),
    radial-gradient(farthest-side at 100% 50%, color-mix(in srgb, var(--text) 22%, transparent), transparent);
  background-position: left center, right center, left center, right center;
  background-size: 36px 100%, 36px 100%, 12px 100%, 12px 100%;
  background-repeat: no-repeat;
  background-attachment: local, local, scroll, scroll; }
.table-wrap:focus-visible { outline: 2px solid var(--focus, var(--text)); outline-offset: 2px; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl thead th { background: var(--surface); font-size: 12px; font-weight: 600; color: var(--text-3); white-space: nowrap; border-bottom: 1px solid var(--line-2); }
.tbl tbody th { font-weight: 500; }
.tbl .num { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl .ctr { text-align: center; }
.tbl tbody tr[data-href] { cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tfoot th, .tbl tfoot td { font-weight: 600; border-bottom: 0; border-top: 1px solid var(--line-2); background: var(--surface-2); }
.tbl .c-brand { min-width: 200px; }
.tbl-sku, .tbl-claims, .tbl-pl { min-width: 760px; }
.tbl-sku { min-width: 900px; font-size: 13px; }
.tbl-sku th, .tbl-sku td { padding: 10px 8px; }
.tbl-reports, .tbl-team { min-width: 640px; }
.tbl-cov { min-width: 420px; }
.tbl tbody th.c-brand, .tbl thead th.c-brand { position: sticky; inset-inline-start: 0; background: var(--surface); z-index: 1; }
.tbl thead th.c-brand { z-index: 3; }
.tbl tbody tr:hover th.c-brand { background: var(--surface-2); }
.tbl tfoot th.c-brand { background: var(--surface-2); }
.bn { display: block; font-weight: 600; color: var(--text); }
.bc { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); font-weight: 400; }
.row-link { display: flex; flex-direction: column; justify-content: center; text-decoration: none; color: inherit; min-height: 44px; padding-block: 2px; }
.row-link:hover .bn { text-decoration: underline; text-underline-offset: 3px; }
.th-btn { position: relative; display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0; border: 0; background: none; color: inherit; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
/* 44px hit area without changing the visual size */
.th-btn::after { content: ""; position: absolute; top: 50%; inset-inline: -6px; min-width: 44px; height: 44px; transform: translateY(-50%); }
.th-btn:hover { color: var(--text); }
.th-ic { opacity: 0.6; }
th[aria-sort="ascending"] .th-btn, th[aria-sort="descending"] .th-btn { color: var(--text); }
th[aria-sort="ascending"] .th-ic, th[aria-sort="descending"] .th-ic { opacity: 1; }
.c-spark { width: 104px; }
.c-wait { color: var(--text-3); }
.wait { display: inline-flex; align-items: center; gap: 6px; }
.is-waiting td, .is-waiting th, .tbl tbody tr.is-waiting th.c-brand, .tbl tbody tr.is-waiting:hover th.c-brand { background: var(--surface-2); }
.tag-loss { padding: 1px 6px; border-radius: 4px; background: var(--loss-bg); color: var(--loss); font-weight: 600; font-size: 12px; }
.tbl .bc { white-space: nowrap; }
.cov.on { color: var(--profit); display: inline-flex; }
.cov.off { color: var(--text-3); }
.more { display: flex; justify-content: center; margin-top: 8px; }

/* Channel chips, badges */
.mks { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.mk { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 4px; min-height: 24px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--info-bg); color: var(--text-2); }
.b-healthy { background: var(--profit-bg); color: var(--profit); }
.b-thin { background: var(--warn-bg); color: var(--warn); }
.b-loss { background: var(--loss-bg); color: var(--loss); }
.sev-high { background: var(--loss-bg); color: var(--loss); }
.sev-med { background: var(--warn-bg); color: var(--warn); }
.sev-low { background: var(--info-bg); color: var(--text-2); }
.rs-sent { background: var(--profit-bg); color: var(--profit); }
.rs-review { background: var(--warn-bg); color: var(--warn); }
.role-owner { background: var(--surface-3); color: var(--text); }

/* Deltas, sparklines */
.delta { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; }
.d-good { color: var(--profit); }
.d-bad { color: var(--loss); }
.d-flat { color: var(--text-3); font-weight: 500; }
.vs { margin-inline-start: 6px; font-size: 12px; color: var(--text-3); }
.spark { overflow: visible; }
.spark polyline { fill: none; stroke: var(--text-3); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark circle { fill: var(--text-2); }
.spark .sp-zero { stroke: var(--line-2); stroke-dasharray: 2 3; }
.spark.sp-kept polyline { stroke: var(--text); }
.spark.sp-kept circle { fill: var(--text); }
.spark.sp-loss polyline { stroke: var(--loss); }
.spark.sp-loss circle { fill: var(--loss); }

/* Toolbar + search */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.search { position: relative; display: block; flex: 1 1 240px; max-width: 360px; }
.search .ico { position: absolute; inset-inline-start: 12px; top: 14px; color: var(--text-3); }
.search input { padding-inline-start: 36px; }
.search input[type="search"] { -webkit-appearance: none; appearance: none; width: 100%; min-height: 44px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text); font-size: 16px; }
.tag, .ok { display: inline-flex; align-items: center; gap: 6px; }
.ok { color: var(--profit); font-weight: 500; }
@media (min-width: 1024px) { .card { padding: 20px; } .search input[type="search"] { font-size: 14px; } }

.bc-mk { display: none; margin-top: 4px; }
.trunc { display: inline; }

/* Portfolio P&L: phone sort bar (hidden on wider screens, where the header sorts) */
.pl-box { display: flex; flex-direction: column; min-width: 0; }
.pl-sort { display: none; }
.sort-chip { position: relative; display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.sort-chip[aria-pressed="true"] { padding-inline-end: 8px; background: var(--surface-3); border-color: var(--text-3); color: var(--text); }
.sort-chip[aria-pressed="true"] .th-ic { opacity: 1; }

/* Portfolio P&L: every brand waiting on a statement */
.pl-wait { display: flex; align-items: flex-start; gap: 12px; padding: 8px 0 4px; }
.pl-wait .ke-ic { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--surface-3); color: var(--text-2); flex: none; }
.pl-wait-t { font-weight: 600; }
.pl-wait-b { color: var(--text-2); max-width: 60ch; }

@media (max-width: 719px) {
  .tbl-sku { min-width: 860px; }
  .tbl .c-brand { min-width: 140px; }
  .tbl-reports, .tbl-team { min-width: 620px; }

  /* Phone P&L: each brand is a compact card. Name and status on top, then Kept, Sales, Margin, TACoS, all in view */
  .pl-sort { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line-2); }
  .tbl-pl { min-width: 0; }
  .tbl-pl thead { display: none; }
  .tbl-pl, .tbl-pl tbody, .tbl-pl tfoot { display: block; }
  .tbl-pl tr { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.3fr) minmax(0, 0.8fr) minmax(0, 0.7fr); grid-template-areas: "name name name name" "net rev margin tacos"; gap: 8px; padding: 12px 8px; border-bottom: 1px solid var(--line); }
  .tbl-pl th, .tbl-pl td, .tbl-pl tfoot th, .tbl-pl tfoot td { padding: 0; border: 0; min-width: 0; }
  .tbl-pl .c-brand, .tbl.tbl-pl tbody th.c-brand, .tbl.tbl-pl tfoot th.c-brand { grid-area: name; position: static; min-width: 0; background: transparent; }
  .tbl-pl .row-link { min-height: 44px; padding-block: 0; }
  /* Status pins to the top end corner; the name reserves room for it */
  .tbl-pl tbody tr { position: relative; }
  .tbl-pl .c-status { z-index: 2; position: absolute; inset-block-start: 12px; inset-inline-end: 8px; }
  .tbl-pl tbody .c-brand .bn, .tbl-pl tbody .c-brand > .row-link > .bc { padding-inline-end: 112px; }
  .tbl-pl .c-net { grid-area: net; }
  .tbl-pl .c-rev { grid-area: rev; }
  .tbl-pl .c-margin { grid-area: margin; }
  .tbl-pl .c-tacos { grid-area: tacos; }
  .tbl-pl .c-mk, .tbl-pl .c-spark { display: none; }
  .tbl-pl td.num { display: grid; align-content: start; gap: 2px; text-align: start; font-size: 13px; }
  .tbl-pl td.num::before { content: attr(data-label); font-size: 12px; font-weight: 500; color: var(--text-3); }
  .tbl-pl td.c-net { font-size: 15px; font-weight: 600; }
  .tbl-pl .bc-mk { display: block; }
  .tbl-pl .bc-mk .mk { min-height: 20px; padding: 0 6px; }
  .tbl-pl .c-wait { grid-column: 1 / -1; }
  .tbl-pl tr.is-waiting, .tbl-pl tfoot tr { background: var(--surface-2); }
  .tbl-pl tfoot tr { border-bottom: 0; border-top: 1px solid var(--line-2); border-radius: 0 0 8px 8px; }
  .tbl-pl tfoot th.c-brand { align-self: center; }

  /* Phone payout checks: rows become two-column cards, money on the end side, names truncate cleanly */
  .tbl-claims { min-width: 0; }
  .tbl-claims thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .tbl-claims, .tbl-claims tbody { display: block; }
  .tbl-claims tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; row-gap: 2px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
  .tbl-claims td { padding: 0; border: 0; min-width: 0; }
  .tbl-claims .num { text-align: end; }
  .tbl-claims td.num::before { content: attr(data-label); margin-inline-end: 6px; font-size: 12px; font-weight: 500; color: var(--text-3); }
  .tbl-claims .trunc { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tbl-claims .c-ord, .tbl-claims .c-date { font-size: 12px; color: var(--text-3); }
  .tbl-claims .c-date { text-align: end; }
  .tbl-claims .c-rs, .tbl-claims .c-mkt { font-size: 13px; color: var(--text-2); }
  .tbl-noon tr { grid-template-areas: "br gap" "rs val" "ord date"; }
  .tbl-noon .c-br { grid-area: br; font-weight: 600; }
  .tbl-noon .c-gap { grid-area: gap; font-weight: 600; }
  .tbl-noon .c-rs { grid-area: rs; }
  .tbl-noon .c-val { grid-area: val; font-size: 13px; color: var(--text-2); }
  .tbl-noon .c-ord { grid-area: ord; }
  .tbl-noon .c-date { grid-area: date; }
  .tbl-amz tr { grid-template-areas: "prod claim" "br units" "rs mkt" "ord date"; }
  .tbl-amz .c-prod { grid-area: prod; font-weight: 600; }
  .tbl-amz .c-claim { grid-area: claim; font-weight: 600; }
  .tbl-amz .c-br { grid-area: br; font-size: 13px; color: var(--text-2); }
  .tbl-amz .c-units { grid-area: units; font-size: 13px; color: var(--text-2); }
  .tbl-amz .c-rs { grid-area: rs; }
  .tbl-amz .c-mkt { grid-area: mkt; text-align: end; }
  .tbl-amz .c-ord { grid-area: ord; }
  .tbl-amz .c-date { grid-area: date; }
}

/* Overview: Noon-only month with no statement yet */
.kpi-empty { display: grid; justify-items: start; gap: 8px; padding: 20px 16px; }
.kpi-empty .ke-ic { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: var(--surface-3); color: var(--text-2); }
.kpi-empty h2 { margin: 0; }
.kpi-empty p { margin: 0; color: var(--text-2); max-width: 60ch; }
