/* B2B Sales Rep Portal - Frontend CSS v1.0.0 */

:root {
    --b2b-primary: #1e40af;
    --b2b-primary-dark: #1e3a8a;
    --b2b-accent: #10b981;
    --b2b-danger: #ef4444;
    --b2b-secondary: #0f172a;
    --b2b-bg: #f1f5f9;
    --b2b-surface: #ffffff;
    --b2b-border: #e2e8f0;
    --b2b-text: #1e293b;
    --b2b-text-muted: #64748b;
    --b2b-radius: 12px;
    --b2b-radius-sm: 8px;
    --b2b-shadow: 0 1px 3px rgba(0,0,0,.1);
    --b2b-shadow-md: 0 4px 12px rgba(0,0,0,.1);
    --b2b-shadow-lg: 0 8px 24px rgba(0,0,0,.12);
    --b2b-topbar-h: 52px;
    --b2b-mob-bar-h: 56px;
    --b2b-card-w: 260px;   /* širina kartice na mobu i tabletu */
}

* { box-sizing: border-box; }

.b2b-srp-portal {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--b2b-text);
    background: var(--b2b-bg);
    min-height: 100vh;
    line-height: 1.5;
}

/* ===== TOPBAR ===== */
.b2b-srp-topbar {
    position: sticky;
    top: 0;
    z-index: 200;
    background: var(--b2b-secondary);
    color: #fff;
    height: var(--b2b-topbar-h);
    box-shadow: var(--b2b-shadow-md);
}
.b2b-srp-topbar__inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    height: 100%;
    overflow: hidden;
}
.b2b-srp-topbar__rep {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-right: 12px;
    border-right: 1px solid rgba(255,255,255,.2);
    flex-shrink: 0;
}
.b2b-srp-topbar__customer {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.b2b-srp-topbar__label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .5px;
    opacity: .6;
    flex-shrink: 0;
}
.b2b-srp-topbar__name {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== MAIN ===== */
.b2b-srp-main {
    padding: 14px 12px;
    max-width: 1440px;
    margin: 0 auto;
}

/* ===== STEP ===== */
.b2b-srp-step { margin-bottom: 20px; }
.b2b-srp-step--hidden { display: none; }
.b2b-srp-step__title { font-size: 17px; font-weight: 700; margin: 0 0 10px; }

/* ===== NOTICE ===== */
.b2b-srp-notice {
    padding: 14px 16px;
    border-radius: var(--b2b-radius-sm);
    margin-bottom: 14px;
}
.b2b-srp-notice--error { background:#fef2f2; border:1px solid #fecaca; color:#991b1b; }
.b2b-srp-notice p { margin: 0; }

/* ===== SEARCH BOX ===== */
.b2b-srp-search-box { position: relative; margin-bottom: 10px; }
.b2b-srp-input {
    width: 100%;
    padding: 11px 42px 11px 14px;
    border: 2px solid var(--b2b-border);
    border-radius: var(--b2b-radius-sm);
    font-size: 15px;
    color: var(--b2b-text);
    background: var(--b2b-surface);
    outline: none;
    -webkit-appearance: none;
    transition: border-color .18s;
}
.b2b-srp-input:focus { border-color: var(--b2b-primary); }
.b2b-srp-search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 17px;
    opacity: .4;
    pointer-events: none;
}

/* ===== CUSTOMER RESULTS ===== */
.b2b-srp-customer-results { display: grid; gap: 8px; }
.b2b-srp-loading-hint {
    color: var(--b2b-text-muted);
    padding: 20px;
    text-align: center;
    background: var(--b2b-surface);
    border-radius: var(--b2b-radius-sm);
    border: 1px solid var(--b2b-border);
}
.b2b-srp-customer-card {
    background: var(--b2b-surface);
    border: 1.5px solid var(--b2b-border);
    border-radius: var(--b2b-radius);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    box-shadow: var(--b2b-shadow);
    transition: border-color .18s, box-shadow .18s;
}
.b2b-srp-customer-card:hover { border-color: var(--b2b-primary); box-shadow: var(--b2b-shadow-md); }
.b2b-srp-customer-card__info { flex: 1; min-width: 0; }
.b2b-srp-customer-card__name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b2b-srp-customer-card__company { font-size: 12px; color: var(--b2b-primary); font-weight: 500; }
.b2b-srp-customer-card__meta { font-size: 11px; color: var(--b2b-text-muted); margin-top: 2px; }

/* ===== MOBILE ORDER BAR ===== */
.b2b-srp-mobile-order-bar {
    position: sticky;
    top: var(--b2b-topbar-h);
    z-index: 150;
    padding: 8px 0;
    background: var(--b2b-bg);
    display: block;
}
.b2b-srp-mobile-order-bar__btn {
    width: 100%;
    height: var(--b2b-mob-bar-h);
    background: var(--b2b-primary);
    color: #fff;
    border: none;
    border-radius: var(--b2b-radius-sm);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: var(--b2b-shadow-md);
    transition: background .18s, transform .15s;
}
.b2b-srp-mobile-order-bar__btn:active { transform: scale(.98); }

@keyframes b2b-bounce {
    0%,100% { transform: scale(1); }
    40%      { transform: scale(1.06); }
    70%      { transform: scale(.96); }
}
.b2b-bounce { animation: b2b-bounce .5s ease; }

/* ===== LAYOUT ===== */
.b2b-srp-order-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ===== CATALOG ===== */
.b2b-srp-catalog-wrap { flex: 1; min-width: 0; }
.b2b-srp-catalog-header { margin-bottom: 10px; }

/* ===== PRODUCT GRID - MOBILE HORIZONTAL SCROLL ===== */
.b2b-srp-product-grid-wrap {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--b2b-primary) var(--b2b-border);
    padding-bottom: 8px;
    margin: 0 -12px;
    padding-left: 12px;
    padding-right: 12px;
}
.b2b-srp-product-grid-wrap::-webkit-scrollbar { height: 4px; }
.b2b-srp-product-grid-wrap::-webkit-scrollbar-track { background: var(--b2b-border); border-radius: 2px; }
.b2b-srp-product-grid-wrap::-webkit-scrollbar-thumb { background: var(--b2b-primary); border-radius: 2px; }

