/* =====================================================================
   Components — buttons, cards, forms, badges, price ranges
   + Product grid / card (2-per-row on phone)
   ===================================================================== */

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 0.625rem 1.125rem;
    font-family: inherit;
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    line-height: 1.2;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: all var(--dur-fast) var(--ease-out);
    user-select: none;
}

.btn:disabled,
.btn.disabled {
    opacity: .5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: var(--brand-500);
    color: #fff;
    border-color: var(--brand-500);
}

.btn-primary:hover {
    background: var(--brand-600);
    border-color: var(--brand-600);
    color: #fff;
    box-shadow: 0 6px 20px rgba(232, 110, 15, .25);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-dark {
    background: var(--ink-900);
    color: #fff;
}

.btn-dark:hover {
    background: var(--ink-700);
    color: #fff;
}

.btn-outline {
    background: transparent;
    color: var(--ink-800);
    border-color: var(--ink-200);
}

.btn-outline:hover {
    border-color: var(--brand-500);
    color: var(--brand-600);
    background: var(--brand-50);
}

.btn-ghost {
    background: transparent;
    color: var(--ink-600);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--ink-50);
    color: var(--ink-900);
}

.btn-danger {
    background: var(--danger-500);
    color: #fff;
}

.btn-danger:hover {
    background: var(--danger-700);
    color: #fff;
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: var(--fs-xs);
}

.btn-lg {
    padding: 0.85rem 1.5rem;
    font-size: var(--fs-base);
}

.btn-block {
    width: 100%;
}

.btn-icon {
    padding: 0;
    width: 40px;
    height: 40px;
    border-radius: var(--r-sm);
}

/* Loading state */
.btn.is-loading {
    color: transparent !important;
    pointer-events: none;
    position: relative;
}

.btn.is-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, .4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

.btn-outline.is-loading::after,
.btn-ghost.is-loading::after {
    border: 2px solid var(--ink-200);
    border-top-color: var(--brand-500);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Cards ── */
.card {
    background: var(--paper);
    border: 1px solid var(--ink-100);
    border-radius: var(--r-md);
    padding: var(--sp-5);
    transition: box-shadow var(--dur-base) var(--ease-out),
        border-color var(--dur-base) var(--ease-out),
        transform var(--dur-base) var(--ease-out);
}

.card-hover:hover {
    border-color: var(--brand-100);
    box-shadow: var(--shadow-3);
    transform: translateY(-2px);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding-bottom: var(--sp-4);
    margin-bottom: var(--sp-4);
    border-bottom: 1px solid var(--ink-50);
}

.card-title {
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
    margin: 0;
}

/* ── KPI card ── */
.kpi-card {
    background: var(--paper);
    border: 1px solid var(--ink-100);
    border-radius: var(--r-md);
    padding: var(--sp-5);
    transition: border-color var(--dur-base);
}

.kpi-card:hover {
    border-color: var(--brand-100);
}

.kpi-label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    color: var(--ink-400);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: var(--sp-2);
}

.kpi-value {
    font-size: var(--fs-3xl);
    font-weight: var(--fw-extrabold);
    color: var(--ink-900);
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--r-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-50);
    color: var(--brand-500);
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* ── Price Range Display (THE KEY FIX) ── */
.price-range {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: var(--sp-1);
    font-family: var(--font-sans);
    font-weight: var(--fw-bold);
    color: var(--brand-600);
    letter-spacing: -0.02em;
}

.price-range .price-min {
    font-size: var(--fs-xl);
    line-height: 1;
}

.price-range .price-sep {
    font-size: var(--fs-sm);
    color: var(--ink-400);
    margin-inline: 2px;
    font-weight: var(--fw-medium);
}

.price-range .price-max {
    font-size: var(--fs-xl);
    line-height: 1;
}

.price-range--sm .price-min,
.price-range--sm .price-max {
    font-size: var(--fs-lg);
}

.price-range--lg .price-min,
.price-range--lg .price-max {
    font-size: var(--fs-3xl);
}

.price-range--on-dark .price-min,
.price-range--on-dark .price-max {
    color: #fff;
}

.price-range--on-dark .price-sep {
    color: rgba(255, 255, 255, .55);
}

.price-note {
    display: block;
    font-size: var(--fs-xs);
    color: var(--ink-400);
    font-weight: var(--fw-normal);
    margin-top: var(--sp-1);
}

