/* =====================================================================
   Groupbuyers — design tokens
   4 primary brand colors, per the brief:
     --green   #2F5233  (trust, wholesale, primary actions)
     --gold    #E8A33D  (savings, tier progress, highlights)
     --brick   #C1440E  (tier-unlock alerts, urgency, discounts)
     --charcoal #26333A (text, headers, dark UI)
   Neutrals below (cream/white/hairline) are structural, not brand colors.
   ===================================================================== */

:root {
    --green: #2F5233;
    --gold: #E8A33D;
    --brick: #C1440E;
    --charcoal: #26333A;

    --cream: #FAF7EF;
    --white: #FFFFFF;
    --hairline: #E4DFD3;

    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --radius: 10px;
    --radius-lg: 18px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--cream);
    color: var(--charcoal);
    line-height: 1.5;
}

h1, h2, h3, .display {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 1.15;
    margin: 0 0 0.4em;
}

a { color: var(--green); }
a:focus, button:focus, input:focus, select:focus { outline: 3px solid var(--gold); outline-offset: 2px; }

.container { max-width: 1120px; margin: 0 auto; padding: 0 24px; }

/* ---------- Header / Nav ---------- */
.site-header {
    background: var(--charcoal);
    color: var(--white);
    position: sticky;
    top: 0;
    z-index: 20;
}
.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    padding-bottom: 14px;
    max-width: 1400px; /* wider than the base .container — the header needs more room than page content does, especially the full 13-item admin nav */
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-display);
    font-size: 1.4rem;
    color: var(--white);
    text-decoration: none;
    font-weight: 600;
    flex-shrink: 0; /* never let the logo/name get squeezed to make room for nav items */
}
.brand .mark {
    width: 30px; height: 30px;
    border-radius: 8px;
    background: var(--gold);
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--charcoal);
    font-weight: 700;
}
.nav-links { display: flex; gap: 10px; align-items: center; flex-wrap: nowrap; min-width: 0; overflow-x: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.35) transparent; padding-bottom: 2px; padding-right: 2px; }
.nav-links::-webkit-scrollbar { height: 4px; }
.nav-links::-webkit-scrollbar-track { background: transparent; }
.nav-links::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.35); border-radius: 2px; }
.nav-links a {
    color: var(--white);
    text-decoration: none;
    font-size: 0.8rem;
    white-space: nowrap;
    flex-shrink: 0;
    opacity: 0.88;
}
.nav-links a:hover { opacity: 1; text-decoration: underline; }
.cart-pill {
    background: var(--gold);
    color: var(--charcoal);
    border-radius: 999px;
    padding: 3px 10px;
    font-weight: 700;
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ---------- Hero ---------- */
.hero {
    background: linear-gradient(180deg, var(--green) 0%, #24401f 100%);
    color: var(--white);
    padding: 56px 0 40px;
}
.hero .container { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 36px; align-items: center; }
.hero h1 { font-size: 2.6rem; color: var(--white); }
.hero p.lede { font-size: 1.1rem; opacity: 0.92; max-width: 46ch; }
.eyebrow {
    display: inline-block;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 10px;
}
.family-row { display: flex; gap: 12px; }
.family-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 10px;
    width: 130px;
}
.family-card svg { width: 100%; display: block; }
.family-card figcaption {
    color: var(--charcoal);
    font-size: 0.72rem;
    text-align: center;
    margin-top: 4px;
    font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius);
    padding: 10px 18px;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.92rem;
    cursor: pointer;
    text-decoration: none;
}
.btn-primary { background: var(--gold); color: var(--charcoal); }
.btn-primary:hover { background: #d8922f; }
.btn-secondary { background: transparent; border: 1.5px solid var(--white); color: var(--white); }
.btn-outline { background: transparent; border: 1.5px solid var(--charcoal); color: var(--charcoal); }
.btn-small { padding: 6px 12px; font-size: 0.82rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Cards / Grid ---------- */
.section { padding: 44px 0; }
/* Shop page catalog section (card + table view share this one container) —
   widened specifically to give the table view's doubled name column
   (.shop-table-name below) room without squeezing the other 8 columns.
   The card grid below shares this same section; its auto-fill/minmax
   layout is responsive, so it just shows more cards per row on the wider
   container rather than breaking. */
#catalog.container { max-width: 1320px; }
.shop-table-name { min-width: 320px; }
/* Admin inventory list (README §101) — 11 columns (Product, Distributor,
   Location, Valid from, Valid to, Verification, Unit price, Total cost,
   Reorder level, On hand, actions), noticeably more than #catalog's own
   table above, so a fixed pixel width risks still falling short and
   forcing .table-wrap's own horizontal scroll on some screens — exactly
   what this request was about avoiding. min() with a viewport-relative
   value adapts to whatever screen an admin is actually using, capped so
   it never gets absurdly wide on an ultra-wide monitor either. */
#inventory-list.container { max-width: min(96vw, 1900px); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 20px; }
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
}
.product-card {
    background: var(--white);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.product-card .icon-badge {
    width: 46px; height: 46px;
    border-radius: 12px;
    background: var(--cream);
    display: flex; align-items: center; justify-content: center;
}
.product-icon { width: 26px; height: 26px; }
.product-card h3 { font-size: 1.05rem; margin: 0; }
.product-card .unit { color: #6b6355; font-size: 0.82rem; }
.price-row { display: flex; align-items: baseline; gap: 8px; }
.price-now { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; color: var(--green); }
.price-base { text-decoration: line-through; color: #9a9284; font-size: 0.85rem; }
.discount-badge {
    background: var(--brick);
    color: var(--white);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
}

/* ---------- Bulk pricing tier hover tooltip (shop page + admin products) ---------- */
/* Show/hide is still CSS-only (:hover / :focus-within) — no JS needed
   for that part. POSITIONING now needs a small shared script (README
   §88, js/tooltip-position.js): all three popups on this page
   (tier-tip, notes-tip, image-tip below) switched from position:
   absolute to position: fixed, so a scrollable ancestor with
   overflow-x: auto (e.g. .table-wrap) can't clip them anymore — the
   same fix already proven for the header credit-tip popup, applied
   here too now that it was found affecting these as well. Unlike
   credit-tip's one predictable spot near the header, these can appear
   at any row's position in a table, so a single hardcoded fixed
   top/left won't work — the script positions each one against its own
   trigger's actual on-screen location instead. */
.tier-tip { position: relative; display: inline-flex; vertical-align: middle; }
.tier-tip-icon {
    width: 20px; height: 20px;
    border-radius: 999px;
    border: 1px solid var(--green);
    background: var(--white);
    color: var(--green);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    padding: 0;
}
.tier-tip-icon:hover, .tier-tip-icon:focus { background: var(--green); color: var(--white); outline: none; }
.tier-tip-popup {
    display: none;
    position: fixed;
    z-index: 20;
    background: var(--white);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(38,51,58,0.18);
    padding: 10px;
    min-width: 220px;
}
.tier-tip:hover .tier-tip-popup, .tier-tip:focus-within .tier-tip-popup { display: block; }
.tier-tip-popup table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.tier-tip-popup th, .tier-tip-popup td { padding: 4px 8px; text-align: left; white-space: nowrap; }
.tier-tip-popup thead th { color: #6b6355; font-weight: 700; border-bottom: 1px solid var(--hairline); }
.tier-tip-popup tr.tier-tip-active td { font-weight: 700; color: var(--green); }
.tier-tip-popup .tier-tip-title { font-weight: 700; font-size: 0.78rem; margin-bottom: 6px; white-space: normal; }

/* ---------- Product notes hover popup (shop page name, §40) ---------- */
.notes-tip { position: relative; }
.notes-tip-popup {
    display: none;
    position: fixed;
    z-index: 20;
    background: var(--white);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(38,51,58,0.18);
    padding: 14px;
    width: 280px;
    max-height: 260px;
    overflow-y: auto;
    font-weight: 400;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--charcoal);
    white-space: normal;
    cursor: auto;
}
.notes-tip:hover .notes-tip-popup, .notes-tip:focus-within .notes-tip-popup { display: block; }
.notes-tip-popup p:first-child { margin-top: 0; }
.notes-tip-popup p:last-child { margin-bottom: 0; }

/* ---------- Product image hover popup (shop page thumbnail, §40) ---------- */
.image-tip { position: relative; display: inline-block; cursor: pointer; }
.image-tip-popup {
    display: none;
    position: fixed;
    z-index: 20;
    background: var(--white);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(38,51,58,0.18);
    padding: 8px;
}
.image-tip-popup img { display: block; border-radius: calc(var(--radius-lg) - 4px); }
.image-tip:hover .image-tip-popup, .image-tip:focus .image-tip-popup { display: block; }

/* ---------- Header "Credits" balance hover popup (§53, fixed §54) ----------
   position: fixed rather than absolute — .nav-links has overflow-x: auto
   (horizontal scroll for a long nav on narrow viewports), and per the CSS
   Overflow spec, setting overflow-x to anything but visible forces
   overflow-y to become non-visible too, even though it was never set
   explicitly. That was silently clipping this popup, since it's
   positioned to extend below the trigger — position: fixed escapes any
   ancestor's overflow clipping entirely (verified: :hover/:focus-within
   matching is unaffected either way, since pseudo-class matching is based
   on the DOM tree, not the rendered layout position). Positioned as a
   fixed offset from the top-right of the viewport rather than tracking
   the trigger's exact position, since the trigger itself sits inside a
   horizontally-scrollable container whose scroll offset can't be
   followed without JavaScript — a stable, predictable top-right spot
   near the header (where Credits/Cart/Log out already visually cluster)
   is more robust than attempting pixel-perfect anchoring that would
   drift as soon as anyone scrolled the nav. */
.credit-tip { position: relative; display: inline-block; }
.credit-tip-popup {
    display: none;
    position: fixed;
    z-index: 30;
    top: 62px;
    right: 24px;
    background: var(--white);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(38,51,58,0.18);
    padding: 12px 16px;
    min-width: 220px;
    font-weight: 400;
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--charcoal);
    white-space: nowrap;
    cursor: auto;
    text-align: left;
}
.credit-tip:hover .credit-tip-popup, .credit-tip:focus-within .credit-tip-popup { display: block; }
.credit-tip-popup .credit-tip-row { display: flex; justify-content: space-between; gap: 16px; }
.credit-tip-popup .credit-tip-label { color: #6b6355; }

/* ---------- Suspicious-activity ticket alert (§49) — genuinely flashing, not just red ---------- */
@keyframes suspicious-flash {
    0%, 100% { background: rgba(193,68,14,0.10); }
    50% { background: rgba(193,68,14,0.35); }
}
.suspicious-ticket-row { animation: suspicious-flash 1.2s ease-in-out infinite; }
.suspicious-ticket-banner {
    animation: suspicious-flash 1.2s ease-in-out infinite;
    border: 2px solid var(--brick);
    border-radius: var(--radius-lg);
    padding: 14px 18px;
    margin-bottom: 16px;
    font-weight: 700;
    color: var(--brick);
}
@media (prefers-reduced-motion: reduce) {
    .suspicious-ticket-row, .suspicious-ticket-banner { animation: none; background: rgba(193,68,14,0.20); }
}

/* ---------- Community basket progress bar (signature element) ---------- */
.basket-progress {
    position: relative;
    height: 14px;
    background: var(--hairline);
    border-radius: 999px;
    overflow: visible;
    margin: 6px 0 2px;
}
.basket-progress .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--green), var(--gold));
    border-radius: 999px;
    transition: width 0.4s ease;
}
.basket-progress .tick {
    position: absolute;
    top: -3px;
    width: 2px;
    height: 20px;
    background: var(--charcoal);
    opacity: 0.35;
}
.basket-progress .tick.reached { background: var(--brick); opacity: 0.8; }
.progress-caption { font-size: 0.78rem; color: #6b6355; }
.progress-caption strong { color: var(--brick); }

.qty-form { display: flex; gap: 8px; margin-top: auto; }
.qty-form input[type=number] {
    width: 64px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: 8px;
    font-family: var(--font-body);
}

/* ---------- Tables (spreadsheet-style views) ---------- */
.table-wrap { overflow-x: auto; background: var(--white); border-radius: var(--radius-lg); border: 1px solid var(--hairline); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data-table th {
    background: var(--charcoal);
    color: var(--white);
    text-align: left;
    padding: 10px 14px;
    position: sticky; top: 0;
}
table.data-table td { padding: 9px 14px; border-bottom: 1px solid var(--hairline); }
table.data-table tr:nth-child(even) td { background: var(--cream); }
.pos { color: var(--brick); font-weight: 700; }
.neg { color: var(--green); font-weight: 700; }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat-card {
    background: var(--white);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    padding: 18px;
}
.stat-card .value { font-family: var(--font-display); font-size: 1.9rem; color: var(--green); }
.stat-card .label { font-size: 0.82rem; color: #6b6355; }

/* ---------- Forms ---------- */
.form-card {
    background: var(--white);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 420px;
    margin: 40px auto;
}
.form-card label { display: block; font-size: 0.85rem; font-weight: 700; margin: 14px 0 6px; }
.form-card input, .form-card select, .form-card textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 0.95rem;
}
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 0.88rem; margin-bottom: 14px; }
.alert-error { background: #fbe3da; color: var(--brick); border: 1px solid var(--brick); }
.alert-success { background: #e6ede2; color: var(--green); border: 1px solid var(--green); }

/* ---------- Stars ---------- */
.stars { color: var(--gold); letter-spacing: 2px; }

/* ---------- Footer ---------- */
.site-footer {
    background: var(--charcoal);
    color: var(--white);
    padding: 30px 0;
    margin-top: 50px;
    font-size: 0.85rem;
    opacity: 0.85;
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 16px 0;
}
.pagination-disabled { opacity: 0.4; pointer-events: none; }
.page-info { font-size: 0.85rem; color: #6b6355; }

/* ---------- Live-updating values (js/live-update.js) ---------- */
.live-flash {
    animation: live-flash-bg 1.6s ease-out;
    border-radius: 4px;
}
@keyframes live-flash-bg {
    0%   { background-color: rgba(232, 163, 61, 0.45); }
    100% { background-color: transparent; }
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
    .hero .container { grid-template-columns: 1fr; }
    .family-row { flex-wrap: wrap; }
    .nav-links { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .basket-progress .fill { transition: none; }
    .live-flash { animation: none; }
}
