/* Dashboard 2.0 — ported from dashboard.py's <style> block + render_group_card's
   inline styles, adapted to real CSS now that we're not fighting Streamlit's
   DOM. Notably: no CARD_HEIGHT magic-number hack needed — CSS Grid rows
   naturally stretch every card in a row to match the tallest one. */

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background: #fafafa;
    color: #212529;
}

a { color: inherit; }

.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 24px;
    background: white;
    border-bottom: 1px solid #e9ecef;
    position: sticky;
    top: 0;
    z-index: 10;
    transition: transform 200ms ease;
}

/* Auto-hide (app.js toggles this on scroll-down, only under the mobile
   breakpoint below) — on a phone the topbar eats a much bigger share of
   the viewport than on desktop, so it should get out of the way while
   reading instead of staying permanently pinned. */
.topbar.topbar-hidden {
    transform: translateY(-100%);
}

.topbar .brand {
    font-weight: 700;
    font-size: 1.15rem;
    white-space: nowrap;
}

.tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.tabs a {
    padding: 8px 14px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    color: #495057;
}

.tabs a.active {
    background: #EBFBEE;
    color: #2F9E44;
    font-weight: 700;
}

.tabs a:hover:not(.active) {
    background: #f1f3f5;
}

main {
    padding: 20px 32px 60px;
    max-width: 1900px;
    margin: 0 auto;
}

/* Mobile: the topbar was wrapping the brand + 8 nav links into 3-4 rows,
   permanently eating a huge chunk of a phone's viewport since it's
   position:sticky. Collapse it into one compact, horizontally-scrollable
   row instead — same links, a fraction of the height. */
@media (max-width: 768px) {
    .topbar {
        gap: 10px;
        padding: 8px 12px;
        flex-wrap: nowrap;
        overflow: hidden;
    }

    .topbar .brand {
        font-size: 1rem;
    }

    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        -webkit-overflow-scrolling: touch;
    }

    .tabs::-webkit-scrollbar { display: none; }

    .tabs a {
        padding: 6px 10px;
        font-size: 0.85rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    main {
        padding: 12px 16px 40px;
    }

    .toolbar {
        padding: 12px 14px;
    }
}

.caption {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 20px;
    margin-bottom: 20px;
    align-items: flex-end;
    background: white;
    border: 1px solid #eef0f2;
    border-radius: 14px;
    padding: 16px 20px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.toolbar .field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toolbar label {
    font-size: 0.72rem;
    color: #868e96;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.toolbar input[type="text"],
.toolbar select,
.dropdown-field summary {
    padding: 9px 14px;
    border: 1px solid #e1e4e8;
    border-radius: 10px;
    font-size: 0.88rem;
    background: white;
    color: #212529;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.toolbar input[type="text"] { min-width: 240px; }

.toolbar input[type="text"]:focus,
.toolbar select:focus {
    outline: none;
    border-color: #2F9E44;
    box-shadow: 0 0 0 3px rgba(47, 158, 68, 0.14);
}

.toolbar select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23495057' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
    min-width: 160px;
}

.toolbar input[type="range"] {
    accent-color: #2F9E44;
    width: 200px;
    cursor: pointer;
}

/* Dropdown checklist (Format, Store, Unit) — a native <details>/<summary>
   pair, so opening/closing and focus behavior come free from the browser
   with zero JS. app.js only adds click-outside-to-close and the
   "N selected" summary text, both progressive enhancement. */
.dropdown-field { position: relative; }

.dropdown-field summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 170px;
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.dropdown-field summary::-webkit-details-marker { display: none; }

.dropdown-field summary .chevron {
    color: #868e96;
    flex-shrink: 0;
    transition: transform 150ms ease;
}

.dropdown-field[open] summary .chevron { transform: rotate(180deg); }

.dropdown-field[open] summary {
    border-color: #2F9E44;
    box-shadow: 0 0 0 3px rgba(47, 158, 68, 0.14);
}

.dropdown-summary-text {
    color: #212529;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 220px;
    max-height: 280px;
    overflow-y: auto;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.12);
    padding: 8px;
    z-index: 30;
}

.dropdown-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 0.86rem;
    color: #495057;
    cursor: pointer;
    user-select: none;
}

.dropdown-option:hover { background: #f8f9fa; }

.dropdown-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #2F9E44;
    cursor: pointer;
    flex-shrink: 0;
}

.toolbar .checkbox-field {
    flex-direction: row;
    align-items: center;
}

.switch-field {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 38px;
    font-size: 0.86rem;
    color: #495057;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    inset: 0;
    background: #dee2e6;
    border-radius: 22px;
    transition: background 150ms ease;
}

