/* Joswe Pharma — application styles. Tokens live in tokens.css. */
* { margin: 0; padding: 0; box-sizing: border-box; }
/* Form controls don't inherit font-size (browser default 13.33px) — pin them to the scale. */
button, input, select, textarea { font-size: var(--fs-footnote); }
/* Browser default placeholder grey is 3.96:1 on our inputs; muted text is 8.89:1. */
::placeholder { color: var(--text-muted); opacity: 1; }

body {
    font-family: var(--font-main);
    font-size: var(--fs-subhead);
    background-color: var(--bg-base);
    color: var(--text-main);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-x: clip;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(14, 165, 233, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(139, 92, 246, 0.08) 0%, transparent 50%);
    background-attachment: fixed;
}

/* --- Screens --- */
.screen {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 100vh; min-height: 100dvh; padding: 2rem;
    animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.1); opacity: 0.7; } 100% { transform: scale(1); opacity: 1; } }

/* --- Main Layout --- */
.app-container { display: flex; min-height: 100vh; min-height: 100dvh; }

/* Sidebar */
.sidebar {
    width: 248px;
    background: rgba(17, 24, 39, 0.95);
    border-right: 1px solid var(--border);
    backdrop-filter: blur(20px);
    padding: 2rem 1rem;
    display: flex; flex-direction: column; gap: 1.5rem;
    position: fixed; height: 100vh; height: 100dvh; z-index: 50;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Retractable Sidebar State */
.sidebar.collapsed { width: 88px; padding: 2rem 1rem; }
.sidebar.collapsed .brand { justify-content: center; gap: 0; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 0.75rem; gap: 0; }
/* Labels collapse their own width in step with the rail instead of
   blinking out via display:none — max-width + opacity are both
   animatable, so the text slides away as the sidebar narrows and
   slides back on expand. white-space:nowrap stops the mid-animation
   word wrap. */
.brand-text,
.nav-item span {
    white-space: nowrap;
    overflow: hidden;
    max-width: 200px;
    transition: max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.2s ease;
}
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-item span {
    max-width: 0;
    opacity: 0;
}

.sidebar-toggle {
    position: absolute;
    top: 2.25rem;
    right: -14px;
    width: 28px;
    height: 28px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-muted);
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1); transition-property: var(--ui-transition-props);
    z-index: 60;
}
.sidebar-toggle:hover { color: var(--primary); border-color: var(--primary); box-shadow: 0 0 10px var(--primary-glow); transform: scale(1.1); }
.sidebar.collapsed .sidebar-toggle svg { transform: rotate(180deg); }

.brand { display: flex; align-items: center; gap: 1rem; }
.brand-icon {
    width: 48px; height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 14px; display: flex; align-items: center; justify-content: center;
    font-size: var(--fs-title2); box-shadow: 0 8px 16px var(--primary-glow);
}
.brand-text { font-size: var(--fs-title2); font-weight: 700; letter-spacing: -0.5px; }
.brand-text span { font-weight: 300; color: var(--text-muted); }

.nav-menu { display: flex; flex-direction: column; gap: 0.5rem; }
.nav-item {
    padding: 0.75rem; border-radius: 12px; cursor: pointer;
    display: flex; align-items: center; gap: 0.75rem;
    font-weight: 500; color: var(--text-muted);
    border: 1px solid transparent;
    /* gap/padding ride the 0.3s rail collapse; hover stays at 0.2s */
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease,
                gap 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.nav-item:hover { background: rgba(255, 255, 255, 0.03); color: var(--text-main); }
/* Even tint + full border so the pill closes on the right (the old
   fade-to-transparent gradient left it looking cut off); the accent bar
   is an inset shadow so it doesn't widen the left border and nudge the
   icon/label sideways. */
.nav-item.active {
    background: rgba(14, 165, 233, 0.1);
    border-color: rgba(14, 165, 233, 0.25);
    box-shadow: inset 3px 0 0 var(--primary);
    color: var(--primary); font-weight: 600;
}

/* Collapsed-rail hover flyout labels */
.sidebar.collapsed:not(.mobile-open) .nav-item { position: relative; overflow: visible; }
.sidebar.collapsed:not(.mobile-open) .nav-item::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%) scale(0.9);
    transform-origin: left center;
    background: var(--bg-surface-solid);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: var(--fs-footnote); font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 70;
}
.sidebar.collapsed:not(.mobile-open) .nav-item:hover::after {
    opacity: 1;
    transform: translateY(-50%) scale(1);
}

/* Main Content */
.main-content {
    margin-left: 248px; flex: 1; min-width: 0; padding: 2rem;
    /* was max-width:98% — with flex:1 + margin-left that let the box's
       footprint (margin + width) exceed the viewport, so every child
       sat ~40px past the right edge with no gap while the left kept
       its margin. min-width:0 lets the flex item size to the space
       that's actually left of the sidebar; overflow-x:clip keeps any
       wide child (tables, chart rows) inside the padding box so the
       right gap matches the left. clip (not hidden) leaves the
       vertical axis alone, so dropdowns/sticky bars still overflow. */
    max-width: 100%;
    overflow-x: clip;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.main-content.expanded {
    margin-left: 88px;
}

.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.page-title { font-size: var(--fs-title1); font-weight: 700; letter-spacing: -0.5px; }
/* Ex-factory indicator beside a page title — inline, so it never overlays or shifts the content below. */
.xf-title-badge {
    display: inline-flex; align-items: center; gap: 0.25rem; vertical-align: middle; margin-left: 0.5rem;
    padding: 0.12rem 0.5rem; border-radius: 999px; border: 1px solid var(--warning);
    background: var(--warning); color: #1a1a1a; font-family: inherit; font-size: var(--fs-caption2); font-weight: 800;
    letter-spacing: 0.03em; line-height: 1.4; cursor: pointer; white-space: nowrap;
}
.xf-title-badge:hover { filter: brightness(1.1); }

/* Brand Deep Dive: compact filter recap that slides in once the real
   filter bar is scrolled out of view. position:fixed, so it never
   takes flow space; left tracks the sidebar via .main-content state. */
.bd-sticky-chips {
    /* z-index below the sidebar (50) so the sidebar's collapse handle,
       which pokes ~14px past its right edge, stays on top of this bar
       instead of being covered by it. Still well above page content. */
    position: fixed; top: 0; left: 248px; right: 0; z-index: 45;
    display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
    padding: 0.5rem 2rem;
    background: rgba(17, 24, 39, 0.92);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    transform: translateY(-140%);
    /* Resting state is visibility:hidden as well as parked off-screen,
       so the bar can never paint unless .show is set — a refresh into
       BD / Target Calculator that reveals the parent view can't flash
       it. Longhand transition (not the shorthand, which round-trips
       ambiguously when a duration is 0s): visibility flips with a
       0.25s delay here so it stays visible through the slide-up when
       .show is removed, then hides. */
    visibility: hidden;
    pointer-events: none;
    transition-property: transform, left, visibility;
    transition-duration: 0.25s, 0.3s, 0s;
    transition-timing-function: ease, cubic-bezier(0.4, 0, 0.2, 1), linear;
    transition-delay: 0s, 0s, 0.25s;
}
.main-content.expanded .bd-sticky-chips { left: 88px; }
.bd-sticky-chips.show {
    transform: translateY(0);
    visibility: visible;
    pointer-events: auto;
    /* slide in immediately — no visibility delay on the way in */
    transition-delay: 0s, 0s, 0s;
}
.bd-chip {
    display: inline-flex; align-items: center; gap: 0.5rem;
    background: rgba(14, 165, 233, 0.1); border: 1px solid var(--primary);
    color: var(--text-main); border-radius: 999px;
    padding: 0.25rem 0.75rem; font-family: inherit; font-size: var(--fs-footnote);
    font-weight: 600; cursor: pointer; transition: 0.15s; transition-property: var(--ui-transition-props); max-width: 280px;
}
.bd-chip:hover { background: rgba(14, 165, 233, 0.18); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15); }
.bd-chip-k { color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-size: var(--fs-caption2); }
.bd-chip-v { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.calc-chip-ignore { margin-left: auto; border-color: var(--border); background: transparent; color: var(--text-muted); }
.calc-chip-ignore:hover { border-color: var(--primary); color: var(--primary); }
.calc-chip-ignore.active { background: rgba(14, 165, 233, 0.18); border-color: var(--primary); color: var(--primary); }
#bd-chip-sku, #calc-chip-sku { border-color: var(--secondary); background: rgba(139, 92, 246, 0.1); }
#bd-chip-sku:hover, #calc-chip-sku:hover { background: rgba(139, 92, 246, 0.18); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15); }
.bd-chip-wrap { position: relative; display: inline-flex; }
.bd-chip-pop {
    position: absolute; top: calc(100% + 6px); left: 0;
    min-width: 240px; max-width: 340px; max-height: 62vh; overflow-y: auto;
    background: rgba(17, 24, 39, 0.98); border: 1px solid var(--border);
    border-radius: 12px; box-shadow: 0 14px 44px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    padding: 0.5rem; display: none; z-index: 95;
}
.bd-chip-pop.open { display: block; }
/* "Done" applies a pending SKU selection; sticky so it stays reachable in a long list. */
.sku-done-btn {
    display: block; width: 100%; margin-top: 0.5rem; padding: 0.5rem 0.75rem;
    border: none; border-radius: 8px; background: var(--primary); color: var(--on-primary);
    font-family: inherit; font-size: var(--fs-footnote); font-weight: 700; cursor: pointer;
}
.sku-done-btn:hover { filter: brightness(1.1); }
.bd-chip-pop .sku-done-btn { position: sticky; bottom: 0; }
.dropdown-body > .sku-done-btn { margin: 0; border-radius: 0; border-top: 1px solid var(--border); }
.bd-chip-pop-title { font-size: var(--fs-caption2); text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 700; margin: 0.125rem 0 0.5rem; }
.bd-chip-pop label.checkbox-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0.5rem; border-radius: 6px; font-size: var(--fs-footnote); cursor: pointer; }
.bd-chip-pop label.checkbox-item:hover { background: rgba(255, 255, 255, 0.05); }
.bd-chip-pop label.checkbox-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bd-chip-pop select {
    width: 100%; margin: 0.25rem 0; padding: 0.5rem 2rem 0.5rem 0.75rem; border-radius: 8px;
    background-color: rgba(14, 165, 233, 0.1); border: 1px solid var(--primary); color: var(--text-main);
    font-family: inherit; font-size: var(--fs-footnote); background-position: right 0.5rem center; background-size: 0.9rem;
}
.bd-chip-pop .bd-pop-row { display: flex; gap: 0.5rem; align-items: center; }
.bd-chip-pop .bd-pop-row select { margin: 0.25rem 0; }
@media (max-width: 900px) {
    /* Sit above page content but BELOW the mobile nav drawer (150) and
       its backdrop (149) — opening the hamburger menu must cover the
       chip bar, not the other way round — and below the mobile header
       and bottom nav (200). */
    .bd-sticky-chips { left: 0 !important; top: 60px; padding: 0.5rem 0.75rem; z-index: 140; overflow-x: auto; flex-wrap: nowrap; }
    .bd-chip { flex: 0 0 auto; }
    .bd-chip-pop { position: fixed; top: 104px; left: 0.5rem; right: 0.5rem; max-width: none; z-index: 141; }
}

select {
    appearance: none; background: var(--bg-surface); border: 1px solid var(--border);
    color: var(--text-main); padding: 0.75rem 3rem 0.75rem 1.5rem; border-radius: 12px;
    font-family: inherit; font-size: var(--fs-subhead); cursor: pointer; outline: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 1rem center; background-size: 1.25rem;
    transition: 0.2s; transition-property: var(--ui-transition-props);
}
select:hover, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1); }

/* Custom Elegant Dropdown */
.custom-dropdown {
    position: relative;
    width: 320px;
    font-family: var(--font-main);
    z-index: 100;
}
/* Brand dropdown must stack above content but not above header/nav */
#brand-custom-dropdown { z-index: 60; }
/* SKU dropdown must stack above the date filter container rendered below it, and above bottom nav (z-index:200) */
#sku-custom-dropdown { z-index: 50; }
/* Calc dropdowns: above content, below header */
#calc-brand-dropdown { z-index: 60; }
#calc-sku-dropdown   { z-index: 50; }
.dropdown-header {
    background: rgba(14, 165, 233, 0.1);
    border: 1px solid var(--primary);
    color: var(--text-main);
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: var(--fs-body);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: 0.2s; transition-property: var(--ui-transition-props);
}
.dropdown-header:hover, .dropdown-header.active {
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
    background: rgba(14, 165, 233, 0.15);
}
.dropdown-header svg {
    transition: transform 0.3s ease;
    color: var(--primary);
}
.dropdown-header.active svg {
    transform: rotate(180deg);
}
.dropdown-body {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.5rem;
    background: rgba(17, 24, 39, 0.95);
    border: 1px solid var(--border);
    border-radius: 12px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: none;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
    overflow: hidden;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.15s ease-out, transform 0.15s ease-out;
}
.dropdown-body.open {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}
/* Opening flips display:none -> flex, which skips transitions; @starting-style
   gives the open state a "from" value so the fade/slide actually plays. */