.b2b-srp-product-grid {
    display: flex;
    flex-direction: row;
    gap: 10px;
    flex-wrap: nowrap;
    width: max-content;
    min-width: 100%;
}

/* ===== PRODUCT CARD ===== */
.b2b-srp-product-card {
    background: var(--b2b-surface);
    border: 1.5px solid var(--b2b-border);
    border-radius: var(--b2b-radius);
    overflow: hidden;
    box-shadow: var(--b2b-shadow);
    display: flex;
    flex-direction: column;
    width: var(--b2b-card-w);
    flex-shrink: 0;
    transition: box-shadow .18s, transform .15s;
}
.b2b-srp-product-card:hover {
    box-shadow: var(--b2b-shadow-md);
    transform: translateY(-2px);
}
.b2b-srp-product-card__img-wrap {
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    background: #f1f5f9;
    flex-shrink: 0;
}
.b2b-srp-product-card__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .3s;
}
.b2b-srp-product-card:hover .b2b-srp-product-card__img { transform: scale(1.04); }

.b2b-srp-product-card__body {
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}
.b2b-srp-product-card__name {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--b2b-secondary);
    /* Maks 2 linije */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.b2b-srp-product-card__sku { font-size: 10px; color: var(--b2b-text-muted); font-family: monospace; }
.b2b-srp-product-card__price {
    font-size: 14px;
    font-weight: 700;
    color: var(--b2b-primary);
    line-height: 1.3;
}
.b2b-srp-product-card__price del { color: var(--b2b-text-muted); font-weight: 400; font-size: 11px; }
.b2b-srp-product-card__price small { font-size: 10px; font-weight: 400; }
.b2b-discount-badge {
    display: inline-block;
    background: #ef4444;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    margin-left: 3px;
    vertical-align: middle;
}
.b2b-srp-product-card__stock {
    font-size: 10px;
    display: flex;
    align-items: center;
    gap: 3px;
}
.b2b-srp-product-card__stock--in  { color: var(--b2b-accent); }
.b2b-srp-product-card__stock--out { color: var(--b2b-danger); }

