/* ==========================================================================
   Berrylush Control Tower — theme
   ==========================================================================

   Brand color is #62083f (deep plum/wine). Every other hue in this file is
   derived from it by color-wheel relationship, not picked freely:

     - Categorical chart colors (--cat-1..--cat-8) alternate around the wheel
       in fixed hue order (plum, amber, violet, terracotta, sage, olive, rose,
       taupe) so adjacent categories in a stacked chart are never neighbors on
       the wheel. The order is FIXED — a category keeps its color when filters
       remove other categories, per Berrylush's canonical L2 list in
       config/settings.json (Dresses, Tops, Skirts, Jumpsuits, Co-Ords, Bags,
       Trousers, Shorts, Jeans, Shirts). Categories beyond --cat-8 fall back to
       --cat-other (a neutral) rather than generating a new hue.
     - Green / red / amber are reserved for semantic meaning only (good /
       alert / warning) and never reused as a categorical series color.
     - No hue in the 190-250 degree range (blue) appears anywhere in this file.

   Both a light and a dark reading of the palette are defined below; the
   toggle in the header sets [data-theme] on <html> and the choice is
   persisted to localStorage (see app.js: THEME_STORAGE_KEY).
   ========================================================================== */

:root {
  /* ---- surfaces & text (light) ---- */
  --bg: #faf7f8;
  --bg2: #ffffff;
  --bg3: #f3eef0;
  --bg4: #e9e1e5;
  --border: #ddd2d8;
  --text: #241620;
  --text2: #6b5a63;
  --text3: #94838a;

  /* ---- brand accent (light) ---- */
  --accent: #62083f;
  --accent-hover: #7c1052;
  --accent-soft: rgba(98, 8, 63, 0.09);
  --accent-contrast: #ffffff;

  /* ---- semantic (light) — reserved for status, never categorical ---- */
  --green: #157f3c;
  --green-bg: rgba(21, 127, 60, 0.1);
  --red: #c22b2b;
  --red-bg: rgba(194, 43, 43, 0.1);
  --amber: #a15d07;
  --amber-bg: rgba(161, 93, 7, 0.1);

  /* ---- categorical chart series (light), fixed order ---- */
  --cat-1: #8c2f5e; /* plum   */
  --cat-2: #b4650f; /* amber  */
  --cat-3: #6b4a9e; /* violet */
  --cat-4: #a8481f; /* terracotta */
  --cat-5: #5c7a1e; /* sage   */
  --cat-6: #8a7311; /* olive  */
  --cat-7: #a83d6e; /* rose   */
  --cat-8: #7a6b63; /* taupe  */
  --cat-other: #9a8d92;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 8px 24px rgba(36, 22, 32, 0.12);
  font-size: 14px;
  color-scheme: light;
}

/* Dark mode: system preference, unless the user picked "light" explicitly. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171114;
    --bg2: #201a1f;
    --bg3: #2a2228;
    --bg4: #362c33;
    --border: #423640;
    --text: #f2ecef;
    --text2: #b7a9b0;
    --text3: #8b7c83;

    --accent: #e37aae;
    --accent-hover: #ec96c0;
    --accent-soft: rgba(227, 122, 174, 0.16);
    --accent-contrast: #1a0e14;

    --green: #4ade80;
    --green-bg: rgba(74, 222, 128, 0.14);
    --red: #f87171;
    --red-bg: rgba(248, 113, 113, 0.14);
    --amber: #fbbf24;
    --amber-bg: rgba(251, 191, 36, 0.14);

    --cat-1: #e27cb4;
    --cat-2: #f0a75c;
    --cat-3: #b79ae0;
    --cat-4: #e68a5c;
    --cat-5: #a8c468;
    --cat-6: #d4bb55;
    --cat-7: #e8a0c4;
    --cat-8: #b3a69d;
    --cat-other: #7d7278;

    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

/* Explicit toggle wins over system preference in both directions. */
:root[data-theme="dark"] {
  --bg: #171114;
  --bg2: #201a1f;
  --bg3: #2a2228;
  --bg4: #362c33;
  --border: #423640;
  --text: #f2ecef;
  --text2: #b7a9b0;
  --text3: #8b7c83;

  --accent: #e37aae;
  --accent-hover: #ec96c0;
  --accent-soft: rgba(227, 122, 174, 0.16);
  --accent-contrast: #1a0e14;

  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, 0.14);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.14);
  --amber: #fbbf24;
  --amber-bg: rgba(251, 191, 36, 0.14);

  --cat-1: #e27cb4;
  --cat-2: #f0a75c;
  --cat-3: #b79ae0;
  --cat-4: #e68a5c;
  --cat-5: #a8c468;
  --cat-6: #d4bb55;
  --cat-7: #e8a0c4;
  --cat-8: #b3a69d;
  --cat-other: #7d7278;

  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  transition: background-color .15s, color .15s;
}
button { cursor: pointer; font-family: inherit; }
a { color: inherit; }
.myntra-link { color: var(--accent); text-decoration: none; }
.myntra-link:hover { text-decoration: underline; }