/* ── Tables (mobile-safe) ── */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--r-md);
    border: 1px solid var(--ink-100);
    background: var(--paper);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
    min-width: 640px;
}

.table thead {
    background: var(--ink-50);
}

.table th {
    text-align: left;
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-500);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--ink-100);
    white-space: nowrap;
}

.table td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--ink-50);
    color: var(--ink-700);
    vertical-align: middle;
}

.table tbody tr:last-child td {
    border-bottom: 0;
}

.table tbody tr:hover {
    background: var(--paper-2);
}

/* ── Forms ── */
.form-group {
    margin-bottom: var(--sp-4);
}

.form-label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--ink-700);
    margin-bottom: var(--sp-2);
}

.form-label.required::after {
    content: " *";
    color: var(--danger-500);
}

.form-control,
.form-select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-family: inherit;
    font-size: var(--fs-sm);
    color: var(--ink-800);
    background: #fff;
    border: 1px solid var(--ink-200);
    border-radius: var(--r-sm);
    transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus,
.form-select:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px var(--brand-50);
}

.form-control.is-invalid,
.form-select.is-invalid {
    border-color: var(--danger-500);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

.form-error {
    font-size: var(--fs-xs);
    color: var(--danger-500);
    margin-top: var(--sp-1);
}

.form-help {
    font-size: var(--fs-xs);
    color: var(--ink-400);
    margin-top: var(--sp-1);
}

/* Select arrow */
.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px;
    padding-right: 2.5rem;
}

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--r-full);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    white-space: nowrap;
    line-height: 1.4;
}

.badge-success {
    background: var(--success-50);
    color: var(--success-700);
}

.badge-warning {
    background: var(--warning-50);
    color: var(--warning-700);
}

.badge-danger {
    background: var(--danger-50);
    color: var(--danger-700);
}

.badge-info {
    background: var(--info-50);
    color: var(--info-700);
}

.badge-neutral {
    background: var(--ink-50);
    color: var(--ink-600);
}

.badge-primary {
    background: var(--brand-50);
    color: var(--brand-700);
}

/* ── Alerts ── */
.alert {
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-sm);
    border: 1px solid;
    font-size: var(--fs-sm);
    margin-bottom: var(--sp-4);
}

.alert-success {
    background: var(--success-50);
    color: var(--success-700);
    border-color: #BBF7D0;
}

.alert-warning {
    background: var(--warning-50);
    color: var(--warning-700);
    border-color: #FDE68A;
}

.alert-danger {
    background: var(--danger-50);
    color: var(--danger-700);
    border-color: #FECACA;
}

.alert-info {
    background: var(--info-50);
    color: var(--info-700);
    border-color: #BFDBFE;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: calc(var(--header-h) + var(--sp-4));
    right: var(--sp-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    pointer-events: none;
    max-width: 360px;
}

.toast {
    background: var(--ink-900);
    color: #fff;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-sm);
    box-shadow: var(--shadow-4);
    font-size: var(--fs-sm);
    pointer-events: auto;
    animation: toastIn var(--dur-base) var(--ease-out);
}

.toast.success {
    background: var(--success-500);
}

.toast.error {
    background: var(--danger-500);
}

.toast.warning {
    background: var(--warning-500);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ── Pagination ── */
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-1);
    justify-content: center;
    margin-top: var(--sp-8);
    list-style: none;
    padding: 0;
}

.pagination a,
.pagination span {
    min-width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding-inline: var(--sp-2);
    border: 1px solid var(--ink-100);
    border-radius: var(--r-sm);
    font-size: var(--fs-sm);
    color: var(--ink-700);
}

.pagination a:hover {
    border-color: var(--brand-500);
    color: var(--brand-500);
    background: var(--brand-50);
}

.pagination .active {
    background: var(--brand-500);
    color: #fff;
    border-color: var(--brand-500);
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: var(--sp-16) var(--sp-4);
    color: var(--ink-400);
}

.empty-state h3 {
    color: var(--ink-800);
    font-size: var(--fs-xl);
    margin-bottom: var(--sp-2);
}


/* =====================================================================
   PRODUCT GRID + PRODUCT CARD  —  2 per row on phone
   ===================================================================== */