@starting-style {
    .dropdown-body.open { opacity: 0; transform: translateY(-4px); }
}
.dropdown-search {
    background: rgba(0,0,0,0.3);
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
    padding: 1rem 1.25rem;
    font-family: inherit;
    font-size: var(--fs-subhead);
    outline: none;
    width: 100%;
}
.dropdown-search::placeholder { color: var(--text-muted); }
.dropdown-search:focus { background: rgba(0,0,0,0.5); }
.dropdown-list {
    max-height: 280px;
    overflow-y: auto;
}
.dropdown-item {
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    transition: 0.2s; transition-property: var(--ui-transition-props);
    color: var(--text-muted);
    font-weight: 500;
    border-left: 3px solid transparent;
}
.dropdown-item:hover {
    background: rgba(14, 165, 233, 0.1);
    color: var(--text-main);
    border-left: 3px solid var(--primary);
}
.dropdown-item.selected {
    background: rgba(14, 165, 233, 0.15);
    color: var(--primary-light);
    border-left: 3px solid var(--primary);
}

/* Checkbox Items for Multi-Select */
.checkbox-item {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1.25rem; 
    cursor: pointer; color: var(--text-muted); transition: 0.2s; transition-property: var(--ui-transition-props); font-size: var(--fs-subhead);
    user-select: none;
}
.checkbox-item:hover { background: rgba(139, 92, 246, 0.1); color: var(--text-main); }
.checkbox-item input[type="checkbox"] { 
    accent-color: var(--secondary); width: 1.1rem; height: 1.1rem; cursor: pointer; 
}

/* --- Bento Box Grid System --- */
.bento-grid {
    display: grid;
    /* minmax(0, 1fr) rather than 1fr so a wide child (table/chart)
       can't force its track past 1/N and spill/clip on the right. */
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.5rem;
    grid-auto-rows: minmax(200px, auto);
}

.bento-card {
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: var(--card-radius); padding: 1.5rem;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    transition: border-color 0.15s ease-out;
    display: flex; flex-direction: column; position: relative; overflow: hidden;
}
/* Cards aren't clickable, so hover only firms up the border — no lift. */
.bento-card:hover { border-color: rgba(255,255,255,0.1); }

/* Grid Spans */
.col-span-1 { grid-column: span 1; }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }
.col-span-4 { grid-column: span 4; }
.row-span-2 { grid-row: span 2; }

/* Brand Deep Dive: don't force a 200px-tall implicit row on the section
   header / grid rows (that was the big empty band under the "Analytics"
   and "SKU Monthly Performance" titles). KPI stat tiles keep their size. */
#brand-workspace { grid-auto-rows: auto; }
#brand-workspace > .bento-card { min-height: 200px; }

/* SKU Monthly Performance: laid out purely by its own "1 / 2 per row"
   toggle (remembered for every brand), NOT by the shared 4/2/1-column
   bento math and NOT by free-form "Edit layout" positioning — the
   toggle overrides Edit layout for this section only (dashLayoutApply
   keeps this container out of the free-form canvas).
   Default (no modifier class): 2 charts per row when there's room for
   two comfortably wide ones, otherwise 1 per row. */
#sku-charts-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr));
}
#sku-charts-grid.sku-cols-1 { grid-template-columns: 1fr; }
#sku-charts-grid.sku-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#sku-charts-grid > .bento-card { grid-column: auto; }
@media (max-width: 768px) {
    #sku-charts-grid.sku-cols-2 { grid-template-columns: 1fr; }
}

/* --- Editable chart dashboard ("Edit layout" mode) --- */
/* A container that carries a saved free-form layout becomes a
   position:relative canvas of explicit height; each laid-out card is
   absolutely positioned inside it. Containers with no saved layout are
   untouched, so users who never open Edit see zero change. */
/* Each section grid (main charts / analytics / SKU) becomes its own
   independent position:relative canvas of explicit height. Cards only
   move & resize inside their own canvas — they can't cross sections. */
.dash-canvas { position: relative; }
.dash-canvas.bento-grid { grid-auto-rows: auto; align-content: start; }
.dash-canvas > *:not(.dash-card--positioned) { align-self: start; }
/* A section title with no visible card in its canvas is hidden. */
.dash-section-empty { display: none !important; }
.dash-card--positioned {
    position: absolute !important;
    margin: 0 !important;
    grid-column: auto !important;
    grid-row: auto !important;
    overflow: auto;
}
.dash-card--positioned .chart-wrap { min-height: 0; }
/* Auto-height card: height tracks its content (all SKU rows visible,
   no inner vertical scroll); only its width is user-resizable. */
.dash-card--positioned.dash-autoheight { height: auto !important; overflow: visible; }
.dash-autoheight .dash-resize-h { cursor: ew-resize; }
/* IMS cards use inner fixed-height chart holders — let them flex to the
   card box once the card is free-form sized. */
.ims-card.dash-card--positioned { display: flex; flex-direction: column; }
.ims-card.dash-card--positioned > div:has(> canvas) {
    flex: 1 1 auto; height: auto !important; min-height: 120px;
}
.dash-hidden { display: none !important; }

/* While a view is in edit mode */
.dash-editing .dash-card { outline: 2px dashed var(--primary); outline-offset: -2px; }
.dash-editing .dash-card:hover { transform: none; box-shadow: none; }
/* Faint reference grid on the editing canvas */
.dash-canvas.dash-editing {
    background-image:
        linear-gradient(rgba(148,163,184,0.10) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148,163,184,0.10) 1px, transparent 1px);
    background-size: 24px 24px;
}
/* Smart alignment guides shown while dragging / resizing */
.dash-guide { position: absolute; z-index: 45; pointer-events: none; background: #f43f5e; box-shadow: 0 0 0 0.5px rgba(244,63,94,0.4); }
.dash-guide-v { width: 1px; top: 0; bottom: 0; }
.dash-guide-h { height: 1px; left: 0; right: 0; }
/* Live size / position badge on the card being moved or resized */
.dash-editing .dash-card.dash-dragging::after,
.dash-editing .dash-card.dash-resizing::after {
    content: attr(data-dash-dim);
    position: absolute; right: 6px; bottom: 6px; z-index: 46;
    background: var(--primary); color: var(--on-primary); font-size: var(--fs-caption2); font-weight: 700;
    padding: 2px 4px; border-radius: 6px; pointer-events: none; white-space: nowrap;
}
.dash-editing .dash-card:not(.dash-swapping),
.dash-editing .dash-card:not(.dash-swapping) * { transition: none !important; }
/* A card displaced by a drag-to-swap glides into its new slot. */
.dash-editing .dash-card.dash-swapping {
    transition: left .16s ease, top .16s ease, width .16s ease, height .16s ease !important;
    z-index: 8;
}
.dash-editing .dash-card.dash-card--positioned.dash-dragging { z-index: 30; opacity: 0.92; }
.dash-move-bar {
    position: absolute; top: 0; left: 0; right: 0; height: 14px;
    cursor: grab; background: rgba(14,165,233,0.25);
    border-bottom: 1px solid var(--primary);
    display: none; z-index: 20; touch-action: none;
}
.dash-move-bar:active { cursor: grabbing; }
.dash-resize-h {
    position: absolute; bottom: 0; width: 20px; height: 20px;
    display: none; z-index: 20; touch-action: none;
}
.dash-resize-se {
    right: 0; cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 45%, var(--primary) 45%, var(--primary) 70%, transparent 70%);
}
.dash-resize-sw {
    left: 0; cursor: nesw-resize;
    background: linear-gradient(225deg, transparent 45%, var(--primary) 45%, var(--primary) 70%, transparent 70%);
}
.dash-eye-btn {
    position: absolute; top: 3px; right: 6px; display: none; z-index: 21;
    width: 24px; height: 24px; padding: 0; line-height: 1;
    border-radius: 6px; border: 1px solid var(--border);
    background: var(--bg-surface); color: var(--text-main);
    cursor: pointer; font-size: var(--fs-footnote);
}
.dash-editing .dash-move-bar,
.dash-editing .dash-resize-h,
.dash-editing .dash-eye-btn { display: block; }
/* The thin drag bar (14px) overlays the card's existing top padding —
   it must NOT push content down, which used to inflate every card the
   moment you entered edit mode and shove every section below it. */
.dash-editing .ims-card.dash-card--positioned { padding-top: 16px; }

/* Edit-mode toolbar bits */
.dash-checklist {
    position: absolute; z-index: 4000; margin-top: 0.5rem;
    /* Solid, not --bg-surface: this floats over the charts it's
       toggling, and --bg-surface's 0.7 alpha let them bleed through
       and wash out the list. */
    background: var(--bg-surface-solid); border: 1px solid var(--border);
    border-radius: 12px; padding: 0.5rem; min-width: 240px;
    max-height: 340px; overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.dash-checklist label {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.25rem 0.5rem; border-radius: 8px; cursor: pointer;
    font-size: var(--fs-footnote); color: var(--text-main);
}
.dash-checklist label:hover { background: rgba(255,255,255,0.05); }

@media (max-width: 768px) {
    /* Free-form canvas is unusable on phones — force native flow. */
    .dash-canvas { position: static !important; height: auto !important; }
    .dash-canvas.bento-grid { display: grid; }
    .dash-card--positioned {
        position: static !important; left: auto !important; top: auto !important;
        width: auto !important; height: auto !important;
    }
    #dash-edit-btn-brands, #dash-edit-btn-ims { display: none !important; }
}

/* KPI Card Specifics */
.kpi-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.5rem; z-index: 2;}
.kpi-title { color: var(--text-muted); font-size: var(--fs-footnote); font-weight: 600; }
/* Glyph stays as a quiet label, never louder than the number beside it. */
.kpi-icon { font-size: var(--fs-subhead); line-height: 1; filter: grayscale(1); opacity: 0.6; }
/* The page's one lead figure (Overview Gross Sales, Brand Sales Value)
   outranks the page title (28px); the other KPIs sit level with it. */
.kpi-value {
    font-size: var(--fs-title1);
    font-weight: 600;
    margin-bottom: 0.25rem; 
    z-index: 2; 
    position: relative;
    word-break: break-word;
    line-height: 1.1;
}
.kpi-value.kpi-lead { font-size: var(--fs-largetitle); font-weight: 700; }
/* Currency unit set small so the lead figure fits a 4-column card at 34px. */
.kpi-unit { font-size: var(--fs-subhead); font-weight: 600; }
.kpi-trend { font-size: var(--fs-footnote); font-weight: 600; display: flex; align-items: center; gap: 0.25rem; z-index: 2; position: relative; margin-top: 0.5rem;}
.kpi-skeleton { color: transparent !important; -webkit-text-fill-color: transparent !important; background: linear-gradient(90deg, rgba(148,163,184,0.12) 25%, rgba(148,163,184,0.26) 50%, rgba(148,163,184,0.12) 75%) !important; background-size: 200% 100% !important; -webkit-background-clip: border-box !important; background-clip: border-box !important; border-radius: 6px; animation: kpiShimmer 1.4s linear infinite; user-select: none; }
.kpi-value.kpi-skeleton { width: 70%; min-height: 1.9rem; }
.kpi-trend.kpi-skeleton { width: 40%; min-height: 1rem; }
@keyframes kpiShimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .kpi-skeleton { animation: none; } }
/* Breadcrumb trail above deep-view page titles */
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 0.25rem; font-size: var(--fs-caption1); color: var(--text-muted); margin-bottom: 0.25rem; }
.crumbs a { color: var(--text-muted); text-decoration: none; cursor: pointer; }
.crumbs a:hover { color: var(--primary); text-decoration: underline; }
.crumbs .crumb-sep { opacity: 0.6; }
/* Page actions under a page title: one wrapping row, 8px apart. */
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.page-actions-group { position: relative; display: inline-flex; flex-wrap: wrap; gap: 0.5rem; }
.page-actions-group > .dash-checklist { top: 100%; left: 0; }
.crumbs .crumb-cur { color: var(--text-main); font-weight: 600; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Sidebar footer buttons: hover label when the rail is collapsed */
.sidebar.collapsed:not(.mobile-open) [data-tip] { position: relative; }
.sidebar.collapsed:not(.mobile-open) [data-tip]::after {
    content: attr(data-tip); position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%);
    background: var(--bg-surface-solid); border: 1px solid var(--border); color: var(--text-main);
    padding: 0.5rem 0.75rem; border-radius: 8px; font-size: var(--fs-footnote); font-weight: 600; white-space: nowrap;
    pointer-events: none; opacity: 0; transition: opacity 0.15s ease; box-shadow: 0 8px 24px rgba(0,0,0,0.4); z-index: 70;
}
.sidebar.collapsed:not(.mobile-open) [data-tip]:hover::after,
.sidebar.collapsed:not(.mobile-open) [data-tip]:focus-visible::after { opacity: 1; }
/* Dense tables: aligned digits + optional compact rows */
.ims-tbl, .details-table, #table-top-products, #calc-portfolio-table, #calc-achievement-table, .calc-target-table { font-variant-numeric: tabular-nums; }
body.tbl-compact .ims-tbl td { padding: 0.25rem 0.75rem; }
body.tbl-compact .ims-tbl th { padding: 0.25rem 0.75rem; }
body.tbl-compact .details-table td { padding: 0.5rem 0.75rem; }
body.tbl-compact .calc-target-table td, body.tbl-compact #calc-portfolio-table td { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.ims-cols-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 90; min-width: 220px; max-height: 60vh; overflow-y: auto; background: var(--bg-surface-solid); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 14px 44px rgba(0,0,0,0.6); padding: 0.5rem; display: none; }
.ims-cols-pop.open { display: block; }
.ims-cols-pop label { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0.5rem; font-size: var(--fs-footnote); border-radius: 6px; cursor: pointer; white-space: nowrap; }
.ims-cols-pop label:hover { background: rgba(255,255,255,0.05); }
.ims-cols-pop .cols-head { display: flex; justify-content: space-between; align-items: center; font-size: var(--fs-caption2); text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 700; padding: 0.125rem 0.5rem 0.5rem; }
.ims-cols-pop .cols-head button { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; text-transform: none; letter-spacing: 0; }
/* Frozen first data column in Market Browser tables (wide tables only) */
.ims-tbl td.ims-freeze, .ims-tbl th.ims-freeze, .ims-tbl td.ims-freeze-tick, .ims-tbl th.ims-freeze-tick { position: sticky; }
.ims-tbl td.ims-freeze, .ims-tbl td.ims-freeze-tick { z-index: 2; background-color: var(--bg-surface-solid); }
.ims-tbl th.ims-freeze, .ims-tbl th.ims-freeze-tick { z-index: 5; }
.ims-tbl .ims-freeze { box-shadow: 1px 0 0 var(--border); }
.ims-tbl tbody tr:hover td.ims-freeze, .ims-tbl tbody tr:hover td.ims-freeze-tick { background-image: linear-gradient(rgba(14,165,233,0.06), rgba(14,165,233,0.06)); }
/* Layout-edit tools: styled apart from the view tabs (Product Grid / Charts / ...) */
#dash-charts-btn-ims, #dash-tidy-btn-ims, #dash-reset-btn-ims,
#dash-charts-btn-brands, #dash-tidy-btn-brands, #dash-reset-btn-brands {
    border: 1px dashed var(--secondary); color: var(--secondary-text); background: rgba(139,92,246,0.08);
}
#dash-charts-btn-ims:hover, #dash-tidy-btn-ims:hover, #dash-reset-btn-ims:hover,
#dash-charts-btn-brands:hover, #dash-tidy-btn-brands:hover, #dash-reset-btn-brands:hover { background: rgba(139,92,246,0.18); }
#bd-analytics-grid.analytics-collapsed:not(.dash-editing) { display: none !important; }
.trend-up { color: var(--success); } .trend-down { color: var(--danger); }