.b2b-srp-product-card__footer {
    padding: 10px 12px;
    border-top: 1px solid var(--b2b-border);
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.b2b-srp-product-card__select {
    width: 100%;
    padding: 9px 10px;
    border: 1.5px solid var(--b2b-border);
    border-radius: var(--b2b-radius-sm);
    font-size: 13px;
    background: var(--b2b-surface);
    color: var(--b2b-text);
    outline: none;
    cursor: pointer;
    transition: border-color .18s;
    min-height: 40px;
}
.b2b-srp-product-card__select:focus { border-color: var(--b2b-primary); }

.b2b-srp-card-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.b2b-srp-qty-input {
    width: 100%;
    padding: 9px 8px;
    border: 1.5px solid var(--b2b-border);
    border-radius: var(--b2b-radius-sm);
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    outline: none;
    -webkit-appearance: none;
    transition: border-color .18s;
    min-height: 44px;
}
.b2b-srp-qty-input:focus { border-color: var(--b2b-primary); }

/* ===== BUTTONS ===== */
.b2b-srp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 9px 14px;
    border-radius: var(--b2b-radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    transition: background .18s, color .18s, border-color .18s;
    text-decoration: none;
    white-space: nowrap;
    min-height: 42px;
    outline: none;
}
.b2b-srp-btn--primary { background: var(--b2b-primary); color: #fff; border-color: var(--b2b-primary); }
.b2b-srp-btn--primary:hover { background: var(--b2b-primary-dark); }
.b2b-srp-btn--primary:disabled { opacity: .5; cursor: not-allowed; }
.b2b-srp-btn--outline { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.b2b-srp-btn--outline:hover { background: rgba(255,255,255,.15); }
.b2b-srp-btn--sm { padding: 5px 10px; font-size: 11px; min-height: 30px; }
.b2b-srp-btn--lg { padding: 13px 20px; font-size: 15px; min-height: 50px; }
.b2b-srp-btn--full { width: 100%; }
.b2b-srp-btn--select-customer {
    background: var(--b2b-primary); color: #fff; border-color: var(--b2b-primary);
    flex-shrink: 0;
}
.b2b-srp-btn--select-customer:hover { background: var(--b2b-primary-dark); }
.b2b-srp-btn--add {
    width: 100%;
    background: var(--b2b-accent);
    color: #fff;
    border-color: var(--b2b-accent);
    font-size: 14px;
    font-weight: 700;
    min-height: 48px;
    padding: 10px 12px;
    letter-spacing: .2px;
}
.b2b-srp-btn--add:hover:not(:disabled) { background: #059669; }
.b2b-srp-btn--add:disabled {
    opacity: .45; cursor: not-allowed;
    background: #94a3b8; border-color: #94a3b8;
}
.b2b-badge {
    background: #fff;
    color: var(--b2b-primary);
    font-size: 11px;
    font-weight: 800;
    padding: 1px 7px;
    border-radius: 999px;
    min-width: 20px;
    text-align: center;
}
/* Badge unutar order panela (na dark bg) */
.b2b-srp-order-panel__title .b2b-badge {
    background: var(--b2b-primary);
    color: #fff;
}

/* ===== ORDER PANEL - mobile: slide od dole ===== */
.b2b-srp-order-panel {
    background: var(--b2b-surface);
    border: 1.5px solid var(--b2b-border);
    border-radius: var(--b2b-radius);
    box-shadow: var(--b2b-shadow-lg);
    overflow: hidden;
    /* mobile: skrivena, slide up */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 300;
    transform: translateY(100%);
    transition: transform .32s cubic-bezier(.4,0,.2,1);
    max-height: 85vh;
    overflow-y: auto;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
.b2b-srp-order-panel--open {
    transform: translateY(0);
}
/* Backdrop kad je panel otvoren */
.b2b-srp-order-panel--open::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.3);
    z-index: -1;
}

.b2b-srp-order-panel__inner {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 32px; /* extra space na dnu za prste */
}
.b2b-srp-order-panel__title {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--b2b-secondary);
}
.b2b-srp-order-customer-info {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: var(--b2b-radius-sm);
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.5;
}
.b2b-srp-order-customer-info strong { font-size: 13px; }
.b2b-info-sep { opacity: .4; margin: 0 2px; }

.b2b-srp-order-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 38vh;
    overflow-y: auto;
}
.b2b-srp-order-empty { text-align: center; color: var(--b2b-text-muted); padding: 20px 0; font-size: 13px; }

.b2b-srp-order-item {
    display: grid;
    grid-template-columns: 38px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 7px 10px;
    background: var(--b2b-bg);
    border: 1px solid var(--b2b-border);
    border-radius: var(--b2b-radius-sm);
}
.b2b-srp-order-item__img { width:38px; height:38px; object-fit:cover; border-radius:6px; }
.b2b-srp-order-item__info { min-width: 0; }
.b2b-srp-order-item__name { font-weight:600; font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.b2b-srp-order-item__meta { color: var(--b2b-text-muted); font-size: 11px; }
.b2b-srp-order-item__right { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.b2b-srp-order-item__subtotal { font-weight:700; color:var(--b2b-primary); font-size:12px; white-space:nowrap; }
.b2b-srp-order-item__remove {
    background: none; border: none; color: var(--b2b-danger);
    cursor: pointer; font-size: 14px; padding: 2px 4px;
    border-radius: 4px; line-height: 1; transition: background .15s;
}
.b2b-srp-order-item__remove:hover { background: #fee2e2; }

.b2b-srp-order-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #f0f9ff;
    border-radius: var(--b2b-radius-sm);
    font-size: 15px;
    font-weight: 600;
}
.b2b-srp-order-total-row strong { font-size: 19px; color: var(--b2b-primary); }

.b2b-srp-order-message {
    padding: 10px 12px;
    border-radius: var(--b2b-radius-sm);
    font-size: 12px;
    text-align: center;
    font-weight: 500;
}
.b2b-srp-order-message--success { background:#f0fdf4; border:1px solid #86efac; color:#166534; }
.b2b-srp-order-message--error   { background:#fef2f2; border:1px solid #fca5a5; color:#991b1b; }

/* ===== GLOBAL MESSAGE ===== */
.b2b-srp-global-message {
    position: fixed;
    bottom: 80px;
    right: 16px;
    z-index: 9999;
    max-width: 300px;
    padding: 12px 16px;
    border-radius: var(--b2b-radius);
    box-shadow: var(--b2b-shadow-lg);
    font-size: 13px;
    font-weight: 500;
    animation: b2b-slide-in .28s ease;
}
@keyframes b2b-slide-in { from{transform:translateY(20px);opacity:0} to{transform:translateY(0);opacity:1} }
.b2b-srp-global-message--success { background:#166534; color:#fff; }
.b2b-srp-global-message--error   { background:#991b1b; color:#fff; }

/* ===== LOADING ===== */
.b2b-srp-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--b2b-text-muted);
    width: 100%;
}
.b2b-srp-spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--b2b-border);
    border-top-color: var(--b2b-primary);
    border-radius: 50%;
    animation: b2b-spin .7s linear infinite;
}
@keyframes b2b-spin { to{transform:rotate(360deg)} }

/* ===== PAGINATION ===== */
.b2b-srp-pagination { display:flex; gap:6px; justify-content:center; margin-top:12px; flex-wrap:wrap; }
.b2b-srp-pagination button {
    min-width: 40px; height: 40px;
    border: 1.5px solid var(--b2b-border);
    border-radius: var(--b2b-radius-sm);
    background: var(--b2b-surface);
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
.b2b-srp-pagination button.active,
.b2b-srp-pagination button:hover { background:var(--b2b-primary); color:#fff; border-color:var(--b2b-primary); }

/* ===== NO RESULTS ===== */
.b2b-srp-no-results {
    text-align: center;
    padding: 32px 16px;
    color: var(--b2b-text-muted);
    background: var(--b2b-surface);
    border-radius: var(--b2b-radius);
    border: 1px dashed var(--b2b-border);
    width: 100%;
}

/* ================================================================
   TABLET 640px+
================================================================ */
@media (min-width: 640px) {
    .b2b-srp-main { padding: 16px; }
    :root { --b2b-card-w: 220px; }
    .b2b-srp-customer-results { grid-template-columns: repeat(2, 1fr); }
}

/* ================================================================
   DESKTOP 1024px+ — vertikalni grid, order panel sa strane
================================================================ */
@media (min-width: 1024px) {
    .b2b-srp-main { padding: 20px 24px; }

    /* Sakrij mobile toggle bar na desktopu */
    .b2b-srp-mobile-order-bar { display: none; }

    /* Horizontalni layout */
    .b2b-srp-order-layout {
        flex-direction: row;
        align-items: flex-start;
        gap: 20px;
    }
    .b2b-srp-catalog-wrap { flex: 1; min-width: 0; }

    /* Order panel: normalan u flow-u na desktopu */
    .b2b-srp-order-panel {
        position: sticky;
        top: calc(var(--b2b-topbar-h) + 12px);
        bottom: auto;
        left: auto;
        right: auto;
        transform: none !important;
        width: 320px;
        flex-shrink: 0;
        max-height: calc(100vh - var(--b2b-topbar-h) - 24px);
        overflow-y: auto;
        border-radius: var(--b2b-radius);
        border-bottom-left-radius: var(--b2b-radius);
        border-bottom-right-radius: var(--b2b-radius);
    }
    .b2b-srp-order-panel--open::before { display: none; }
    .b2b-srp-order-panel__inner { padding-bottom: 16px; }
    .b2b-srp-order-items { max-height: 340px; }

    /* Desktop grid: više kolona */
    .b2b-srp-product-grid-wrap {
        overflow-x: visible;
        margin: 0;
        padding: 0;
    }
    .b2b-srp-product-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        flex-direction: unset;
        flex-wrap: unset;
        width: auto;
        min-width: unset;
        gap: 14px;
    }
    .b2b-srp-product-card {
        width: auto;
        flex-shrink: unset;
    }
    :root { --b2b-card-w: auto; }

    /* Dugme uvek puna širina ispod qty - i na desktopu */
    .b2b-srp-card-actions { flex-direction: column; }
    .b2b-srp-qty-input { width: 100%; }
    .b2b-srp-btn--add { width: 100%; flex: unset; font-size: 14px; min-height: 48px; }

    .b2b-srp-customer-results { grid-template-columns: repeat(3, 1fr); }
    .b2b-srp-global-message { bottom: 24px; right: 24px; }
}

@media (min-width: 1280px) {
    .b2b-srp-product-grid { grid-template-columns: repeat(4, 1fr); }
    .b2b-srp-order-panel { width: 340px; }
}

@media (min-width: 1600px) {
    .b2b-srp-product-grid { grid-template-columns: repeat(5, 1fr); }
}