/* ---- Header ---- */
.header { display: flex; align-items: center; gap: 16px; padding: 12px 24px; background: var(--bg2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; flex-wrap: wrap; }
.header__logo { font-size: 18px; font-weight: 700; color: var(--accent); letter-spacing: -.5px; white-space: nowrap; }
.header__logo span { color: var(--text2); font-weight: 400; font-size: 13px; margin-left: 8px; }
.header__controls { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-wrap: wrap; }
.header select, .header input[type=date] { background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: var(--radius); font-size: 13px; }
.header select:focus, .header input:focus { outline: none; border-color: var(--accent); }

.toggle-btn { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 12px; transition: .15s; }
.toggle-btn.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.refresh-btn { padding: 6px 14px; border-radius: var(--radius); border: 1px solid var(--accent); background: transparent; color: var(--accent); font-size: 12px; font-weight: 600; transition: .15s; }
.refresh-btn:hover { background: var(--accent); color: var(--accent-contrast); }
.refresh-btn:disabled { opacity: .5; cursor: not-allowed; }
.freshness { font-size: 11px; color: var(--text3); white-space: nowrap; }
.muted-reason { font-size: 10px; color: var(--text3); font-style: italic; }
.freshness.stale { color: var(--amber); }

.theme-toggle { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 13px; line-height: 1; }
.theme-toggle:hover { border-color: var(--accent); color: var(--text); }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 0; background: var(--bg2); border-bottom: 1px solid var(--border); padding: 0 24px; overflow-x: auto; }
.tab { padding: 10px 20px; font-size: 13px; font-weight: 500; color: var(--text3); border: none; background: none; border-bottom: 2px solid transparent; transition: .15s; white-space: nowrap; }
.tab:hover { color: var(--text2); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- Sub-view switcher ---- */
.view-switcher { display: flex; gap: 4px; padding: 12px 24px 0; }
.view-btn { padding: 7px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 12px; font-weight: 500; transition: .15s; }
.view-btn.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

/* ---- Content ---- */
.content { padding: 20px 24px; max-width: 1440px; margin: 0 auto; }
.section-title { font-size: 15px; font-weight: 600; color: var(--text); margin: 20px 0 12px; display: flex; align-items: center; gap: 8px; }
.section-title:first-child { margin-top: 0; }

/* ---- Banners (loading / error / stale) ---- */
.banner { display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px; border-radius: var(--radius-lg); font-size: 13px; margin-bottom: 16px; border: 1px solid transparent; }
.banner-info { background: var(--bg3); color: var(--text2); border-color: var(--border); }
.banner-warning { background: var(--amber-bg); color: var(--amber); border-color: var(--amber); }
.banner-error { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.banner strong { color: inherit; }
.banner .banner-action { margin-left: auto; flex-shrink: 0; }
.empty-state { text-align: center; padding: 64px 24px; color: var(--text3); }
.empty-state__title { font-size: 15px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }

/* ---- KPI tiles ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 20px; }
.kpi-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; position: relative; }
.kpi-card__label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; display: flex; align-items: center; gap: 4px; }
.kpi-card__value { font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -.5px; }
.kpi-card__delta { font-size: 11px; margin-top: 4px; }
.kpi-card__delta.pos { color: var(--green); }
.kpi-card__delta.neg { color: var(--red); }

.info-icon { display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; border-radius: 50%; background: var(--bg4); color: var(--text3); font-size: 9px; cursor: help; position: relative; flex-shrink: 0; }
.info-icon:hover .tooltip, .info-icon:focus .tooltip { display: block; }
.tooltip { display: none; position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--bg4); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: 11px; color: var(--text2); width: 280px; z-index: 200; line-height: 1.5; white-space: normal; box-shadow: var(--shadow); text-align: left; }
.tooltip strong { color: var(--text); display: block; margin-bottom: 4px; }
.tooltip code { background: var(--bg); padding: 1px 4px; border-radius: 3px; font-size: 10px; color: var(--accent); }
.tooltip .tooltip-note { display: block; margin-top: 6px; color: var(--text3); font-style: italic; }

/* ---- SKU thumbnail: small always-visible image, hover preview, click-to-enlarge ---- */
.sku-thumb-wrap { display: inline-flex; position: relative; vertical-align: middle; margin-right: 6px; }
.sku-thumb { width: 26px; height: 26px; border-radius: var(--radius-sm, 4px); object-fit: cover; border: 1px solid var(--border); cursor: zoom-in; background: var(--bg4); flex-shrink: 0; display: block; }
.sku-thumb-placeholder { width: 26px; height: 26px; border-radius: var(--radius-sm, 4px); border: 1px dashed var(--border); background: var(--bg4); flex-shrink: 0; }
/* A single shared instance, appended to <body> and repositioned/re-sourced
 * on each hover (see app.js's _showSkuThumbPreview) — not one embedded per
 * thumbnail. Visibility and position are both JS-driven, not a CSS :hover
 * rule: position:fixed needs viewport-relative pixel coordinates computed
 * from the thumbnail's actual location, which CSS alone can't do. Living
 * directly under <body> (no sticky/scrolling table ancestor in between)
 * also avoids a real compositing quirk where a position:fixed descendant of
 * a position:sticky/overflow:auto ancestor can render clipped to that
 * ancestor's box instead of the viewport — this works identically no
 * matter which table/row/column it's triggered from. */
.sku-thumb-preview { display: none; position: fixed; z-index: 300; background: var(--bg4); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; box-shadow: var(--shadow); }
.sku-thumb-preview.is-open { display: block; }
.sku-thumb-preview img { width: 160px; height: 160px; object-fit: cover; border-radius: var(--radius-sm, 4px); display: block; }

.img-modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 500; align-items: center; justify-content: center; }
.img-modal-backdrop.open { display: flex; }
.img-modal { max-width: min(90vw, 640px); max-height: 90vh; background: var(--bg2); border-radius: var(--radius-lg); padding: 12px; box-shadow: var(--shadow); }
.img-modal img { max-width: 100%; max-height: calc(90vh - 24px); display: block; border-radius: var(--radius-sm, 4px); }

/* ---- Generic drill-down modal (ROS/cause summary tables' double-click) ---- */
.generic-modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 500; align-items: center; justify-content: center; }
.generic-modal-backdrop.open { display: flex; }
.generic-modal { width: min(92vw, 1100px); max-height: 85vh; background: var(--bg2); border-radius: var(--radius-lg); box-shadow: var(--shadow); display: flex; flex-direction: column; }
.generic-modal__header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; }
.generic-modal__close { background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; line-height: 1; }
.generic-modal__close:hover { color: var(--text); }
.generic-modal__body { padding: 12px 18px 18px; overflow: auto; }
.ros-bucket-cell { cursor: pointer; }
.ros-bucket-cell:hover { text-decoration: underline; }