.sparkline-container {
    position: absolute; bottom: 0; left: 0; right: 0; height: 50%; opacity: 0.3; z-index: 1;
    pointer-events: none; /* Let clicks pass through to card */
}

/* Chart Containers */
.chart-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-bottom: 1.5rem; gap: 0.5rem; }
#calc-results > .bento-grid { max-width: 100%; }
#view-calc .bento-grid { max-width: 100%; }
#view-calc .bento-card { min-width: 0; max-width: 100%; }
/* minmax(0,1fr), not plain 1fr: a `1fr` track keeps an implicit
   min-width of min-content, so a wide table/chart inside a card
   stretches its track past its share and the surplus is clipped on
   the right (body is overflow-x:clip, so it reads as cut-off
   content, not a scrollbar). */
#calc-sku-charts-container { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; width: 100%; max-width: 100%; }
#calc-sku-charts-container > * { min-width: 0; }
/* Horizontal-scroll wrapper around the Target Configuration table. */
.calc-table-scroll { overflow-x: auto; max-width: 100%; }
.chart-title { font-size: var(--fs-body); font-weight: 600; }
/* Calculator per-SKU cards: the Units/Value buttons stay beside the title (a long title wraps
   inside its own space instead of pushing the buttons to a second line).
   A long SKU name used to wrap the buttons onto a second line, which changed the
   chart area's height and made Chart.js resize (cutting the grow-in animation short). */
.chart-header.calc-sku-header { flex-wrap: nowrap; }
.chart-header.calc-sku-header .chart-title { min-width: 0; flex: 1 1 auto; overflow-wrap: anywhere; }
.chart-header.calc-sku-header .chart-taps { flex: 0 0 auto; }
/* Fixed chart height: the chart's size must not depend on how many lines the title takes
   (or on the other card's height), or a late reflow resizes it mid-animation. */
.chart-wrap.calc-sku-wrap { flex: none; height: 300px; min-height: 300px; }
.chart-wrap { flex: 1; position: relative; min-height: 250px; width: 100%; overflow: hidden; }
.chart-wrap.tall { min-height: 350px; }

/* Fix for Chart.js infinite flex stretch bug */
.chart-wrap canvas { position: absolute !important; top: 0; left: 0; width: 100% !important; height: 100% !important; }

/* Enhanced Tables */
.table-wrap { overflow-x: auto; margin-top: 1rem; }
table { width: 100%; border-collapse: separate; border-spacing: 0 0.25rem; }
th { padding: 0 0.75rem 0.5rem; text-align: left; color: var(--text-muted); font-size: var(--fs-caption1); text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
td { padding: 0.5rem 0.75rem; background: rgba(255,255,255,0.04); font-size: var(--fs-footnote); }
td:first-child { border-top-left-radius: 12px; border-bottom-left-radius: 12px; font-weight: 500;}
td:last-child { border-top-right-radius: 12px; border-bottom-right-radius: 12px; }
tr:hover td { background: rgba(14, 165, 233, 0.05); }
.td-right { text-align: right; }

.progress-bar-bg { width: 100px; height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; display: inline-block; vertical-align: middle; margin-left: 8px; overflow: hidden;}
.progress-bar-fill { height: 100%; border-radius: 3px; background: var(--primary); }

/* Details Table (Compact) */
.details-table-wrap {
    max-height: 280px; overflow-y: auto; overflow-x: auto; margin-top: 1.5rem;
    border-radius: 12px; border: 1px solid var(--border); background: rgba(0,0,0,0.2);
}
.details-table { width: 100%; border-collapse: collapse; border-spacing: 0; }
.details-table th {
    position: sticky; top: 0; background: rgba(17, 24, 39, 0.95); backdrop-filter: blur(10px);
    padding: 1rem; text-align: left; color: var(--text-muted); font-size: var(--fs-caption1);
    text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); z-index: 10;
}
.details-table td { padding: 0.75rem 1rem; font-size: var(--fs-footnote); border-bottom: 1px solid rgba(51, 65, 85, 0.3); transition: background-color 0.2s; background: transparent; }
.details-table td:first-child, .details-table td:last-child { border-radius: 0; }
.details-table tbody tr:last-child td { border-bottom: none; }
.details-table tbody tr:hover td { background: rgba(14, 165, 233, 0.1); }
.details-table th.td-right, .details-table td.td-right { text-align: right; }

.details-table-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
.details-table-wrap::-webkit-scrollbar-track { background: transparent; }
.details-table-wrap::-webkit-scrollbar-thumb { background: rgba(51, 65, 85, 0.8); border-radius: 3px; }
.details-table-wrap::-webkit-scrollbar-thumb:hover { background: var(--primary); }

.table-badge { display: inline-block; padding: 0.25rem 0.5rem; border-radius: 6px; font-size: var(--fs-caption1); font-weight: 600; }
.badge-danger { background: rgba(244, 63, 94, 0.15); color: var(--danger-text); }
.badge-success { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-neutral { background: rgba(148, 163, 184, 0.1); color: var(--text-muted); }

/* Utilities */
.hidden { display: none !important; }
.text-gradient { background: linear-gradient(to right, var(--primary), var(--secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

/* All tabs share the same content width as the Market tab */
.view-section { max-width: 100%; margin: 0 auto; }

/* Responsive */
@media (max-width: 1400px) {
    .bento-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .col-span-3, .col-span-4 { grid-column: span 2; }
    /* This grid isn't a .bento-grid, so collapse it here too. */
    #calc-sku-charts-container { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
    #calc-sku-charts-container { grid-template-columns: minmax(0, 1fr); }
}

/* ============================================
   MOBILE UI — complete overhaul ≤ 768 px
============================================ */

/* Mobile top header bar */
.mobile-header {
    display: none;
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    height: 60px;
    background: rgba(17, 24, 39, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    gap: 0.75rem;
}
.mobile-header-brand {
    display: flex; align-items: center; gap: 0.5rem; flex: 1;
    overflow: hidden;
}
.mobile-header-brand .brand-icon {
    width: 36px; height: 36px; border-radius: 10px; font-size: var(--fs-body); flex-shrink: 0;
}
.mobile-header-brand .brand-text { font-size: var(--fs-body); font-weight: 700; white-space: nowrap; }
.mobile-header-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.mobile-header-sync-btn {
    background: rgba(16,185,129,0.1); border: 1px solid var(--success); color: var(--success);
    width: 36px; height: 36px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.2s; transition-property: var(--ui-transition-props); flex-shrink: 0;
}
.mobile-header-sync-btn:active { transform: scale(0.92); }
.mobile-hamburger {
    background: rgba(255,255,255,0.04); border: 1px solid var(--border); color: var(--text-muted);
    width: 36px; height: 36px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease, transform 0.1s ease;
}
.mobile-hamburger.active { color: var(--primary); border-color: var(--primary); background: rgba(14,165,233,0.1); }
.mobile-hamburger:active { transform: scale(0.92); }

/* Sidebar overlay backdrop — fades with the drawer instead of a
   hard display:none/block flip (which popped in and out). */
.sidebar-backdrop {
    position: fixed; inset: 0; z-index: 149;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.28s ease, visibility 0s linear 0.28s;
}
.sidebar-backdrop.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.28s ease, visibility 0s linear 0s;
}

/* Bottom navigation bar */
.mobile-bottom-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
    background: rgba(17, 24, 39, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    padding: 0.5rem 0.25rem;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}
.bottom-nav-items {
    display: flex; align-items: stretch; justify-content: space-around;
}
.bottom-nav-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0.25rem; flex: 1; padding: 0.5rem 0.25rem;
    border-radius: 10px; cursor: pointer; color: var(--text-muted);
    font-size: var(--fs-caption2); font-weight: 600;
    transition: 0.2s; transition-property: var(--ui-transition-props); min-height: 52px;
}
.bottom-nav-item svg { flex-shrink: 0; }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item.active svg { filter: drop-shadow(0 0 6px var(--primary)); }
.bottom-nav-item:active { transform: scale(0.92); }
.bottom-nav-sep {
    width: 1px; background: var(--border); align-self: stretch; margin: 0.25rem 0;
}

/* ── Mobile + Tablet (≤ 1250 px CSS viewport ──)
   This breakpoint fires only on small screens / phones / tablets.
   Desktop at any normal zoom stays above this threshold. */
@media (max-width: 1250px) {
    /* Show mobile chrome */
    .mobile-header { display: flex; }
    .mobile-bottom-nav { display: block; }

    .sidebar-toggle { display: none; }

    /* Mobile drawer.
       The drawer stays laid out at this breakpoint (no display:none)
       and is parked off-screen with a transform, so it can animate
       BOTH in and out — the old keyframe animation only ran on open,
       so closing just yanked the panel away with display:none.
       .collapsed always rides along on mobile (it's the default
       markup class); the drawer ignores it and always shows full
       width + labels.
       padding-bottom clears the fixed .mobile-bottom-nav (z-index:200,
       ~68px) so the Sign Out / Sync DB buttons at the bottom of this
       flex column stay scrollable above it rather than underneath. */
    .sidebar,
    .sidebar.collapsed {
        display: flex !important;
        position: fixed;
        top: 60px; left: 0; bottom: 0;
        width: min(300px, 85vw);
        height: auto;
        gap: 1.25rem;
        border-right: 1px solid var(--border);
        border-bottom: none;
        padding: 1.5rem 1.25rem;
        padding-bottom: calc(68px + max(1.5rem, env(safe-area-inset-bottom)));
        z-index: 150;
        overflow-y: auto;
        overscroll-behavior: contain;
        box-shadow: 24px 0 48px -12px rgba(0, 0, 0, 0.55);
        transform: translateX(-100%);
        visibility: hidden;
        -webkit-tap-highlight-color: transparent;
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1),
                    visibility 0s linear 0.3s;
    }
    .sidebar.mobile-open,
    .sidebar.mobile-open.collapsed {
        transform: translateX(0);
        visibility: visible;
        transition: transform 0.34s cubic-bezier(0.32, 0.72, 0, 1),
                    visibility 0s linear 0s;
    }
    @media (prefers-reduced-motion: reduce) {
        .sidebar, .sidebar.collapsed,
        .sidebar.mobile-open, .sidebar.mobile-open.collapsed,
        .sidebar-backdrop, .sidebar-backdrop.visible {
            transition-duration: 0s;
        }
    }

    /* Drawer always shows full labels, even though .collapsed is set —
       also undo the desktop rail's label-collapse (max-width/opacity). */
    .sidebar.collapsed .brand-text,
    .sidebar.collapsed .nav-item span { max-width: none; opacity: 1; }
    .sidebar.collapsed .nav-item { justify-content: flex-start; padding: 0.75rem; gap: 0.75rem; }
    .sidebar.collapsed .brand { gap: 1rem; }

    /* Tap feedback for drawer rows — crisp press, no sticky hover */
    .sidebar .nav-item {
        -webkit-tap-highlight-color: transparent;
        transition: background 0.15s ease, color 0.15s ease, transform 0.08s ease;
    }
    .sidebar .nav-item:hover { background: transparent; color: var(--text-muted); }
    .sidebar .nav-item.active:hover { color: var(--primary); }
    .sidebar .nav-item:active {
        transform: scale(0.97);
        background: rgba(14, 165, 233, 0.14);
        color: var(--text-main);
    }

    /* Main content — no left margin, full width on mobile.
       Zoom is handled via viewport initial-scale=0.5 (preserves touch accuracy).
       Mobile styles fire at ≤ 1536 px CSS viewport (768 px physical). */
    .main-content,
    .main-content.expanded {
        margin-left: 0;
        width: 100%;
        padding: 0.75rem;
        padding-top: calc(60px + 0.75rem);   /* below mobile header */
        padding-bottom: calc(68px + 0.75rem); /* above bottom nav */
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* Single-column grid */
    .bento-grid { grid-template-columns: minmax(0, 1fr); gap: 0.75rem; }
    .col-span-1, .col-span-2, .col-span-3, .col-span-4 { grid-column: span 1; }
    .row-span-2 { grid-row: span 1; }

    /* Stack top-bar vertically */
    .top-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }
    .top-bar > div:last-child {
        width: 100%;
        align-items: flex-start !important;
    }
    .page-title { font-size: var(--fs-title2); }

    /* Filter controls: full-width, horizontally scrollable strip
       NOTE: overflow-x:auto implicitly clips overflow-y, hiding dropdown menus.
       Tabs with custom dropdowns override this with overflow:visible below. */
    #overview-controls > div,
    .top-bar [style*="display: flex"][style*="gap"] {
        width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.25rem;
        scrollbar-width: none;
    }
    #overview-controls > div::-webkit-scrollbar,
    .top-bar [style*="display: flex"][style*="gap"]::-webkit-scrollbar { display: none; }

    /* Make selects touch-friendly */
    select { font-size: var(--fs-body); padding: 0.75rem 2.5rem 0.75rem 1rem; }

    /* Custom dropdowns — full width */
    .custom-dropdown { width: 100%; }

    /* Brand deep-dive filter area stacks */
    #view-brands .top-bar > div:last-child {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem;
    }
    /* Allow dropdown bodies to overflow the stacked filter container (overrides the
       overflow-x:auto rule above, which implicitly clips overflow-y too) */
    #view-brands .top-bar [style*="display: flex"][style*="gap"] {
        overflow: visible;
    }
    #sku-filter-container,
    #bd-date-filter-container { width: 100%; }
    .sku-filter-hidden { display: none !important; }

    /* Calc tab: brand/SKU filter bar is outside .top-bar — stack vertically and
       allow dropdown bodies to show (no overflow clipping on this container) */
    #view-calc > [style*="display: flex"][style*="gap"],
    #view-calc > div[style*="display: flex"] {
        flex-direction: column !important;
        align-items: stretch !important;
        overflow: visible !important;
    }
    #calc-sku-filter-container { width: 100%; }

    /* Admin dashboard: each account card's Tabs/Brands columns stack
       on narrow screens instead of squeezing side by side. */
    .admin-card-grid { grid-template-columns: 1fr !important; }

    /* IMS tab: search results dropdown must escape the scrollable filter container */

    /* Tables: horizontal scroll + sticky first column */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 12px;
        border: 1px solid var(--border);
    }
    /* Details table (IMS full breakdown etc.) — reinforce touch scrolling and reduce height on mobile.
       overflow-x:auto is already set globally on .details-table-wrap; this block only overrides
       max-height and adds touch-momentum scrolling. */
    .details-table-wrap {
        -webkit-overflow-scrolling: touch;
        max-height: 260px;
    }
    table { min-width: 500px; }
    td, th { padding: 0.75rem 0.75rem; font-size: var(--fs-footnote); }
    td:first-child { position: sticky; left: 0; background: rgba(17, 24, 39, 0.98); z-index: 1; }
    tr:hover td:first-child { background: rgba(14, 165, 233, 0.15); }

    /* Remove extra horizontal padding in the IMS tab's inner wrapper on mobile */

    /* KPI cards: slightly reduced padding */
    .bento-card { padding: 1rem; }
    .kpi-value { font-size: var(--fs-title2); }

    /* Chart minimum heights on mobile */
    .chart-wrap { min-height: 180px; }
    .chart-wrap.tall { min-height: 240px; }


    /* Brand empty state */
    #brand-empty { padding: 2.5rem 1.25rem; }

    /* Progress bar width */
    .progress-bar-bg { width: 55px; }
}

