:root {
    --brand: #ED351F;
    --brand-dark: #c42a18;
    --brand-light: #fef0ee;
    --brand-ring: rgba(237, 53, 31, 0.18);
    --bg: #f3f4f6;
    --surface: #ffffff;
    --text: #111827;
    --text-secondary: #374151;
    --muted: #6b7280;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 4px 16px rgba(17,24,39,.08);
    --shadow-lg: 0 20px 48px rgba(17,24,39,.12);
    --radius: 12px;
    --radius-sm: 8px;
    --header-h: 72px;
    --font-body: 'Open Sans', system-ui, sans-serif;
    --font-display: 'Rubik', 'Open Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3,
.brand-tag,
.content-header h1,
.modal-header h2,
.detail-meta h2,
.product-card h3,
.product-card .cat-tag,
.catalog-item .name,
.btn {
    font-family: var(--font-display);
}

/* ── Header ── */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 1480px;
    margin: 0 auto;
    padding: 0 24px;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    flex-shrink: 0;
    padding-right: 8px;
}

.brand-logo {
    height: 40px;
    width: auto;
    display: block;
}

.brand-tag {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    padding-left: 12px;
    border-left: 1px solid var(--border);
    white-space: nowrap;
}

.nav-categories {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 1;
    padding: 4px 0;
}

.nav-categories::-webkit-scrollbar { display: none; }

.nav-categories button {
    border: 1px solid var(--border);
    background: var(--surface);
    padding: 7px 16px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all .18s ease;
    white-space: nowrap;
    font-family: inherit;
}

.nav-categories button:hover {
    border-color: var(--brand);
    color: var(--brand);
    background: var(--brand-light);
}

.nav-categories button.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    box-shadow: 0 2px 8px rgba(237,53,31,.25);
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.search-box {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--muted);
    pointer-events: none;
}

.search-box input {
    width: 260px;
    padding: 10px 14px 10px 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--bg);
    transition: border-color .15s, box-shadow .15s, background .15s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--brand);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all .15s ease;
    font-family: inherit;
    white-space: nowrap;
}

.btn-primary {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 2px 6px rgba(237,53,31,.2);
}

.btn-primary:hover {
    background: var(--brand-dark);
    box-shadow: 0 4px 12px rgba(237,53,31,.3);
}

.btn-outline {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--brand);
    color: var(--brand);
    background: var(--brand-light);
}

.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-link {
    background: none;
    border: none;
    color: var(--brand);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    padding: 4px 0;
}

.btn-link:hover { text-decoration: underline; }

.btn-icon {
    display: none;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.badge {
    background: rgba(255,255,255,.25);
    color: inherit;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    min-width: 20px;
    text-align: center;
}

.btn-primary .badge {
    background: rgba(255,255,255,.3);
}

.btn-catalog .badge {
    background: rgba(255,255,255,.3);
    color: #fff;
}

/* ── Layout ── */
.main {
    max-width: 1480px;
    margin: 0 auto;
    padding: 24px;
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 24px;
    align-items: start;
}

.sidebar {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
    position: sticky;
    top: calc(var(--header-h) + 16px);
    max-height: calc(100vh - var(--header-h) - 32px);
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.sidebar-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--brand-light);
    color: var(--brand-dark);
    border: 1px solid rgba(237,53,31,.2);
    border-radius: 999px;
    padding: 4px 8px 4px 12px;
    font-size: 12px;
    font-weight: 500;
    max-width: 100%;
}

.filter-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-chip button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--brand);
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
    flex-shrink: 0;
}

.filter-group {
    margin-bottom: 18px;
}

.filter-group:last-child { margin-bottom: 0; }

.filter-group label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 8px;
}

.filter-group label .filter-count {
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    color: var(--brand);
    font-size: 11px;
}

.filter-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.filter-group select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

.filter-group select.has-value {
    border-color: var(--brand);
    background-color: var(--brand-light);
    color: var(--brand-dark);
    font-weight: 600;
}

.empty-hint, .muted {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

.filters-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    padding: 8px 0;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Content ── */
.content-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 20px;
    gap: 16px;
}

.content-header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -.02em;
}

.subtitle {
    color: var(--muted);
    font-size: 14px;
    margin-top: 4px;
}

.result-info {
    font-size: 13px;
    font-weight: 600;
    color: var(--brand);
    background: var(--brand-light);
    padding: 6px 14px;
    border-radius: 999px;
    white-space: nowrap;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.product-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow .2s, transform .2s, border-color .2s;
    display: flex;
    flex-direction: column;
}

.product-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-3px);
    border-color: rgba(237,53,31,.25);
}

.product-card .img-wrap {
    height: 170px;
    background: linear-gradient(160deg, #fafafa 0%, #f3f4f6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-bottom: 1px solid var(--border-light);
}

.product-card img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    transition: transform .25s ease;
}

.product-card:hover img { transform: scale(1.04); }

.product-card .no-img { color: #d1d5db; font-size: 36px; }

.product-card .card-body {
    padding: 14px 16px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.product-card .cat-tag {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--brand);
    font-weight: 700;
    letter-spacing: .06em;
}

.product-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 5px 0 4px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text);
}

.product-card .ref {
    font-size: 11px;
    color: var(--muted);
    font-weight: 500;
}

.product-card .desc {
    font-size: 12px;
    color: var(--muted);
    margin-top: 8px;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.45;
}

.card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.card-actions .btn { flex: 1; justify-content: center; }

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 32px;
}

.pagination button {
    min-width: 38px;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-secondary);
    transition: all .15s;
}