/* ---- Charts ---- */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.chart-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; }
.chart-card__title { font-size: 13px; font-weight: 600; color: var(--text2); margin-bottom: 4px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chart-cat-select, .chart-period-select { font-size: 11px; font-weight: 500; color: var(--text2); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm, 4px); padding: 2px 6px; }
#execPeriodToolbar { display: inline-flex; align-items: center; gap: 8px; }
.chart-period-toggle { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; }
.chart-period-toggle__label { font-size: 12px; color: var(--text3); }
.chart-period-toggle .chart-period-select { font-size: 12px; padding: 6px 10px; border-radius: var(--radius); background: var(--bg3); }
.chart-canvas { width: 100%; height: 200px; }
svg text { font-family: inherit; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; font-size: 10px; color: var(--text3); }
.chart-legend__item { display: flex; align-items: center; gap: 4px; }
.chart-legend__swatch { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.chart-empty { color: var(--text3); padding: 40px; text-align: center; font-size: 12px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; margin-bottom: 20px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
/* Top SKUs / Slow Moving SKUs: the toolbar (Download buttons, column-group
 * toggles) and the table need separate scroll behavior — the toolbar must
 * stay put, only the table should scroll (both directions). Deliberately
 * NOT a scroll container itself (no overflow set — default visible): an
 * ancestor with only overflow-x:auto still becomes a scroll container for
 * BOTH axes per the CSS overflow spec, which would make it the sticky
 * header's positioning context instead of the actual (inner) scrolling
 * table-wrap below — breaking header freezing even though this element
 * itself never visibly scrolls. Kept overflow:visible so the real
 * `.table-wrap` (rendered by JS, wrapping just the table) is the only
 * scroll container in the chain, exactly like every other table on the
 * page. */
.skb-outer-wrap { margin-bottom: 20px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
/* The actual scroll container (both axes) — border/margin live on
 * .skb-outer-wrap above instead, so this doesn't nest a second visible box
 * inside it. */
.skb-inner-scroll { overflow: auto; max-height: 600px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead th { background: var(--bg3); color: var(--text2); padding: 8px 10px; text-align: center; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
thead th .info-icon { margin-left: 3px; }
/* Freeze the first column (SKU/Parent SKU) on horizontal scroll, Excel-style.
 * Needs an explicit opaque background (not "transparent") or columns scrolling
 * underneath would show through; matched to whatever background each row state
 * already uses elsewhere in this file (default/hover/reorder-group-a/b). */
table td:first-child { position: sticky; left: 0; z-index: 1; background: var(--bg2); }
tbody tr:hover td:first-child { background: var(--bg3); }
tr.reorder-group-a td:first-child { background: var(--bg2); }
tr.reorder-group-b td:first-child { background: var(--bg3); }
/* Only the header's own first row, not every <tr> in <thead> — a `rowspan`
 * header (renderBSInv) makes a later row's first <th> land in the SECOND
 * visual column, not the frozen one, so targeting all thead th:first-child
 * would freeze the wrong cell there. */
thead tr:first-child th:first-child { position: sticky; left: 0; z-index: 3; background: var(--bg3); }
/* Queue tables (pricing/marketing/reorder) have a select-checkbox as column 1,
 * Myntra ID as column 2, and the actual SKU/Parent SKU/Barcode column 3 —
 * freeze all three together (min-width on the Myntra ID column, same reason
 * as the Top SKUs comment below, so the SKU column's fixed `left` offset
 * always lines up with no gap). */
table td:first-child:has(input.q-check),
table th:first-child:has(input[type="checkbox"]) { width: 34px; }
table td:first-child:has(input.q-check) + td,
table th:first-child:has(input[type="checkbox"]) + th {
  width: 90px; min-width: 90px; max-width: 90px; overflow: hidden; text-overflow: ellipsis;
  position: sticky; left: 34px; z-index: 1; background: var(--bg2);
}
table td:first-child:has(input.q-check) + td + td {
  position: sticky; left: 124px; z-index: 1; background: var(--bg2);
}
tbody tr:hover td:first-child:has(input.q-check) + td { background: var(--bg3); }
tbody tr:hover td:first-child:has(input.q-check) + td + td { background: var(--bg3); }
tr.reorder-group-a td:first-child:has(input.q-check) + td,
tr.reorder-group-a td:first-child:has(input.q-check) + td + td { background: var(--bg2); }
tr.reorder-group-b td:first-child:has(input.q-check) + td,
tr.reorder-group-b td:first-child:has(input.q-check) + td + td { background: var(--bg3); }
thead tr:first-child th:first-child:has(input[type="checkbox"]) + th {
  position: sticky; left: 34px; z-index: 3; background: var(--bg3);
}
thead tr:first-child th:first-child:has(input[type="checkbox"]) + th + th {
  position: sticky; left: 124px; z-index: 3; background: var(--bg3);
}
/* Top SKUs / Slow Moving SKUs (Inventory Health): freeze the first THREE
 * columns together — checkbox, Style ID, Parent SKU (the previous version of
 * this rule miscounted the checkbox as the Style ID column and Style ID as
 * Parent SKU, one column short, which is why the freeze visibly landed on
 * the wrong column and Parent SKU scrolled out from under Style ID). Widths
 * use min-width/max-width together (not just width) so the rendered column
 * width can never drift from the fixed `left` offset below regardless of
 * cell content — Parent SKU carries a thumbnail image, so it gets more room
 * than the plain queue tables' equivalent column. */
#skbTopTable table td:nth-child(1), #skbTopTable table th:nth-child(1),
#skbSlowMovingTable table td:nth-child(1), #skbSlowMovingTable table th:nth-child(1) {
  width: 34px; min-width: 34px; max-width: 34px;
  position: sticky; left: 0; z-index: 1; background: var(--bg2);
}
#skbTopTable table td:nth-child(2), #skbTopTable table th:nth-child(2),
#skbSlowMovingTable table td:nth-child(2), #skbSlowMovingTable table th:nth-child(2) {
  width: 90px; min-width: 90px; max-width: 90px; overflow: hidden; text-overflow: ellipsis;
  position: sticky; left: 34px; z-index: 1; background: var(--bg2);
}
/* No overflow:hidden here (unlike column 2 above) — this cell holds the SKU
 * thumbnail's hover-preview popup (.sku-thumb-preview), which is positioned
 * outside the cell's own box; overflow:hidden on an ancestor clips it to a
 * thin sliver no matter which direction it opens. Truncation for long SKU
 * codes is instead scoped to just the text via .sku-cell-text below. */
#skbTopTable table td:nth-child(3), #skbTopTable table th:nth-child(3),
#skbSlowMovingTable table td:nth-child(3), #skbSlowMovingTable table th:nth-child(3) {
  width: 170px; min-width: 170px; max-width: 170px;
  position: sticky; left: 124px; z-index: 1; background: var(--bg2);
}
#skbTopTable table th:nth-child(3), #skbSlowMovingTable table th:nth-child(3) {
  overflow: hidden; text-overflow: ellipsis;
}
.sku-cell-text { display: inline-block; max-width: 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
/* thead cells need the higher z-index (3, matching every other frozen-header
 * pattern in this file) so they stay above frozen *body* cells (z-index 1)
 * scrolling underneath, not just above unfrozen body columns. */
#skbTopTable thead th:nth-child(1), #skbTopTable thead th:nth-child(2), #skbTopTable thead th:nth-child(3),
#skbSlowMovingTable thead th:nth-child(1), #skbSlowMovingTable thead th:nth-child(2), #skbSlowMovingTable thead th:nth-child(3) {
  z-index: 3; background: var(--bg3);
}
#skbTopTable tbody tr:hover td:nth-child(1), #skbTopTable tbody tr:hover td:nth-child(2), #skbTopTable tbody tr:hover td:nth-child(3),
#skbSlowMovingTable tbody tr:hover td:nth-child(1), #skbSlowMovingTable tbody tr:hover td:nth-child(2), #skbSlowMovingTable tbody tr:hover td:nth-child(3) {
  background: var(--bg3);
}
/* Inventory Alignment: same two-column freeze (Myntra ID + Parent SKU). */
#invAlignTable table td:first-child,
#invAlignTable table th:first-child {
  width: 110px; min-width: 110px; max-width: 110px; overflow: hidden; text-overflow: ellipsis;
}
#invAlignTable table td:first-child + td,
#invAlignTable table th:first-child + th {
  width: 150px; min-width: 150px; max-width: 150px; overflow: hidden; text-overflow: ellipsis;
}
#invAlignTable table td:first-child + td {
  position: sticky; left: 110px; z-index: 1; background: var(--bg2);
}
#invAlignTable tbody tr:hover td:first-child + td { background: var(--bg3); }
#invAlignTable thead tr:first-child th:first-child + th {
  position: sticky; left: 110px; z-index: 3; background: var(--bg3);
}
/* Header tooltips open downward, not upward — the table/P&L containers
 * scroll horizontally (overflow-x: auto), which clips anything positioned
 * above the header row since that forces overflow-y to clip too. */