/* Extra-small phones (≤ 360 px physical screen). */
@media (max-width: 720px) {
    .main-content, .main-content.expanded { padding: 0.75rem; padding-top: calc(60px + 0.75rem); padding-bottom: calc(68px + 0.75rem); }
    .bento-grid { gap: 0.75rem; }
    .page-title { font-size: var(--fs-title2); }
    .kpi-value.kpi-lead { font-size: var(--fs-title1); }
    .bottom-nav-item { font-size: var(--fs-caption2); min-height: 50px; }
    .bottom-nav-item svg { width: 20px; height: 20px; }

    /* IMS molecule search dropdown: always escape clipping on mobile */
}

/* Month Selection Apply Bar */
.month-apply-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    background: rgba(14, 165, 233, 0.07);
    border: 1px solid rgba(14, 165, 233, 0.25);
    border-radius: 10px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}
.month-apply-text {
    flex: 1;
    font-size: var(--fs-caption1);
    color: var(--text-muted);
    min-width: 120px;
}
.apply-bar-btn {
    border: none;
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-size: var(--fs-caption1);
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: 0.2s; transition-property: var(--ui-transition-props);
    white-space: nowrap;
}
.apply-bar-btn-clear  { background: rgba(244,63,94,0.1);  color: var(--danger-text);     border: 1px solid var(--danger); }
.apply-bar-btn-cancel { background: rgba(148,163,184,0.1); color: var(--text-muted); border: 1px solid var(--border); }
.apply-bar-btn-apply  { background: var(--cta-gradient); color: white; border: 1px solid transparent; }
.apply-bar-btn:hover  { opacity: 0.85; transform: translateY(-1px); }
.month-override-hint  { font-size: var(--fs-caption2); color: var(--primary); text-align: right; margin-top: 0.25rem; }
.filter-clear-btn { background: rgba(244,63,94,0.08); color: var(--danger-text); border: 1px solid var(--danger); border-radius: 6px; padding: 0.25rem 0.75rem; font-size: var(--fs-caption1); font-weight: 600; cursor: pointer; font-family: inherit; transition: 0.2s; transition-property: var(--ui-transition-props); white-space: nowrap; }
.filter-clear-btn:hover { opacity: 0.85; transform: translateY(-1px); }

/* Login Specific Styles */
@keyframes float { 0% { transform: translateY(0px); } 50% { transform: translateY(-10px); } 100% { transform: translateY(0px); } }
@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}
#pass-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2); }
#btn-login:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--primary-glow); }