.pagination button:hover:not(:disabled) {
    border-color: var(--brand);
    color: var(--brand);
}

.pagination button.active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

.pagination button:disabled { opacity: .35; cursor: not-allowed; }

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 64px 24px;
    color: var(--muted);
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px dashed var(--border);
}

.empty-state strong {
    display: block;
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

/* ── Modals ── */
.modal[hidden], .sidebar-backdrop[hidden] { display: none; }

.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 32px 20px;
    overflow-y: auto;
}

.modal-backdrop, .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(17,24,39,.5);
    backdrop-filter: blur(2px);
}

.sidebar-backdrop { z-index: 90; }

.modal-panel {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-lg { max-width: 920px; }
.modal-md { max-width: 560px; }
.modal-catalog { max-width: 720px; }

.modal-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: var(--bg);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 22px;
    cursor: pointer;
    color: var(--muted);
    z-index: 1;
    display: grid;
    place-items: center;
    transition: background .15s, color .15s;
}

.modal-close:hover { background: var(--brand-light); color: var(--brand); }

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 { font-size: 18px; font-weight: 700; }

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    border-radius: 0 0 var(--radius) var(--radius);
}

.field-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}

.modal-footer input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 14px;
    font-family: inherit;
}

.modal-footer input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.product-detail {
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    gap: 28px;
    padding: 28px;
}

.product-detail .detail-img {
    background: linear-gradient(160deg, #fafafa, #f3f4f6);
    border-radius: var(--radius);
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-light);
}

.product-detail .detail-img img {
    max-width: 100%;
    max-height: 340px;
    object-fit: contain;
}

.detail-meta h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.25;
}

.detail-meta .ref {
    color: var(--muted);
    font-size: 13px;
    margin: 8px 0 14px;
}

.detail-meta .desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.6;
}

.detail-meta h4 {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    margin-bottom: 8px;
}

.attrs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.attrs-table th, .attrs-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-light);
    text-align: left;
}

.attrs-table th {
    width: 38%;
    color: var(--muted);
    font-weight: 500;
    background: var(--bg);
}

.attrs-table tr:last-child th,
.attrs-table tr:last-child td { border-bottom: none; }

.detail-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.catalog-list {
    padding: 8px 24px 16px;
    max-height: 280px;
    overflow-y: auto;
}

.catalog-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
    gap: 12px;
}

.catalog-item:last-child { border-bottom: none; }
.catalog-item .name { font-size: 13px; font-weight: 600; flex: 1; }
.catalog-item .ref { font-size: 11px; color: var(--muted); margin-top: 2px; }

.catalog-footer {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.catalog-modes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.catalog-mode-card {
    text-align: left;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s, background .15s;
    font-family: var(--font-body);
}

.catalog-mode-card strong {
    display: block;
    font-family: var(--font-display);
    font-size: 14px;
    color: var(--text);
    margin-bottom: 4px;
}

.catalog-mode-card span {
    display: block;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.35;
}

.catalog-mode-card:hover {
    border-color: var(--brand);
}

.catalog-mode-card.is-active {
    border-color: var(--brand);
    background: var(--brand-light);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

.presupuesto-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.presupuesto-table-wrap {
    max-height: 240px;
    overflow: auto;
}

.presupuesto-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.presupuesto-table th,
.presupuesto-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    text-align: left;
    vertical-align: middle;
}

.presupuesto-table th {
    background: var(--bg);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    position: sticky;
    top: 0;
    z-index: 1;
}

.presupuesto-table th:nth-child(2),
.presupuesto-table td:nth-child(2),
.presupuesto-table th:nth-child(3),
.presupuesto-table td:nth-child(3),
.presupuesto-table th:nth-child(4),
.presupuesto-table td:nth-child(4) {
    text-align: right;
    white-space: nowrap;
}

.presupuesto-table .prod-name {
    font-weight: 600;
    font-size: 13px;
}

.presupuesto-table .prod-ref {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.presupuesto-table input {
    width: 88px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    text-align: right;
}

.presupuesto-table input.qty {
    width: 64px;
}

.presupuesto-table tfoot td {
    font-weight: 700;
    background: var(--brand-light);
    border-bottom: none;
}

@media (max-width: 720px) {
    .catalog-modes { grid-template-columns: 1fr; }
}

.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    background: var(--text);
    color: #fff;
    padding: 14px 22px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    z-index: 300;
    box-shadow: var(--shadow-lg);
    animation: slideUp .25s ease;
}

.toast[hidden] { display: none; }

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ── */
@media (max-width: 1024px) {
    .brand-tag { display: none; }
    .search-box input { width: 200px; }
}

@media (max-width: 900px) {
    .main { grid-template-columns: 1fr; padding: 16px; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(320px, 88vw);
        max-height: none;
        z-index: 95;
        border-radius: 0;
        transform: translateX(-110%);
        transition: transform .28s ease;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open { transform: translateX(0); }

    .btn-icon { display: inline-flex; }
    .search-box input { width: 160px; }
    .product-detail { grid-template-columns: 1fr; padding: 20px; }
    .header-inner { padding: 0 16px; gap: 12px; }
    .nav-categories { display: none; }
}

@media (max-width: 520px) {
    .search-box { display: none; }
    .btn-catalog span:not(.badge) { display: none; }
    .products-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .product-card .img-wrap { height: 130px; }
    .product-card .card-body { padding: 10px 12px 12px; }
    .product-card h3 { font-size: 12px; }
    .card-actions { flex-direction: column; }
}