thead th .info-icon .tooltip, .pnl-header .info-icon .tooltip {
  bottom: auto; top: calc(100% + 6px);
}
tbody td { padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; color: var(--text); text-align: center; }
/* ROS Summary / Cause Summary (Top SKUs, Slow Moving SKUs): every column,
 * header and value alike, is a bucketed count/total — center-aligning both
 * (not just the .num-class value cells) reads as one coherent grid instead
 * of left-aligned labels sitting over right-aligned numbers. ID selectors so
 * this wins over the .num/.pct right-align and the default header
 * left-align without needing !important. */
#skbTopSummary th, #skbTopSummary td, #skbSlowSummary th, #skbSlowSummary td { text-align: center; }
tbody tr:hover { background: var(--bg3); }
tbody tr:last-child td { border-bottom: none; }
.total-row td { font-weight: 700; background: var(--bg4) !important; }

/* Reorder queue: alternating tint per parent-SKU group, plus a divider line
 * where a new parent group starts — so all sizes of one style read as a
 * single block. Background is set on the <tr> (not <td>) so tbody tr:hover
 * still wins on specificity and rows remain hoverable. */
tr.reorder-group-a { background: var(--bg2); }
tr.reorder-group-b { background: var(--bg3); }
.reorder-group-start td { border-top: 2px solid var(--accent); }
td.num, th.num { text-align: center; font-variant-numeric: tabular-nums; }