/* ── Grid wrapper: EXACTLY 2 per row on phone ── */
.product-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    list-style: none;
    margin: 0 auto;
}

/* ── The card ── */
.product-card {
    display: flex;
    flex-direction: column;
    background: var(--paper);
    border: 1px solid var(--ink-100);
    border-radius: var(--r-md);
    overflow: hidden;
    min-width: 0;
    box-sizing: border-box;
    transition: box-shadow var(--dur-base) var(--ease-out),
        transform var(--dur-base) var(--ease-out);
    -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
    .product-card:hover {
        box-shadow: 0 6px 18px rgba(0, 0, 0, .08);
        transform: translateY(-2px);
    }
}

/* ── Image area: square, cover ── */
.product-card-image {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--ink-50);
    overflow: hidden;
    text-decoration: none;
}

.product-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.product-card-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.6rem, 8vw, 2.5rem);
    color: var(--ink-300);
    user-select: none;
}

/* ── Badge: small + repositioned so it never overlaps at 2-up ── */
.product-card-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    font-size: 10px;
    line-height: 1;
    padding: 3px 6px;
    border-radius: var(--r-full);
    background: var(--brand-500);
    color: #fff;
    font-weight: var(--fw-semibold);
    letter-spacing: .02em;
    white-space: nowrap;
}

/* ── Body ── */
.product-card-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 9px 10px;
    flex: 1;
    min-width: 0;
}

.product-card-category {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-400);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-card-title {
    font-size: 13px;
    line-height: 1.3;
    margin: 0;
    font-weight: var(--fw-semibold);
    color: var(--ink-900);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.6em;
    word-break: break-word;
}

.product-card-title a {
    color: inherit;
    text-decoration: none;
}

.product-card-desc {
    font-size: 11px;
    line-height: 1.35;
    color: var(--ink-500);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── Footer: price + CTA ── */
.product-card-footer {
    margin-top: auto;
    padding-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

/* ── Price: shrink inside card (base .price-range is too big) ── */
.product-card .price-range,
.product-card .price-range--sm {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 2px;
    min-width: 0;
    font-weight: var(--fw-bold);
    line-height: 1.15;
    color: var(--brand-600);
}

.product-card .price-range--sm .price-min,
.product-card .price-range--sm .price-max {
    font-size: 13px;
}

.product-card .price-range--sm .price-sep {
    font-size: 11px;
    color: var(--ink-400);
    font-weight: var(--fw-normal);
}

.product-card .price-range .price-contact {
    font-size: 11px;
    color: var(--ink-400);
    font-weight: var(--fw-medium);
}

/* ── CTA button: full width on narrow 2-up cards ── */
.product-card .product-card-cta,
.product-card .btn.btn-sm.product-card-cta {
    width: 100%;
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: var(--fw-semibold);
    border-radius: var(--r-sm);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    gap: 4px;
}

/* ══════════════════════════════════════════════════════════════
   Breakpoints
   ══════════════════════════════════════════════════════════════ */

/* Tiny phones (≤360px) */
@media (max-width: 360px) {
    .product-grid {
        gap: 8px;
        padding: 8px;
    }

    .product-card-title {
        font-size: 12px;
    }

    .product-card .price-range--sm .price-min,
    .product-card .price-range--sm .price-max {
        font-size: 12px;
    }
}

/* From 480px: footer side-by-side (price left, button right) */
@media (min-width: 480px) {
    .product-card-footer {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 6px;
    }

    .product-card .product-card-cta,
    .product-card .btn.btn-sm.product-card-cta {
        width: auto;
        flex-shrink: 0;
    }
}

/* Tablet portrait */
@media (min-width: 640px) {
    .product-grid {
        gap: 14px;
        padding: 14px;
    }

    .product-card-title {
        font-size: 14px;
    }

    .product-card-desc {
        font-size: 12px;
    }

    .product-card .price-range--sm .price-min,
    .product-card .price-range--sm .price-max {
        font-size: 15px;
    }
}

/* Small desktop */
@media (min-width: 900px) {
    .product-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 18px;
        padding: 18px;
    }
}

/* Desktop */
@media (min-width: 1200px) {
    .product-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 22px;
        padding: 22px;
    }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .product-card {
        transition: none;
    }

    .product-card:hover {
        transform: none;
    }
}