/* === Target Calculator View === */
.calc-target-table { width: 100%; border-collapse: separate; border-spacing: 0 0.4rem; }
.calc-target-table th { font-size: var(--fs-caption1); text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); font-weight: 600; padding: 0.5rem 0.75rem; text-align: left; white-space: nowrap; }
.calc-target-table td { padding: 0.5rem 0.75rem; vertical-align: middle; background: rgba(17,24,39,0.5); }
.calc-target-table tbody tr td:first-child { border-radius: 8px 0 0 8px; }
.calc-target-table tbody tr td:last-child { border-radius: 0 8px 8px 0; }
.calc-input { background: rgba(14,165,233,0.05); border: 1px solid var(--border); color: var(--text-main); padding: 0.5rem 0.75rem; border-radius: 8px; font-family: inherit; font-size: var(--fs-footnote); outline: none; transition: border-color 0.2s, box-shadow 0.2s; min-width: 90px; }
.calc-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(14,165,233,0.15); }
.calc-input-narrow { min-width: 65px; width: 75px; }
.calc-month-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; min-width: 190px; }
.calc-chip { padding: 0.25rem 0.5rem; font-size: var(--fs-caption2); font-weight: 600; border-radius: 5px; cursor: pointer; border: 1px solid var(--border); background: transparent; color: var(--text-muted); transition: 0.15s; transition-property: var(--ui-transition-props); font-family: inherit; white-space: nowrap; line-height: 1.4; }
.calc-chip:hover:not(:disabled):not(.calc-chip-unavail) { border-color: var(--warning); color: var(--warning); }
.calc-chip.selected { background: rgba(245,158,11,0.2); border-color: var(--warning); color: var(--warning); }
.calc-chip:disabled, .calc-chip.calc-chip-unavail { opacity: 0.3; cursor: not-allowed; }
/* Shortage month waiting for admin review (Target Calculator) */
.calc-chip.pending { border-style: dashed; border-color: var(--warning); color: var(--warning); background: transparent; }
.calc-target-locked { display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem; }
.calc-req-link { background: none; border: 0; padding: 0; font: inherit; font-size: var(--fs-caption2); color: var(--primary); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.calc-req-link:hover { color: var(--primary-light); }
.calc-req-note { font-size: var(--fs-caption2); color: var(--warning); white-space: nowrap; }
/* Per-quarter targets under the monthly target (target phasing) */
.calc-phase-note { font-size: var(--fs-caption2); color: var(--text-muted); white-space: nowrap; margin-top: 0.15rem; }
.ims-input.calc-field-missing, .ims-input.calc-field-missing:focus { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(225, 29, 72, 0.25); }
/* Admin -> Target review: pending count on the tab, "requested" link in Targets */
.ctr-count-badge { margin-left: 0.4rem; background: var(--danger-fill); color: #fff; border-radius: 999px; padding: 0.05rem 0.5rem; font-size: var(--fs-caption2); font-weight: 700; }
.ctr-pending-link { background: none; border: 0; padding: 0; margin-top: 0.2rem; font: inherit; font-size: var(--fs-caption2); color: var(--warning); cursor: pointer; white-space: nowrap; }
.ctr-pending-link:hover { text-decoration: underline; }
.calc-duration-preset { padding: 0.25rem 0.75rem; font-size: var(--fs-caption1); border-radius: 6px; border: 1px solid rgba(14,165,233,0.3); background: transparent; color: var(--text-muted); cursor: pointer; font-family: inherit; transition: 0.15s; transition-property: var(--ui-transition-props); }
.calc-duration-preset.active { background: rgba(14,165,233,0.2); color: var(--primary); border-color: var(--primary); font-weight: 600; }
.calc-display-val { color: var(--text-muted); font-size: var(--fs-footnote); white-space: nowrap; }
.calc-ach-great { color: #10b981; font-weight: 700; }
.calc-ach-good  { color: #f59e0b; font-weight: 700; }
.calc-ach-bad   { color: #f43f5e; font-weight: 700; }
#calc-brand-list .dropdown-item.calc-brand-all { font-weight: 600; color: var(--primary); border-bottom: 1px solid var(--border); }
/* The brand picker popover hangs below the card's header — let it overflow a short roll-up card instead of being clipped. */
#calc-portfolio-rollup .bento-card { overflow: visible; }
#calc-portfolio-table tr.calc-pf-brand { cursor: pointer; }
#calc-portfolio-table th.calc-pf-sortable, #calc-achievement-table th.calc-pf-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
/* Nine columns: let headers wrap and tighten cell padding so the roll-up fits without a horizontal scrollbar. */
#calc-portfolio-table { min-width: 0; }
#calc-portfolio-table th.calc-pf-sortable { white-space: normal; }
#calc-portfolio-table th, #calc-portfolio-table td { padding-left: 0.75rem; padding-right: 0.75rem; }
#calc-portfolio-table th.calc-pf-sortable:hover, #calc-achievement-table th.calc-pf-sortable:hover { color: var(--primary); }
#calc-portfolio-table th.calc-pf-sorted, #calc-achievement-table th.calc-pf-sorted { color: var(--primary); }
#calc-portfolio-table tr.calc-pf-sku td { background: rgba(255,255,255,0.015); font-size: var(--fs-footnote); padding-top: 0.75rem; padding-bottom: 0.75rem; }
#calc-portfolio-table tr.calc-pf-sku td:first-child { color: var(--text-muted); font-weight: 400; }
.calc-pf-open { background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: 6px; cursor: pointer; font-size: var(--fs-caption2); font-family: inherit; padding: 0.1rem 0.5rem; margin-left: 0.5rem; }
.calc-pf-open:hover { color: var(--primary); border-color: var(--primary); }
#calc-brand-dropdown { z-index: 60; }
#calc-sku-dropdown   { z-index: 50; }
.calc-export-btn { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0.75rem; font-size: var(--fs-caption1); font-weight: 600; font-family: inherit; border-radius: 8px; border: 1px solid rgba(14,165,233,0.4); background: rgba(14,165,233,0.1); color: var(--primary); cursor: pointer; transition: 0.18s; transition-property: var(--ui-transition-props); white-space: nowrap; }
.calc-export-btn:hover { background: rgba(14,165,233,0.22); border-color: var(--primary); }
.calc-export-btn:active { transform: scale(0.97); }
.calc-tap-btn { padding: 0.25rem 0.5rem; font-size: var(--fs-caption2); font-weight: 600; border-radius: 6px; border: 1px solid var(--border); background: transparent; color: var(--text-muted); cursor: pointer; font-family: inherit; transition: 0.15s; transition-property: var(--ui-transition-props); }
.calc-tap-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.calc-tap-btn.active { background: rgba(14,165,233,0.18); border-color: var(--primary); color: var(--primary); }
.calc-tap-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* === Brand Top Cards === */
#calc-brand-top-cards { display: flex; gap: 0.75rem; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.5rem; }
.brand-top-card {
    background: rgba(17,24,39,0.6);
    border-radius: 14px;
    padding: 0.75rem 1rem;
    flex: 0 0 auto;
    min-width: 200px;
    max-width: 320px;
    width: 280px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    transition: box-shadow 0.2s;
}
.brand-top-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.3); }
.brand-top-card.contribution { border-color: var(--primary); border-width: 2px; }
.brand-top-card.neutral { border-color: var(--border); }
.brand-top-card.growth-pos { border-color: #10b981; border-width: 2px; }
.brand-top-card.growth-neg { border-color: #f43f5e; border-width: 2px; }
.brand-top-card.sku-card { border-color: rgba(139,92,246,0.4); }
.brand-top-card-label {
    font-size: var(--fs-caption2);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
}
.brand-top-card-value {
    font-size: var(--fs-title2);
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.1;
}
.brand-top-card-value.sku-name { font-size: var(--fs-subhead); font-weight: 700; line-height: 1.3; }
.brand-top-card-sub {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--fs-caption1);
    color: var(--text-muted);
}
.brand-top-card-sub .pct-badge {
    font-weight: 700;
    font-size: var(--fs-caption2);
    padding: 0.1rem 0.5rem;
    border-radius: 5px;
    background: rgba(14,165,233,0.12);
    color: var(--primary);
}
.brand-top-card-sub .growth-badge {
    font-weight: 700;
    font-size: var(--fs-caption2);
    padding: 0.1rem 0.5rem;
    border-radius: 5px;
}
.brand-top-card-sub .growth-badge.pos { background: rgba(16,185,129,0.15); color: #10b981; }
.brand-top-card-sub .growth-badge.neg { background: rgba(244,63,94,0.15); color: #f43f5e; }
.brand-top-card-row .growth-badge { font-weight: 700; font-size: var(--fs-caption2); padding: 0.1rem 0.5rem; border-radius: 5px; }
.brand-top-card-row .growth-badge.pos { background: rgba(16,185,129,0.15); color: #10b981; }
.brand-top-card-row .growth-badge.neg { background: rgba(244,63,94,0.15); color: #f43f5e; }
.brand-top-card-bar { display: flex; gap: 0.5rem; align-items: center; }
.brand-top-card-bar .mini-bar-wrap {
    flex: 1;
    height: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
    overflow: hidden;
    display: flex;
}
.brand-top-card-bar .mini-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.25s ease-out;
}
.brand-top-card-bar .mini-bar-fill.brand { background: var(--primary); }
.brand-top-card-bar .mini-bar-fill.company { background: rgba(139,92,246,0.6); }
.brand-top-card-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.brand-top-card-row .jod-val { font-size: var(--fs-caption1); font-weight: 600; color: var(--text-main); }
.brand-top-card-growth {
    font-size: var(--fs-footnote);
    font-weight: 800;
    line-height: 1.1;
    white-space: nowrap;
}
.brand-top-card-growth.pos { color: #10b981; }
.brand-top-card-growth.neg { color: #f43f5e; }
.brand-top-card-growth .growth-sub {
    font-size: var(--fs-caption2);
    font-weight: 400;
    color: var(--text-muted);
    display: block;
}
.brand-top-card-diff {
    font-size: var(--fs-subhead);
    font-weight: 700;
    margin-top: 4px;
}

.calc-export-status { font-size: var(--fs-caption1); color: #10b981; margin-left: 0.25rem; opacity: 0; transition: opacity 0.3s; }
.calc-export-status.visible { opacity: 1; }

/* Generic bottom-right notification toast. Same hidden-state
   approach as the other hidden-by-default overlays (opacity/visibility/
   pointer-events, not just a transform) so there's no lingering
   invisible-but-clickable sliver once it's dismissed. */
#app-toast {
    position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 10000;
    display: flex; align-items: center; gap: 0.5rem;
    background: #1e293b; border: 1px solid rgba(16,185,129,0.4); border-radius: 12px;
    padding: 0.75rem 1rem; max-width: min(340px, calc(100vw - 2rem));
    box-shadow: 0 8px 28px rgba(0,0,0,0.5);
    font-size: var(--fs-footnote); color: var(--text-main);
    transform: translateY(16px); opacity: 0; visibility: hidden; pointer-events: none;
    transition: transform 0.2s cubic-bezier(0.2,0,0,1), opacity 0.2s ease-out, visibility 0s linear 0.2s;
}
#app-toast.visible {
    transform: translateY(0); opacity: 1; visibility: visible; pointer-events: auto;
    transition: transform 0.2s cubic-bezier(0.2,0,0,1), opacity 0.2s ease-out, visibility 0s linear 0s;
}
#app-toast-icon { color: #10b981; font-weight: 700; flex-shrink: 0; }
@media (max-width: 1250px) {
    /* Clear the fixed mobile bottom nav bar the same way the mobile
       sidebar's Sign Out button had to. */
    #app-toast { bottom: calc(68px + max(1rem, env(safe-area-inset-bottom))); right: 1rem; }
}
/* Back-to-top button — appears once a page is scrolled down
   (backToTopSync() in index.html). Same hidden-state approach as
   #app-toast, so the invisible button can't be clicked. Sits under
   the toast and dialogs (z-index) and above the mobile bottom nav. */
#back-to-top {
    position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 190;
    width: 44px; height: 44px; border-radius: 50%; padding: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-surface-solid); border: 1px solid var(--border);
    color: var(--text-muted); cursor: pointer; font-family: inherit;
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    transform: translateY(8px); opacity: 0; visibility: hidden; pointer-events: none;
    transition: transform 0.2s cubic-bezier(0.2,0,0,1), opacity 0.2s ease-out,
                color 0.2s ease, border-color 0.2s ease, visibility 0s linear 0.2s;
}
#back-to-top.visible {
    transform: none; opacity: 1; visibility: visible; pointer-events: auto;
    transition: transform 0.2s cubic-bezier(0.2,0,0,1), opacity 0.2s ease-out,
                color 0.2s ease, border-color 0.2s ease, visibility 0s linear 0s;
}
#back-to-top:hover { color: var(--primary); border-color: var(--primary); }
#back-to-top:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (max-width: 1250px) {
    #back-to-top { bottom: calc(68px + max(1rem, env(safe-area-inset-bottom))); right: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
    #back-to-top, #back-to-top.visible { transform: none; }
}
html.ims-embed #back-to-top { display: none !important; }

/* Group By option buttons */
.ims-gb-opt { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; padding: 0.75rem 0.75rem; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--text-muted); font-size: var(--fs-footnote); font-weight: 600; transition: 0.15s; transition-property: var(--ui-transition-props); user-select: none; }
.ims-gb-opt:hover { border-color: var(--primary); color: var(--text-main); background: rgba(14,165,233,0.08); }
.ims-gb-opt.ims-gb-active { border-color: var(--primary); background: rgba(14,165,233,0.15); color: var(--primary-light); }
/* Custom ATC molecule chips */
.ims-custom-mol-chip { display: flex; align-items: center; gap: 0.25rem; padding: 0.25rem 0.5rem 0.25rem 0.75rem; border-radius: 20px; font-size: var(--fs-caption1); font-weight: 500; cursor: pointer; transition: 0.15s; transition-property: var(--ui-transition-props); border: 1px solid transparent; }
.ims-custom-mol-chip.selected { background: rgba(14,165,233,0.2); border-color: rgba(14,165,233,0.4); color: var(--primary-light); }
.ims-custom-mol-chip:not(.selected) { background: rgba(17,24,39,0.6); border-color: var(--border); color: var(--text-muted); }
.ims-custom-mol-chip:hover { border-color: var(--primary); color: var(--text-main); }
.ims-custom-mol-chip .chip-x { width: 16px; height: 16px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: var(--fs-caption2); flex-shrink: 0; }
.ims-custom-mol-chip.selected .chip-x { background: rgba(14,165,233,0.3); color: var(--primary-light); }
.ims-custom-mol-chip:not(.selected) .chip-x { background: rgba(255,255,255,0.08); color: var(--text-muted); }
/* Export button hover */


/* ═══════════════════════════════════════════════════════════════
   IMS MARKET BROWSER
   Shared classes for the patterns that used to be hand-repeated as
   inline style="..." on every button, card and input.
   ═══════════════════════════════════════════════════════════════ */
.ims-pill {
    background: rgba(17,24,39,0.8); border: 1.5px solid var(--border);
    color: var(--text-muted); padding: 0.25rem 0.75rem; border-radius: 8px;
    cursor: pointer; font-size: var(--fs-caption1); font-weight: 600;
    font-family: inherit; transition: 0.15s; transition-property: var(--ui-transition-props); white-space: nowrap;
}
.ims-pill:hover:not(:disabled) { border-color: var(--primary); color: var(--primary-light); }
.ims-pill.active {
    background: rgba(14,165,233,0.15); border-color: var(--primary);
    color: var(--primary); font-weight: 700;
}
.ims-pill:disabled { opacity: 0.45; cursor: not-allowed; }
/* "Clear all filters" turns amber while any sidebar filter is active,
   so it's obvious the table is being narrowed. */
.ims-pill.filters-on {
    background: rgba(245,158,11,0.16); border-color: #f59e0b;
    color: #f59e0b; font-weight: 700;
}
.ims-pill.filters-on:hover:not(:disabled) { border-color: #fbbf24; color: #fbbf24; }
.ims-pill-sm { padding: 0.25rem 0.5rem; font-size: var(--fs-caption2); }
.ims-pill-lg { font-size: var(--fs-caption1); }
/* IMS header: MAT/YTD segmented control + data tabs on one row. */
.ims-period-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-top: 0.75rem; }
.ims-seg {
    display: inline-flex; gap: 0.125rem; padding: 0.125rem;
    border: 1.5px solid var(--border); border-radius: 10px; background: rgba(17,24,39,0.8);
}
.ims-seg .ims-pill { border-color: transparent; background: transparent; }
.ims-seg .ims-pill.active { background: rgba(14,165,233,0.15); border-color: var(--primary); }

.ims-card {
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 0.75rem; margin-bottom: 0.75rem;
}
.ims-card-head {
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; margin-bottom: 0.5rem; gap: 0.5rem;
}
.ims-card-title {
    font-size: var(--fs-caption1); font-weight: 700; color: var(--text-main);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.ims-card-arrow { color: var(--text-muted); font-size: var(--fs-caption2); }
/* Consumer Shift legend chips — reflect the active trace */
.shift-chip { padding: 2px 8px; border-radius: 999px; transition: background-color .12s ease, opacity .12s ease, box-shadow .12s ease; }
.shift-chip:hover { background-color: rgba(148,163,184,0.16); }
.shift-chip-hot { background-color: rgba(148,163,184,0.28); font-weight: 700; box-shadow: 0 0 0 1px rgba(226,232,240,0.35); }
.shift-chip-cold { opacity: 0.35; }
/* padding-right + scrollbar-gutter reserve room for the vertical
   scrollbar so it doesn't render on top of .ims-check-count's number
   badges — those sit flush against the right edge (margin-left:auto)
   with nothing else in this container claiming that space. */
.ims-card-body { max-height: 170px; overflow-y: auto; padding-right: 8px; scrollbar-gutter: stable; }

.ims-input {
    flex: 1; min-width: 0; padding: 0.25rem 0.5rem; font-size: var(--fs-caption1);
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg-surface); color: var(--text-main);
    outline: none; font-family: inherit; box-sizing: border-box;
}
.ims-input:focus { border-color: var(--primary); }

/* Admin Dashboard tab strip (Accounts / Portfolio / Sales upload) */
.admin-tabs { margin-bottom: 1.25rem; max-width: 100%; overflow-x: auto; }
.admin-tabs .ims-pill { white-space: nowrap; }

/* Portfolio page (admin) */
.pf-chip {
    display: inline-flex; align-items: center; gap: 0.25rem; max-width: 100%;
    padding: 0.12rem 0.125rem 0.12rem 0.75rem; border-radius: 999px;
    background: rgba(14,165,233,0.10); border: 1px solid rgba(14,165,233,0.25);
    font-size: var(--fs-caption1); color: var(--text-main); box-sizing: border-box;
}
.pf-chip > span { overflow-wrap: anywhere; }
.pf-chip > button {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: var(--fs-subhead); line-height: 1; padding: 0.1rem 0.25rem; border-radius: 999px; font-family: inherit;
}
.pf-chip > button:hover { color: var(--danger); background: rgba(239,68,68,0.14); }
.pf-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.85);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 9999; font-family: inherit;
}
.pf-dialog {
    background: var(--bg-surface-solid); border: 1px solid var(--border); border-radius: 16px;
    width: 92vw; margin: 6vh auto; display: flex; flex-direction: column; overflow: hidden; max-height: 86vh;
}
.pf-dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
.pf-dialog-body { flex: 1; overflow-y: auto; padding: 1rem 1.5rem; min-height: 0; }
.pf-dialog-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 1rem 1.5rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pf-field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 1rem; }
.pf-field label { font-size: var(--fs-caption1); color: var(--text-muted); font-weight: 600; }
.pf-field .ims-input { padding: 0.5rem 0.75rem; font-size: var(--fs-footnote); }
.pf-note { font-size: var(--fs-caption1); line-height: 1.45; padding: 0.5rem 1rem; border-radius: 10px; margin-bottom: 0.75rem; overflow-wrap: anywhere; }
.pf-edit-btn { background: none; border: 0; color: var(--text-muted); cursor: pointer; font-size: var(--fs-footnote); padding: 0 0.25rem; font-family: inherit; }
.pf-edit-btn:hover { color: var(--primary); }
.pf-note.err { border: 1px solid var(--danger); color: var(--danger); }
.pf-note.warn { border: 1px solid var(--warning); color: var(--warning); }
.pf-diff summary { cursor: pointer; font-weight: 600; font-size: var(--fs-footnote); padding: 0.5rem 0; }
.pf-diff ul { margin: 0.25rem 0 0.5rem 1rem; padding: 0; font-size: var(--fs-caption1); color: var(--text-muted); overflow-wrap: anywhere; }