/* Any cell containing the parent-SKU thumbnail (skuThumbHTML output) is left-
 * aligned, everywhere it appears, without touching any other column's
 * alignment — one shared rule instead of per-table overrides. */
td:has(> .sku-thumb-wrap) { text-align: left; }
td.pct, th.pct { text-align: center; font-variant-numeric: tabular-nums; }
.text-muted { color: var(--text3); }

/* ---- Business Snapshot: Sales Metrics column groups ---- */
.bs-col--yesterday { background: color-mix(in srgb, var(--cat-2) 14%, transparent); }
.bs-col--curve     { background: color-mix(in srgb, var(--cat-3) 14%, transparent); }
.bs-col--mtd       { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.bs-col--asp       { background: color-mix(in srgb, var(--cat-5) 14%, transparent); }
.bs-col--gm        { background: color-mix(in srgb, var(--cat-6) 14%, transparent); }
.bs-col--returns   { background: color-mix(in srgb, var(--cat-4) 12%, transparent); }
thead th.bs-col--yesterday, thead th.bs-col--curve, thead th.bs-col--mtd,
thead th.bs-col--asp, thead th.bs-col--gm, thead th.bs-col--returns { color: var(--text); }

/* ---- Top SKU / Slow Moving SKU column groups ---- */
.skb-col--identity    { background: color-mix(in srgb, var(--text3) 10%, transparent); }
.skb-col--pricing     { background: color-mix(in srgb, var(--cat-5) 14%, transparent); }
.skb-col--performance { background: color-mix(in srgb, var(--cat-6) 14%, transparent); }
.skb-col--inventory   { background: color-mix(in srgb, var(--cat-2) 14%, transparent); }
/* The tint classes above use a transparent color-mix so scrolled-past body
 * rows don't need a hover-state override — but a *sticky* header cell using
 * the same class inherits that same transparency, and a class selector
 * (0,1,0) beats the base `thead th { background: var(--bg3) }` rule's
 * type-only specificity (0,0,2), so scrolled-under rows visibly bled through
 * the header on these tinted columns specifically. Forcing an opaque
 * background here (this selector's specificity — 0,1,2 — wins over the bare
 * tint class) fixes it without touching the tint classes' own transparency,
 * which body cells still rely on. */
thead th.skb-col--identity, thead th.skb-col--pricing, thead th.skb-col--performance,
thead th.skb-col--inventory { color: var(--text); background: var(--bg3); }
/* ROS Summary / Cause Summary: each bucket's Styles+Inv column pair gets its
 * own tint (cycled across the 8 categorical colors), applied to header and
 * value cells alike, so the buckets visually group the way the Reorder
 * queue's alternating parent-SKU shading groups sizes of one style. Value
 * cells use a light transparent tint layered over the row's own background;
 * header cells use a bolder tint mixed into opaque bg3 instead — both the
 * "invert" contrast between header/value strength, and (like the
 * skb-col--* header override below) needed because a *sticky* header cell
 * with a transparent background lets scrolled-under rows bleed through. */
.bucket-tint-1 { background: color-mix(in srgb, var(--cat-1) 16%, transparent); }
.bucket-tint-2 { background: color-mix(in srgb, var(--cat-2) 16%, transparent); }
.bucket-tint-3 { background: color-mix(in srgb, var(--cat-3) 16%, transparent); }
.bucket-tint-4 { background: color-mix(in srgb, var(--cat-4) 16%, transparent); }
.bucket-tint-5 { background: color-mix(in srgb, var(--cat-5) 16%, transparent); }
.bucket-tint-6 { background: color-mix(in srgb, var(--cat-6) 16%, transparent); }
.bucket-tint-7 { background: color-mix(in srgb, var(--cat-7) 16%, transparent); }
.bucket-tint-8 { background: color-mix(in srgb, var(--cat-8) 16%, transparent); }
thead th.bucket-tint-1 { background: color-mix(in srgb, var(--cat-1) 32%, var(--bg3)); color: var(--text); }
thead th.bucket-tint-2 { background: color-mix(in srgb, var(--cat-2) 32%, var(--bg3)); color: var(--text); }
thead th.bucket-tint-3 { background: color-mix(in srgb, var(--cat-3) 32%, var(--bg3)); color: var(--text); }
thead th.bucket-tint-4 { background: color-mix(in srgb, var(--cat-4) 32%, var(--bg3)); color: var(--text); }
thead th.bucket-tint-5 { background: color-mix(in srgb, var(--cat-5) 32%, var(--bg3)); color: var(--text); }
thead th.bucket-tint-6 { background: color-mix(in srgb, var(--cat-6) 32%, var(--bg3)); color: var(--text); }
thead th.bucket-tint-7 { background: color-mix(in srgb, var(--cat-7) 32%, var(--bg3)); color: var(--text); }
thead th.bucket-tint-8 { background: color-mix(in srgb, var(--cat-8) 32%, var(--bg3)); color: var(--text); }
thead th.bucket-tint-total { background: color-mix(in srgb, var(--text3) 24%, var(--bg3)); color: var(--text); }
.bucket-tint-total { background: color-mix(in srgb, var(--text3) 10%, transparent); }

/* Bucket-group headers (ROS Summary / Cause Summary): top-level bucket label
   (rowspan-2, e.g. "ROS > 2") reads as the dominant header; the sub-header
   row ("Styles"/"Inv") is smaller/lighter beneath it. */
.bucket-group-thead tr:first-child th { font-weight: 700; font-size: 13px; text-align: center; }
.bucket-group-thead tr:last-child th { font-weight: 500; font-size: 11px; text-align: center; }

.brand-toggle-group { display: flex; gap: 4px; }
.skb-size-list { display: flex; flex-direction: column; gap: 1px; font-size: 11px; white-space: nowrap; }
.skb-size-list span { color: var(--text2); }

.bs-period-toggle { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; }
.bs-period-month select { padding: 6px 10px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 12px; }
.bs-period-month.active select { border-color: var(--accent); color: var(--accent); }

/* ---- Inventory Health ---- */
.inv-health-toggle { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; }
.inv-health-subtitle { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; padding: 10px 4px 6px; }
.inv-health-subtitle:not(:first-child) { margin-top: 16px; }
.inv-health-subtitle.inv-health--berrylush { color: var(--text2); }
.inv-health-subtitle.inv-health--curve { color: var(--accent); }
tr.inv-health--berrylush td:first-child { border-left: 3px solid var(--text3); }
tr.inv-health--curve td:first-child { border-left: 3px solid var(--accent); }
tr.inv-health--curve { background: color-mix(in srgb, var(--accent) 6%, transparent); }

/* Business Snapshot's Curve vs Overall inventory columns */
.inv-col--curve { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.inv-col--overall { background: color-mix(in srgb, var(--cat-1) 10%, transparent); }
thead th.inv-col--curve { color: var(--accent); }
thead th.inv-col--overall { color: var(--text); }
.text-good { color: var(--green); }
.text-bad { color: var(--red); }
.text-warn { color: var(--amber); }

.tag { display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 10px; font-weight: 600; }
.tag-curve { background: var(--accent-soft); color: var(--accent); }
.tag-core { background: var(--bg4); color: var(--text2); }
.tag-green { background: var(--green-bg); color: var(--green); }
.tag-red { background: var(--red-bg); color: var(--red); }
.tag-amber { background: var(--amber-bg); color: var(--amber); }
.tag-cause { background: var(--amber-bg); color: var(--amber); margin-right: 4px; }

/* ---- Top SKUs / Slow Moving SKUs (Inventory Health) ---- */
.skb-toggle-btn { padding: 5px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 11px; font-weight: 500; transition: .15s; }
.skb-toggle-btn.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
tr.skb-top20 { background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ---- Action queue extras ---- */
.queue-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.queue-toolbar input[type=text] { background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: var(--radius); font-size: 12px; width: 200px; }
.queue-toolbar label { color: var(--text2); font-size: 12px; display: flex; align-items: center; gap: 5px; }
.download-btn { padding: 6px 14px; border-radius: var(--radius); border: 1px solid var(--green); background: transparent; color: var(--green); font-size: 12px; font-weight: 600; transition: .15s; }
.download-btn:hover { background: var(--green); color: var(--bg2); }
.download-btn:disabled { opacity: .4; cursor: not-allowed; }
input[type=checkbox] { accent-color: var(--accent); }

/* ---- Sub-tabs for actions ---- */
.sub-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.sub-tab { padding: 7px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 12px; font-weight: 500; transition: .15s; }
.sub-tab.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

/* ---- Design grid ---- */
.design-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-bottom: 16px; }
.design-cell { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px; cursor: pointer; transition: .15s; text-align: left; width: 100%; }
.design-cell:hover { border-color: var(--accent); }
.design-cell.unreliable { opacity: .55; }
.design-cell__header { font-size: 11px; color: var(--text3); margin-bottom: 6px; }
.design-cell__stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; font-size: 11px; }
.design-cell__stat-label { color: var(--text3); }
.design-cell__stat-value { color: var(--text); font-weight: 600; text-align: right; }

/* ---- Drill-down panel ---- */
.drill-panel { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 16px; }
.drill-panel__close { float: right; background: none; border: none; color: var(--text3); font-size: 16px; }
.drill-panel__close:hover { color: var(--text); }
.drill-panel__title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }

/* ---- P&L ---- */
.pnl-section { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 16px; overflow-x: auto; }
.pnl-row { display: grid; grid-template-columns: 180px repeat(7, 1fr); gap: 1px; font-size: 12px; min-width: 820px; }
.pnl-row > div { padding: 6px 10px; }
.pnl-header { background: var(--bg3); font-weight: 600; color: var(--text2); font-size: 11px; text-transform: uppercase; position: sticky; top: 0; z-index: 3; }
.pnl-row:not(.pnl-header) > div:first-child { color: var(--text2); }
.pnl-row > div:not(:first-child) { text-align: center; font-variant-numeric: tabular-nums; }
.pnl-total > div { font-weight: 700; background: var(--bg4); }
.pnl-l1 > div { background: var(--bg3); }
/* Freeze the Segment column (P&L uses a CSS-grid of divs, not a <table>, so
 * the sticky-first-column rules above don't apply here). */
.pnl-row > div:first-child { position: sticky; left: 0; z-index: 1; background: var(--bg2); }
.pnl-header > div:first-child { z-index: 3; background: var(--bg3); }
.pnl-total > div:first-child { background: var(--bg4); }
.pnl-l1 > div:first-child { background: var(--bg3); }
.pnl-toggle { cursor: pointer; }
.pnl-toggle:hover > div { filter: brightness(1.08); }
.pnl-caret { display: inline-block; width: 14px; color: var(--text3); }
.pnl-note { font-size: 11px; color: var(--text3); margin-top: 10px; font-style: italic; }