.switch .slider::before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 150ms ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .slider { background: #2F9E44; }
.switch input:checked + .slider::before { transform: translateX(16px); }

.merge-checkbox {
    width: 16px;
    height: 16px;
    accent-color: #2F9E44;
    cursor: pointer;
}

.htmx-indicator { opacity: 0; transition: opacity 100ms ease-in; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }

.product-grid {
    display: grid;
    /* auto-fit (not auto-fill): auto-fill reserves an invisible extra
       column track even with nothing to put in it, which stops the real
       cards from stretching to fill the row — leaves a dead gap at the
       right edge of every row. auto-fit collapses that empty track so
       the actual cards expand to use all available width instead. */
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    align-items: stretch;
}

.card {
    border: 1px solid #e9ecef;
    border-radius: 12px;
    padding: 16px;
    background: white;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.card-image {
    height: 190px;
    background: #f7f7f9;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.card-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.card-image .placeholder {
    font-size: 2.6rem;
}

.card-sport {
    color: #666;
    font-size: 0.82rem;
    margin-bottom: 4px;
}

.card-title {
    font-weight: 600;
    font-size: 1.02rem;
    line-height: 1.32;
    height: calc(1.32em * 2);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    color: #888;
    font-size: 0.8rem;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-spacer { flex-grow: 1; }

.best-badge {
    display: inline-block; background: #FFD54F; color: #4a3800;
    font-size: 0.75rem; font-weight: 700; padding: 2px 10px;
    border-radius: 12px; margin-bottom: 8px;
}

.store-badge {
    display: inline-block; color: white; font-size: 0.7rem; font-weight: 700;
    padding: 2px 9px; border-radius: 10px; margin-bottom: 6px;
}

.cheaper-badge {
    display: inline-block; background: #2F9E44; color: white;
    font-size: 0.7rem; font-weight: 700; padding: 2px 9px; border-radius: 10px;
}

.price-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.price-block {
    position: relative;
    flex: 1;
    border-radius: 8px;
    padding: 5px 12px;
    height: 54px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

.other-stores-hint {
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 0.6rem;
    color: #2F9E44;
    font-weight: 700;
    background: white;
    border: 1px solid #b2f2bb;
    border-radius: 8px;
    padding: 1px 5px;
    line-height: 1.4;
}

.store-popover {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
    padding: 8px 12px;
    font-size: 0.78rem;
    color: #666;
    line-height: 1.7;
    z-index: 20;
    max-height: 160px;
    overflow-y: auto;
    text-align: left;
}

.price-block:hover .store-popover,
.price-block:focus-within .store-popover {
    display: block;
}

.store-popover-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    opacity: 1;
    padding: 2px 0;
}

.store-popover-row.oos { opacity: 0.5; }
.store-popover-row a { text-decoration: none; flex: 1; min-width: 0; }

.store-popover-cart-btn {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 1px solid #ced4da;
    background: white;
    font-size: 0.72rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.store-popover-cart-btn:hover { background: #f1f3f5; }
.store-popover-cart-btn.in-cart { background: #EBFBEE; border-color: #2F9E44; color: #2F9E44; }

.price-block.cheapest { background: #EBFBEE; border: 1px solid #2F9E44; }
.price-block.not-cheapest { background: #F8F9FA; border: 1px solid #e9ecef; }

.price-block .pack-price {
    font-weight: 700;
    font-size: 1.32rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.price-block .pack-price small { font-size: 0.72rem; font-weight: 400; }

.price-block .total-price {
    color: #666;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
}

.view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 54px;
    border-radius: 8px;
    border: 1px solid #ced4da;
    background: white;
    color: #212529;
    font-weight: 500;
    font-size: 0.85rem;
    text-decoration: none;
    padding: 0 14px;
    white-space: nowrap;
}

.view-btn:hover { background: #f1f3f5; }

.cart-btn {
    width: 100%;
    padding: 8px 0;
    border-radius: 8px;
    border: 1px solid #ced4da;
    background: white;
    font-weight: 600;
    font-size: 0.83rem;
    cursor: pointer;
    margin-bottom: 6px;
}

.cart-btn:hover { background: #f1f3f5; }
.cart-btn.in-cart { background: #EBFBEE; border-color: #2F9E44; color: #2F9E44; }

.out-of-stock {
    color: #c92a2a;
    font-size: 0.75rem;
}

.switch-store-btn {
    border: none;
    background: none;
    color: #2F9E44;
    font-size: 0.7rem;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    margin-left: 2px;
}

.switch-store-btn:hover { color: #237a37; }

.deal-ratio {
    color: #e8590c;
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 6px;
}

.price-drop-note {
    color: #2F9E44;
    font-size: 0.78rem;
    font-weight: 600;
    margin-top: 6px;
}

.cart-badge {
    background: #2F9E44;
    color: white;
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-left: 4px;
}

.cart-store-group {
    margin-bottom: 24px;
}

.cart-store-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 0 2px 8px;
    border-bottom: 2px solid #e9ecef;
    margin-bottom: 12px;
    font-weight: 700;
    font-size: 1rem;
}

.cart-store-header-meta {
    font-weight: 500;
    font-size: 0.82rem;
    color: #888;
}

.cart-item {
    border: 1px solid #e9ecef;
    border-radius: 10px;
    padding: 14px;
    background: white;
    margin-bottom: 12px;
}

.cart-item-row {
    display: grid;
    grid-template-columns: 2.2fr 1fr 1fr 1.1fr 1.1fr 0.8fr 0.5fr;
    gap: 12px;
    align-items: center;
}

.cart-metric { display: flex; flex-direction: column; }
.cart-metric .label { font-size: 0.72rem; color: #888; }
.cart-metric .value { font-size: 1rem; font-weight: 600; }

.remove-btn {
    border: none;
    background: transparent;
    font-size: 1.1rem;
    cursor: pointer;
    color: #888;
}

.remove-btn:hover { color: #c92a2a; }

.cart-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e9ecef;
}

.cart-summary .label { font-size: 0.8rem; color: #888; }
.cart-summary .value { font-size: 1.3rem; font-weight: 700; }
.cart-summary .delta { font-size: 0.85rem; color: #2F9E44; }

.info-box {
    background: #E7F5FF;
    border: 1px solid #a5d8ff;
    border-radius: 8px;
    padding: 12px 16px;
    color: #1864ab;
}