/* Sales upload page (admin) */
.su-steps { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1.25rem; }
.su-step {
    display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; border-radius: 999px;
    border: 1.5px solid var(--border); background: rgba(17,24,39,0.6); color: var(--text-muted);
    font-size: var(--fs-caption1); font-weight: 600; white-space: nowrap;
}
.su-step .su-step-n {
    display: inline-flex; align-items: center; justify-content: center; width: 1.3rem; height: 1.3rem;
    border-radius: 50%; background: rgba(148,163,184,0.18); font-size: var(--fs-caption2);
}
.su-step.done { border-color: var(--success); color: var(--success); }
.su-step.done .su-step-n { background: var(--success); color: #0b1220; }
.su-step.active { border-color: var(--primary); color: var(--primary-light); background: rgba(14,165,233,0.12); }
.su-step.active .su-step-n { background: var(--primary); color: #0b1220; }
.su-step.attention { border-color: var(--warning); color: var(--warning); background: rgba(245,158,11,0.1); }
.su-step.attention .su-step-n { background: var(--warning); color: #0b1220; }
.su-step.locked { opacity: 0.55; }
.su-drop {
    border: 2px dashed var(--border); border-radius: 14px; padding: 2rem 1rem; text-align: center;
    color: var(--text-muted); cursor: pointer; transition: 0.15s; transition-property: var(--ui-transition-props);
}
.su-drop:hover, .su-drop.over { border-color: var(--primary); color: var(--primary-light); background: rgba(14,165,233,0.06); }
.su-badge { display: inline-block; padding: 0.125rem 0.5rem; border-radius: 6px; font-size: var(--fs-caption2); font-weight: 600; white-space: nowrap; }
.su-badge.ok { background: rgba(16,185,129,0.15); color: var(--success); }
.su-badge.warn { background: rgba(245,158,11,0.15); color: var(--warning); }
.su-badge.err { background: rgba(239,68,68,0.15); color: var(--danger); }
.su-badge.muted { background: rgba(148,163,184,0.15); color: var(--text-muted); }
.su-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.5rem; margin: 0.75rem 0; }
.su-stat { border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.75rem; min-width: 0; }
.su-stat .su-stat-l { font-size: var(--fs-caption2); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.su-stat .su-stat-v { font-size: var(--fs-body); font-weight: 700; color: var(--text-main); overflow-wrap: anywhere; }
.su-stat .su-stat-c { font-size: var(--fs-caption2); margin-top: 0.125rem; }
.su-frozen button, .su-frozen input, .su-frozen select, .su-frozen textarea { pointer-events: none; }
.su-frozen { opacity: 0.85; }
.su-list { margin: 0.5rem 0 0 1rem; padding: 0; font-size: var(--fs-caption1); overflow-wrap: anywhere; }
.su-report { width: 100%; box-sizing: border-box; min-height: 9rem; font-family: ui-monospace, monospace; font-size: var(--fs-caption1);
    background: var(--bg-surface); color: var(--text-main); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem; }
/* Native <option> lists don't reliably inherit a <select>'s color/background
   (OS-rendered popup in Chrome/Firefox), so without this the options show as
   near-white text on a native white background — invisible until hovered.
   Applies to every <select> in the app, not just .ims-input ones — the
   same OS-popup problem hits the plain `select { }` ones (date/period
   pickers, brand year/month selects, etc.) just as much. */
select option {
    background: #111827; color: var(--text-main);
}
.ims-map-combo { position: relative; }
.ims-map-opt {
    padding: 0.25rem 0.75rem; font-size: var(--fs-caption1); color: var(--text-main);
    cursor: pointer; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ims-map-opt:hover, .ims-map-opt.active { background: rgba(14,165,233,0.16); }
.ims-map-opt-more, .ims-map-opt-empty {
    padding: 0.25rem 0.75rem; font-size: var(--fs-caption2); color: var(--text-muted); font-style: italic;
}
.ims-filter-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.25rem; }

.ims-check-row {
    display: flex; align-items: center; gap: 0.5rem; padding: 0.125rem 0.1rem;
    font-size: var(--fs-caption1); color: var(--text-main); cursor: pointer; border-radius: 4px;
}
.ims-check-row:hover { background: rgba(14,165,233,0.07); }
.ims-check-row.is-empty { opacity: 0.38; }
.ims-check-count { margin-left: auto; font-size: var(--fs-caption2); color: var(--text-muted); }
/* Filter pop-up: options flow into as many columns as fit */
.ims-fpop-list {
    flex: 1; overflow-y: auto; padding: 1rem 1.5rem; min-height: 120px;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.125rem 1rem;
    align-content: start;
}
.ims-fpop-row { padding: 0.25rem 0.5rem; font-size: var(--fs-footnote); }
.ims-fpop-row > span:nth-child(2) { overflow-wrap: anywhere; }
.ims-fpop-row.is-picked { background: rgba(14,165,233,0.14); }
/* Molecule picker (imsOpenMolPicker): one column — combo names are long */
.ims-molpick-list { flex: 1; overflow-y: auto; padding: 0.75rem 1.5rem 1rem; min-height: 120px; }
.ims-molpick-row { padding: 0.375rem 0.5rem; font-size: var(--fs-footnote); }
.ims-molpick-row > span:nth-child(2) { overflow-wrap: anywhere; }
.ims-molpick-row.is-picked { background: rgba(14,165,233,0.14); }
/* Its per-market combination sections — a header that folds each one away */
.ims-molpick-mkt {
    display: flex; align-items: center; gap: 0.25rem;
    margin-top: 0.375rem; padding: 0 0 0 0.5rem; border: 1px solid var(--border); border-radius: 8px;
    background: rgba(17,24,39,0.45);
}
.ims-molpick-mkt:hover { background: rgba(14,165,233,0.08); }
.ims-molpick-mkt-all { flex-shrink: 0; margin: 0; cursor: pointer; }
.ims-molpick-mkt-all:disabled { cursor: default; opacity: 0.4; }
.ims-molpick-mkt-head {
    display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0;
    padding: 0.4375rem 0.5rem; border: 0; background: none; color: var(--text-main);
    font: inherit; font-size: var(--fs-footnote); font-weight: 600; text-align: left; cursor: pointer;
}
.ims-molpick-mkt-chev { color: var(--text-muted); font-size: var(--fs-caption2); transition: transform 0.15s; }
.ims-molpick-mkt.is-open .ims-molpick-mkt-chev { transform: rotate(90deg); }
.ims-molpick-mkt-name { min-width: 0; overflow-wrap: anywhere; }
.ims-molpick-mkt-body { padding: 0.25rem 0 0.25rem 0.75rem; }
.ims-molpick-nprod {
    flex-shrink: 0; border: 0; background: none; padding: 0.125rem 0.25rem; border-radius: 6px;
    font: inherit; font-size: var(--fs-caption2); color: var(--text-muted); cursor: pointer;
}
.ims-molpick-nprod:hover, .ims-molpick-nprod.is-open { color: var(--primary); background: rgba(14,165,233,0.1); }
.ims-molpick-nprod-chev { display: inline-block; transition: transform 0.15s; }
.ims-molpick-nprod.is-open .ims-molpick-nprod-chev { transform: rotate(180deg); }
.ims-molpick-prods { margin: 0 0 0.375rem 1.75rem; padding: 0.25rem 0 0.25rem 0.625rem; border-left: 2px solid var(--border); }
.ims-molpick-prod {
    display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem;
    padding: 0.1875rem 0; font-size: var(--fs-caption1); color: var(--text-main);
}
.ims-molpick-prod > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.ims-molpick-prod-mfr { color: var(--text-muted); font-size: var(--fs-caption2); }
.ims-molpick-prod-num { flex-shrink: 0; color: var(--text-muted); font-size: var(--fs-caption2); text-align: right; }
/* A brand row in the Multi-Year Trend chart's legend/table that's
   been clicked off (its line hidden) — dimmed so it still reads as
   "excluded" rather than looking identical to a shown row. */
.ims-trend-row-off { opacity: 0.4; }
.ims-trend-row-off td { text-decoration: line-through; text-decoration-color: rgba(148,163,184,0.5); }

.ims-chip {
    display: inline-flex; align-items: center; gap: 0.25rem;
    background: rgba(14,165,233,0.14); border: 1px solid rgba(14,165,233,0.4);
    color: var(--primary-light); padding: 0.25rem 0.5rem;
    border-radius: 999px; font-size: var(--fs-caption1); font-weight: 600;
}
.ims-chip .ims-chip-kind {
    font-size: var(--fs-caption2); text-transform: uppercase; letter-spacing: 0.5px;
    opacity: 0.75; font-weight: 700;
}
.ims-chip .ims-chip-x { cursor: pointer; opacity: 0.75; font-weight: 700; }
.ims-chip .ims-chip-x:hover { opacity: 1; color: var(--danger); }

.ims-summary-card {
    flex: 1; min-width: 120px; background: rgba(17,24,39,0.6);
    border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem 1rem;
}
.ims-summary-label {
    font-size: var(--fs-caption2); color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.5px; margin-bottom: 0.25rem;
}
.ims-summary-value { font-size: var(--fs-body); font-weight: 700; color: var(--text-main); }

.ims-tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-footnote); }
.ims-tbl th {
    padding: 0.5rem 0.75rem; text-align: left; font-size: var(--fs-caption2);
    text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted);
    border-bottom: 1px solid var(--border); background: rgba(17,24,39,0.5);
    white-space: nowrap; cursor: pointer; user-select: none;
}
.ims-tbl th.num, .ims-tbl td.num { text-align: right; }
/* Header row stays visible while scrolling — works against whatever
   scrolls: the data-table content area (#main-content in flow mode,
   #ims-table-host's own box on mobile) and every dialog body
   (overflow:auto, capped by the dialog's max-height). Needs an opaque
   background so scrolled rows don't show through the translucent
   default. */
.ims-tbl thead th {
    position: sticky; top: -1px; z-index: 3;
    background: var(--bg-surface-solid);
}
/* Only the OUTERMOST table in a scroll area gets a pinned header.
   A nested table (the strength breakdown inside an expandable brand
   row) must not pin its own header — it would float mid-list and its
   background would paint over the brand row above it. */
.ims-tbl td .ims-tbl thead th { position: static; box-shadow: none; z-index: auto; }
/* SKU view: the Page x/x + Prev/Next bar AND the column-title row
   both stay pinned while scrolling. The bar is a fixed ~43px tall
   (single text line + small pills), so the header pins right under it
   with a constant offset — no per-render JS measurement to go stale
   (it read 0 when imsRenderTable ran before the view was visible,
   which dropped the header behind the z-index:4 bar). */
.ims-sku-pagebar {
    /* left:0 keeps it pinned to the visible edge when a wide table
       scrolls sideways inside its box — otherwise the bar (only as
       wide as the box) scrolls away and leaves a gap on the right. */
    position: sticky; top: 0; left: 0; z-index: 4;
    background: var(--bg-surface-solid);
    min-height: 43px; box-sizing: border-box;
}
#ims-table-host .ims-sku-pagebar ~ .ims-tbl thead th {
    top: 42px;
}
/* These dialog bodies scroll and hold a pinned-header table, so they
   carry NO top padding (a padded strip above a sticky header shows
   the rows scrolling behind it). Put the top breathing room on the
   first child instead — a margin there scrolls away cleanly. */