/* ---- Settings ---- */
.settings-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 16px; }
.settings-card h3 { font-size: 13px; margin-bottom: 12px; color: var(--text); }
.settings-card ul { color: var(--text3); list-style: none; line-height: 2; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .charts-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .header { padding: 10px 16px; }
  .content { padding: 16px; }
}

/* ---- Sortable / filterable table headers ---- */
th.sortable { cursor: pointer; user-select: none; }
th.sortable .sort-arrow { display: inline-block; width: 10px; margin-left: 2px; color: var(--text3); font-size: 9px; }
th.sortable.sort-asc .sort-arrow::after { content: "▲"; color: var(--accent); }
th.sortable.sort-desc .sort-arrow::after { content: "▼"; color: var(--accent); }

.th-filter-anchor { position: relative; display: inline-block; }
.filter-icon { display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; border-radius: 3px; background: transparent; color: var(--text3); font-size: 10px; cursor: pointer; flex-shrink: 0; margin-left: 2px; }
.filter-icon.filter-active { color: var(--accent); }
.filter-icon:hover, .filter-icon.filter-open { background: var(--bg4); }

.filter-popover { display: none; position: absolute; top: calc(100% + 4px); left: 0; background: var(--bg4); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; font-size: 11px; color: var(--text2); width: 200px; z-index: 210; box-shadow: var(--shadow); text-align: left; cursor: default; text-transform: none; letter-spacing: normal; font-weight: normal; white-space: normal; }
.filter-popover.open { display: block; }
.filter-popover .filter-row { display: flex; gap: 4px; margin-bottom: 6px; align-items: center; }
.filter-popover select, .filter-popover input[type=text], .filter-popover input[type=number] { font-size: 11px; padding: 3px 5px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; color: var(--text); width: 100%; }
.filter-popover .filter-checklist { max-height: 160px; overflow-y: auto; margin-bottom: 6px; }
.filter-popover .filter-checklist label { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-weight: normal; text-transform: none; }
.filter-popover .filter-actions { display: flex; justify-content: space-between; gap: 6px; }
.filter-popover .filter-actions button { font-size: 10px; padding: 3px 8px; border-radius: 4px; border: 1px solid var(--border); background: var(--bg3); color: var(--text2); }
.filter-popover .filter-actions button:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Queue logic banner ---- */
.queue-logic-note { margin-bottom: 12px; }

/* ---- Geographical Map (Leaflet tooltip themed to match the app) ---- */
#geoMap { border: 1px solid var(--border); }
.leaflet-tooltip { background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm, 4px); font-size: 12px; box-shadow: var(--shadow); }
.leaflet-tooltip-top:before { border-top-color: var(--border); }

/* ---- Collapsible column groups (Reorder queue, Top SKU, Slow Moving SKU) ---- */
.column-group-toggles { display: flex; gap: 8px; margin-bottom: 8px; }
.group-toggle { padding: 4px 10px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 11px; transition: .15s; }
.group-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Utility ---- */
.hidden { display: none !important; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