#ims-compare-body > :first-child,
#ims-manage-mappings-body > :first-child { margin-top: 1rem; }
/* Default framing for the data-table views (Product / Brand / SKU /
   AI). Moved off the inline style so the Charts view can drop it. */
#ims-table-host { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
/* Data-table views (Product / Brand / SKU / AI): the table renders at
   its full natural height and the whole page scrolls — no inner
   scrollbar on the box — while .ims-tbl thead th (position:sticky)
   keeps the column titles pinned to the top of the content area on
   the way down.

   Desktop: #main-content is the scroller for BOTH axes, so a wide
   grid scrolls horizontally WITHIN the content column instead of
   making the whole document wider than the screen (which brought back
   a page-level horizontal scrollbar and bled past the right gutter
   that .main-content's overflow-x:clip normally enforces). The host
   itself stays overflow:visible so it never becomes its own scroll
   container (that would re-bind the sticky header to it).

   Mobile: keep the table in a bounded scroll box with its own
   scrollbars — a wide/tall grid must not force the small screen to
   pan two ways at once. */
#ims-table-host.ims-host-flow {
    max-height: calc(100dvh - 140px); overflow: auto;
    border-top-left-radius: 0; border-top-right-radius: 0;
}
@media (min-width: 769px) {
    #ims-table-host.ims-host-flow { max-height: none; overflow: visible; }
    body.ims-fullpage-tables #main-content {
        height: 100vh; height: 100dvh; overflow: auto;
        /* #main-content is the scroll container here; its own
           padding-top would push every position:sticky header down by
           that much and leave a dead strip above it where scrolled
           rows show through. Zero it and carry the breathing room on
           the view instead, so it scrolls away cleanly. */
        padding-top: 0;
    }
    body.ims-fullpage-tables #view-imsbrowser { padding-top: 2rem; }
    /* A table wider than its box (extra year columns, many text
       columns) would otherwise spill out past the border. Added by
       imsSyncTopScroll() only when it actually overflows: the box then
       becomes its own bounded scroller, so the table stays inside it
       with a horizontal scrollbar pinned to the box's bottom edge. */
    #ims-table-host.ims-host-flow.ims-host-wide {
        max-height: calc(100dvh - 140px); overflow: auto;
    }
}
/* The Product Grid carries more text columns than the Brand / SKU / AI
   tables (Manufacturer, Strength, Pack, Scope, Channel). Auto layout
   lets each text column shrink to its own content instead of holding a
   rigid share; a per-column max-width then caps it at (roughly) the
   space the old fixed layout gave it, so a long value wraps rather
   than pushing the table wide. Headers wrap (so a long label + its
   sort ▲/▼ isn't clipped), numeric figures never split and size to
   their digits, and any slack goes to the numeric columns. */
.ims-tbl-product { table-layout: auto; }
.ims-tbl-product th:not(.num), .ims-tbl-product td:not(.num) { overflow-wrap: anywhere; }
.ims-tbl-product thead th { white-space: normal; }
.ims-tbl-product td.num { white-space: nowrap; }
/* Column classes (not nth-child) so the caps hold whether or not the
   row-select checkbox column is present. */
.ims-tbl-product th.ims-col-product, .ims-tbl-product td.ims-col-product { max-width: 240px; padding-left: 0.25rem; }
.ims-tbl-product .ims-col-mfr { max-width: 260px; }
.ims-tbl-product .ims-col-strength { max-width: 120px; }
.ims-tbl-product .ims-col-pack { max-width: 110px; }
.ims-tbl-product .ims-col-scope { max-width: 180px; }
.ims-tbl-product .ims-col-channel { max-width: 140px; }
/* Floors for the same columns: with "Add year" columns on, the numeric
   columns claim the width and, since text may wrap anywhere, these
   would otherwise collapse to a letter or two per line. Below the
   floors the table simply gets wider and the box scrolls sideways. */
.ims-tbl-product th.ims-col-product, .ims-tbl-product td.ims-col-product { min-width: 150px; }
.ims-tbl-product .ims-col-mfr { min-width: 120px; }
.ims-tbl-product .ims-col-strength { min-width: 75px; }
.ims-tbl-product .ims-col-pack { min-width: 95px; }
.ims-tbl-product .ims-col-scope { min-width: 100px; }
.ims-tbl-product .ims-col-channel { min-width: 90px; }
/* Charts view: no bordered scroll box — the dashboard grid flows in
   the normal page so it fills the width and only the page scrolls. */
#ims-table-host.ims-charts-view {
    overflow: visible; border: 0; border-radius: 0;
}
/* Narrower than every other column's default padding — this is
   just the Product Grid's row-select checkbox, not a data
   column, so it doesn't need the same generous horizontal
   breathing room. */
.ims-tbl th.ims-tick-col, .ims-tbl td.ims-tick-col { width: 22px; padding-left: 0.5rem; padding-right: 0.125rem; text-align: center; }
.ims-tbl td {
    padding: 0.5rem 0.75rem; color: var(--text-main);
    border-bottom: 1px solid rgba(51,65,85,0.35);
}
/* Square grid cells — the global td:first/last-child pill radius shows
   as a curve on the solid-background frozen columns. */
.ims-tbl td:first-child, .ims-tbl td:last-child { border-radius: 0; }
.ims-tbl tbody tr:hover { background: rgba(14,165,233,0.06); }
.ims-tbl .pos { color: var(--success); }
.ims-tbl .neg { color: var(--danger); }
.ims-tbl .muted { color: var(--text-muted); }
/* Data table under a Multi-Year Trend chart: keep it compact and
   cap its height so a long "All brands" list scrolls inside its
   own box instead of stretching the card and squeezing the chart. */
.ims-trend-legend { max-height: 190px; overflow-y: auto; }
.ims-trend-legend .ims-tbl { font-size: var(--fs-caption2); }
.ims-trend-legend .ims-tbl th { padding: 0.25rem 0.5rem; font-size: var(--fs-caption2); letter-spacing: 0.2px; }
.ims-trend-legend .ims-tbl td { padding: 0.125rem 0.5rem; }
.ims-joswe-tag {
    background: rgba(16,185,129,0.18); color: #34d399; font-size: var(--fs-caption2);
    font-weight: 700; padding: 1px 4px; border-radius: 4px; margin-left: 0.25rem;
}
/* Joswe product's manufacturer name in the IMS tables — same green as the
   SALES / S badges; the row's only "this is ours" marker. */
.ims-mfr-joswe {
    display: inline-block; max-width: 100%; padding: 1px 6px; border-radius: 4px;
    background: rgba(16,185,129,0.18); color: #34d399; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle;
}
/* "S" on a single figure taken from the sales ledger (Show sales view);
   same green as the SALES row badge. Sits before the number so the digits
   stay right-aligned with the IMS figures around it. */
.ims-s-badge {
    display: inline-block; min-width: 14px; margin-right: 0.25rem; padding: 0 3px;
    border-radius: 3px; background: rgba(16,185,129,0.18); color: #34d399;
    font-size: var(--fs-caption2); font-weight: 700; line-height: 14px; text-align: center;
    vertical-align: 1px; cursor: help;
}

/* Loading feedback — the old browser had none of this, it relied purely
   on an internal re-entrancy flag with nothing shown to the user. */
.ims-spinner {
    display: inline-block; width: 13px; height: 13px; border-radius: 50%;
    border: 2px solid rgba(14,165,233,0.25); border-top-color: var(--primary);
    animation: ims-spin 0.7s linear infinite; vertical-align: -2px;
}
@keyframes ims-spin { to { transform: rotate(360deg); } }
.ims-loading-bar {
    display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem;
    background: rgba(14,165,233,0.08); border: 1px solid rgba(14,165,233,0.3);
    border-radius: 10px; color: var(--primary-light); font-size: var(--fs-caption1);
    font-weight: 600; margin-bottom: 0.75rem;
}
.ims-skeleton {
    height: 12px; border-radius: 4px; margin: 0.5rem 0;
    background: linear-gradient(90deg, rgba(51,65,85,0.35) 25%, rgba(71,85,105,0.5) 37%, rgba(51,65,85,0.35) 63%);
    background-size: 400% 100%; animation: ims-shimmer 1.3s linear infinite;
}
@keyframes ims-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.ims-busy { opacity: 0.55; pointer-events: none; }

.ims-empty {
    text-align: center; padding: 4rem 2rem; color: var(--text-muted);
    border: 2px dashed var(--border); border-radius: 20px;
}
.ims-banner {
    display: flex; justify-content: space-between; align-items: center;
    gap: 1rem; border-radius: 12px; padding: 0.75rem 1rem; margin-bottom: 1rem;
    font-size: var(--fs-caption1);
}
.ims-banner-warn {
    background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.4);
    color: var(--warning);
}
.ims-banner-ok {
    background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.4);
    color: #34d399;
}

/* ---- Search results dropdown ---- */
.sr-section-label {
    padding: 0.25rem 0.5rem; font-size: var(--fs-caption2); font-weight: 700;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px;
    border-bottom: 1px solid var(--border); margin-bottom: 0.25rem;
}
.sr-item {
    padding: 0.5rem 0.75rem; cursor: pointer; border-radius: 7px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.5rem; transition: background 0.1s;
}
.sr-item:hover { background: rgba(14,165,233,0.1); }
.sr-item-main { display: flex; align-items: center; flex-wrap: wrap; gap: 0.25rem; }
.sr-item-label { font-size: var(--fs-footnote); color: var(--text-main); font-weight: 600; }
.sr-item-sub   { font-size: var(--fs-caption2);  color: var(--text-muted); margin-top: 1px; }
.sr-item-mfr   { font-size: var(--fs-caption2);  color: var(--primary); margin-top: 1px; }
.sr-item-arrow { font-size: var(--fs-caption2);  color: var(--primary); flex-shrink: 0; }
.sr-badges { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; }
.sr-item-side { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.sr-mol-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.375rem; }
.sr-badge {
    font-size: var(--fs-caption2); background: rgba(14,165,233,0.15); color: #38bdf8;
    padding: 1px 4px; border-radius: 4px; font-weight: 600;
}
.sr-badge-combo {
    font-size: var(--fs-caption2); background: rgba(245,158,11,0.2); color: #f59e0b;
    padding: 1px 4px; border-radius: 4px; font-weight: 600;
}
.sr-atc-code {
    font-size: var(--fs-caption1); color: var(--primary); font-weight: 700; margin-right: 0.5rem;
}

/* ===== Background scroll lock while a modal / dialog is open =====
   Deliberately carries NO layout properties. The lock is enforced in
   JS by swallowing wheel/touch/key events (search modal-scroll-lock);
   the earlier `overflow: hidden` version repainted the whole page on
   every open and close, which is what looked like a flash. The class
   stays purely as a state hook for styling. */

/* ===== Guided tour (hands-on walkthrough) ===== */
#tour-overlay { position: fixed; inset: 0; z-index: 100000; display: none; font-family: var(--font-main); }
#tour-overlay.on { display: block; }
#tour-overlay [hidden] { display: none !important; }
/* The overlay box itself must not eat clicks, or the "hole" around a
   highlighted control would not be clickable; only the mask, the four
   blockers and the card take pointer events. */
#tour-overlay { pointer-events: none; }
#tour-mask, .tour-block, #tour-pop { pointer-events: auto; }
/* The full-screen mask swallows clicks on explainer steps. On a "Your turn"
   step it is hidden and four invisible blockers surround the highlighted
   control instead, leaving just that one hole clickable. */
#tour-mask { position: absolute; inset: 0; background: transparent; cursor: default; }
.tour-block { position: absolute; display: none; background: transparent; cursor: not-allowed; }
#tour-spot {
    position: absolute; border-radius: 14px; pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(3, 7, 18, 0.74), 0 0 0 2px var(--primary), 0 0 24px 6px var(--primary-glow);
    transition: left 0.35s cubic-bezier(0.4,0,0.2,1), top 0.35s cubic-bezier(0.4,0,0.2,1),
                width 0.35s cubic-bezier(0.4,0,0.2,1), height 0.35s cubic-bezier(0.4,0,0.2,1);
}
#tour-spot.no-target { box-shadow: 0 0 0 9999px rgba(3, 7, 18, 0.82); }
#tour-spot.live::after {
    content: ''; position: absolute; inset: -6px; border-radius: 18px;
    border: 2px solid var(--primary); opacity: 0; pointer-events: none;
    animation: tourPulse 1.7s ease-out infinite;
}
@keyframes tourPulse {
    0%   { opacity: 0.9; transform: scale(0.985); }
    70%  { opacity: 0;   transform: scale(1.05); }
    100% { opacity: 0;   transform: scale(1.05); }
}
#tour-pop {
    position: absolute; width: min(380px, calc(100vw - 24px));
    max-height: calc(100vh - 24px); overflow-y: auto;
    background: var(--bg-surface-solid); border: 1px solid var(--border);
    border-radius: 18px; padding: 1.25rem 1.25rem 1rem;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
    color: var(--text-main);
    transition: left 0.3s cubic-bezier(0.4,0,0.2,1), top 0.3s cubic-bezier(0.4,0,0.2,1);
}
#tour-pop .tour-eyebrow {
    font-size: var(--fs-caption2); font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
    color: var(--primary); margin-bottom: 0.5rem; padding-right: 1.5rem;
}
#tour-pop .tour-title { font-size: var(--fs-body); font-weight: 700; line-height: 1.28; margin-bottom: 0.5rem; }
#tour-pop .tour-body { font-size: var(--fs-footnote); line-height: 1.6; color: var(--text-muted); }
#tour-pop .tour-body strong { color: var(--text-main); font-weight: 650; }
#tour-pop .tour-body em { font-style: italic; }
.tour-task {
    margin-top: 0.75rem; padding: 0.75rem 0.75rem; border-radius: 12px;
    background: rgba(14, 165, 233, 0.1); border: 1px solid rgba(14, 165, 233, 0.45);
}
.tour-task.is-done { background: rgba(16, 185, 129, 0.12); border-color: rgba(16, 185, 129, 0.55); }
.tour-task-row { display: flex; align-items: flex-start; gap: 0.5rem; }
.tour-task-badge {
    flex-shrink: 0; font-size: var(--fs-caption2); font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase;
    background: var(--primary); color: #04121c; padding: 0.125rem 0.5rem; border-radius: 6px; margin-top: 0.1rem;
}
.tour-task.is-done .tour-task-badge { background: var(--success); }
.tour-task-text { font-size: var(--fs-footnote); line-height: 1.45; color: var(--text-main); font-weight: 600; }
.tour-task-actions { margin-top: 0.5rem; display: flex; }
.tour-menu { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.25rem; max-height: 46vh; overflow-y: auto; }
.tour-menu-title { font-size: var(--fs-caption2); font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.1rem; }
.tour-menu-item {
    display: flex; align-items: center; gap: 0.5rem; width: 100%; text-align: left;
    background: rgba(255,255,255,0.04); border: 1px solid var(--border); color: var(--text-main);
    padding: 0.5rem 0.75rem; border-radius: 10px; cursor: pointer; font-family: inherit;
    transition: border-color 0.15s, background 0.15s;
}
.tour-menu-item:hover { border-color: var(--primary); background: rgba(14, 165, 233, 0.08); }
.tour-menu-item.is-current { border-color: var(--primary); }
.tour-menu-num {
    flex-shrink: 0; width: 1.45rem; height: 1.45rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    background: rgba(14, 165, 233, 0.15); color: var(--primary); font-size: var(--fs-caption1); font-weight: 800;
}
.tour-menu-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.tour-menu-txt b { font-size: var(--fs-footnote); font-weight: 650; }
.tour-menu-txt small { font-size: var(--fs-caption2); color: var(--text-muted); }
.tour-menu-n { font-size: var(--fs-caption2); color: var(--text-muted); }
.tour-progress { height: 3px; border-radius: 3px; background: var(--border); margin-top: 1rem; overflow: hidden; }
.tour-progress i { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 3px; transition: width 0.3s ease; }
#tour-pop .tour-foot { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.75rem; }
#tour-count { flex: 1; font-size: var(--fs-caption2); color: var(--text-muted); text-align: center; white-space: nowrap; }
.tour-btn-mini {
    background: rgba(255,255,255,0.05); border: 1px solid var(--border); color: var(--text-main);
    padding: 0.5rem 1rem; border-radius: 10px; cursor: pointer; font-family: inherit;
    font-weight: 600; font-size: var(--fs-footnote); transition: border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.tour-btn-mini:hover { border-color: var(--primary); color: var(--primary); }
.tour-btn-primary { background: var(--primary); border-color: var(--primary); color: #04121c; }
.tour-btn-primary:hover { color: #04121c; box-shadow: 0 0 16px var(--primary-glow); }
.tour-btn-primary.tour-ready { animation: tourReady 1.4s ease-in-out infinite; }
@keyframes tourReady { 0%, 100% { box-shadow: 0 0 0 0 var(--primary-glow); } 50% { box-shadow: 0 0 0 6px transparent, 0 0 18px var(--primary-glow); } }
#tour-skip {
    position: absolute; top: 0.7rem; right: 0.8rem; background: none; border: none;
    color: var(--text-muted); font-size: var(--fs-body); cursor: pointer; padding: 0.25rem; line-height: 1;
}
#tour-skip:hover { color: var(--text-main); }
#tour-pop:focus-visible, .tour-btn-mini:focus-visible, #tour-skip:focus-visible, .tour-menu-item:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 2px;
}
@media (max-width: 700px) {
    #tour-pop {
        left: 12px !important; right: 12px; width: auto;
        top: auto !important; bottom: 12px;
        max-height: 62vh;
    }
    /* A highlighted control in the lower half (the bottom tab bar) moves the card to the top. */
    #tour-pop.at-top { top: 12px !important; bottom: auto; }
}
@media (prefers-reduced-motion: reduce) {
    #tour-spot, #tour-pop { transition: none; }
    #tour-spot.live::after, .tour-btn-primary.tour-ready { animation: none; }
}


/* ---- Target Calculator motion (opacity / transform only; never resizes a chart) ---- */
@keyframes calcRise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

#calc-target-cfg-body.calc-anim-expand, #calc-portfolio-inner.calc-anim-expand { animation: calcRise 0.25s ease-out; }

/* Numbers don't jiggle sideways while counting up */
#view-calc .brand-top-card-value { font-variant-numeric: tabular-nums; }

/* Button / chip feedback */
.calc-tap-btn, .bd-chip { transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s; }
.calc-tap-btn:active:not(:disabled), .bd-chip:active { transform: scale(0.96); }

@media (prefers-reduced-motion: reduce) {
        #calc-target-cfg-body.calc-anim-expand, #calc-portfolio-inner.calc-anim-expand { animation: none; }
    .calc-tap-btn:active:not(:disabled), .bd-chip:active { transform: none; }
}

/* EI columns are off by default: the Charts-tab legends and the AI drill-down
   popup (no column chooser of their own) hide them until EI is switched on in
   a table's Columns chooser. Toggled by imsColsSyncDefaultOff() in index.html. */
body.ims-ei-off .ims-ei-col { display: none; }

/* ── Single-chart embed mode (?embed=<chart>) ───────────────────────────────
   Used by the "PowerPoint link" button on each IMS chart card: the same live,
   interactive chart card, stripped of the app chrome so it fills a Web Viewer
   box on a slide. The html.ims-embed class is set by an inline script before
   first paint; .ims-embed-target is stamped on the chosen card by
   imsEmbedApply() in index.html. */
html.ims-embed #sidebar,
html.ims-embed #sidebar-backdrop,
html.ims-embed #mobile-header,
html.ims-embed #mobile-bottom-nav,
html.ims-embed #view-imsbrowser > .top-bar,
html.ims-embed #ims-sidebar,
html.ims-embed #ims-search-wrap,
html.ims-embed #ims-chips-wrap,
html.ims-embed #ims-summary,
html.ims-embed #ims-action-bar,
html.ims-embed #ims-atc-panel,
html.ims-embed #ims-table-section > div:first-child,
html.ims-embed #ims-table-topscroll,
html.ims-embed #ims-table-stats { display: none !important; }
html.ims-embed .main-content { margin-left: 0 !important; padding: 0.5rem 0.75rem !important; }
html.ims-embed body.ims-fullpage-tables #view-imsbrowser { padding-top: 0; }
html.ims-embed #ims-charts-canvas { display: block !important; height: auto !important; }
html.ims-embed #ims-charts-canvas > .dash-card:not(.ims-embed-target) { display: none !important; }
html.ims-embed #ims-charts-canvas > .ims-embed-target {
    position: static !important; transform: none !important; width: auto !important;
    height: auto !important; margin: 0 !important; grid-column: auto !important; grid-row: auto !important;
}
.ims-embed-btn { white-space: nowrap; }

/* Embed layout: one card exactly filling the box — no page scrollbar, title +
   controls kept, descriptive paragraphs dropped. The chart wrapper's height is
   computed in imsEmbedFit() from whatever the card's header/legend take. */
html.ims-embed, html.ims-embed body { height: 100%; overflow: hidden !important; }
html.ims-embed .main-content { padding: 0.25rem 0.5rem !important; overflow: hidden !important; }
html.ims-embed #ims-charts-canvas > .ims-embed-target {
    padding: 0.5rem 0.75rem !important;
    max-height: calc(100vh - 0.7rem); overflow-y: auto;
}
html.ims-embed .ims-embed-target > p { display: none !important; }
html.ims-embed .ims-embed-target > p#ims-chart-expansion-note:not(:empty),
html.ims-embed .ims-embed-target > p#ims-chart-expansion-ai-note:not(:empty) { display: block !important; }
html.ims-embed .ims-embed-target .ims-card-title { margin-bottom: 0 !important; }

/* Embed: the card's surface IS the whole box — no outer frame, border or
   rounded corners showing the page background around it. */
html.ims-embed, html.ims-embed body, html.ims-embed .app-container,
html.ims-embed .main-content {
    background: var(--bg-surface-solid, var(--bg-surface)) !important;
    background-image: none !important;
}
html.ims-embed .main-content { padding: 0 !important; }
html.ims-embed #ims-charts-canvas > .ims-embed-target {
    background: transparent !important; border: 0 !important; border-radius: 0 !important;
    box-shadow: none !important; padding: 0.5rem 1rem !important;
}

/* Embed fit: card = window height, chart wrapper = all the space left over. */
html.ims-embed #view-imsbrowser, html.ims-embed #ims-table-section, html.ims-embed #ims-table-host {
    padding: 0 !important; margin: 0 !important;
}
html.ims-embed #ims-charts-canvas > .ims-embed-target {
    height: 100vh !important; height: 100dvh !important; max-height: none !important;
    display: flex !important; flex-direction: column; box-sizing: border-box; overflow: hidden;
}
html.ims-embed .ims-embed-target > * { flex: 0 0 auto; }
html.ims-embed .ims-embed-target > .ims-embed-chart {
    flex: 1 1 0 !important; min-height: 0; height: auto !important;
}
html.ims-embed .ims-embed-target > [id$="-legend"] { max-height: 38%; overflow-y: auto; }

/* ── White-background embed (?embed=<chart>&ebg=light) ───────────────────────
   Picked in the "PowerPoint link" dialog for white slides. Re-points the
   tokens at a white card with dark ink and re-skins the few controls that
   hard-code a dark fill; the charts' own canvas ink is switched in
   index.html by imsInk(). Tooltips stay the usual dark box on purpose. */
html.ims-embed-light {
    --bg-base: #ffffff;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f1f5f9;
    --bg-surface-solid: #ffffff;
    --text-main: #0f172a;
    --text-muted: #475569;
    --border: rgba(100, 116, 139, 0.35);
    --primary-light: #0369a1;
    color-scheme: light;
}
html.ims-embed-light body { background: #ffffff; color: var(--text-main); }
html.ims-embed-light .ims-pill { background: #f1f5f9; border-color: #cbd5e1; color: #475569; }
html.ims-embed-light .ims-pill:hover:not(:disabled) { border-color: var(--primary); color: #0369a1; }
html.ims-embed-light .ims-pill.active { background: rgba(14,165,233,0.14); border-color: var(--primary); color: #0369a1; }
html.ims-embed-light select,
html.ims-embed-light .ims-input { background-color: #ffffff; color: #0f172a; border-color: #cbd5e1; }
html.ims-embed-light select option { background: #ffffff; color: #0f172a; }
html.ims-embed-light .ims-tbl th { background: #f8fafc; }
html.ims-embed-light .ims-tbl thead th { background: #f8fafc; }
html.ims-embed-light td { background: rgba(15, 23, 42, 0.035); }
html.ims-embed-light .shift-chip:hover { background-color: rgba(100,116,139,0.14); }
html.ims-embed-light .shift-chip-hot { background-color: rgba(100,116,139,0.22); box-shadow: 0 0 0 1px rgba(51,65,85,0.35); }
html.ims-embed-light .ims-trend-row-off td { text-decoration-color: rgba(51,65,85,0.5); }

/* Reduce Motion, app-wide: the per-feature guards above only covered a few
   animations. Durations go near-zero (not none) so transitionend /
   animationend handlers still fire; looping indicators stop after one pass. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* My requests page: compact rows, cells aligned to the top */
.mr-table td { vertical-align: top; font-size: var(--fs-caption1); }
.nav-item svg { flex-shrink: 0; }
.nav-item .ctr-count-badge { margin-left: auto; }
/* Collapsed rail: the count sits on the icon's corner instead of beside it
   (beside it, it would squeeze the icon). */
.sidebar.collapsed:not(.mobile-open) .nav-item .ctr-count-badge {
    position: absolute; top: 2px; right: 4px; margin: 0;
    max-width: none; opacity: 1; padding: 0 0.3rem; line-height: 1.35; font-size: 0.6rem;
}
