:root {
    --purple: #8732a0;
    --purple-dark: #5b1fc2;
    --dark: #14141c;
    --navy: #2b2b38;
    --green: #2fbf71;
    --orange: #f0a13a;
    --bg: #f4f4f7;
    --border: #e2e2ea;
    --text: #1c1c26;
    --muted: #767688;
}

.calc-page {
    font-family: 'Segoe UI',Arial,sans-serif;
    color: var(--text);
}

.note {
    max-width: 1200px;
    margin: 0 auto 18px auto;
    background: #fff8e6;
    border: 1px solid #f0d98c;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 13px;
    color: #6b5b1e;
}

.app {
    max-width: 1200px;
    margin: 0 auto;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,.08);
}

.topbar {
    background: linear-gradient(120deg,var(--navy),var(--dark));
    padding: 16px 28px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
}

    .topbar .brand {
        font-size: 13px;
        font-weight: 700;
        letter-spacing: .04em;
        color: #fff;
    }

    .topbar .brand-sep {
        color: #5a5a6b;
    }

    .topbar .brand-sub {
        font-size: 13px;
        color: #b9b9c8;
    }

.panel-title {
    padding: 24px 28px 6px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

    .panel-title h1 {
        margin: 0;
        font-size: 20px;
        color: #8732a0;
        font-weight: 700;
    }

.btn-add {
    background: #8732a0;
    color: #fff;
    border: none;
    padding: 9px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

    .btn-add:hover {
        background: #6e2882;
    }

.table-scroll {
    overflow-x: auto;
    padding: 0 28px 24px 28px;
}

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

.calc-page thead tr {
    background: #000000;
    color: #fff;
}

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

#pedidosTable {
    font-size: 12px;
    width: 100%;
}

    #pedidosTable tbody tr:hover {
        background: #faf8ff;
    }

.code-pill {
    background: #8732a0;
    color: #fff;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

#calculadoraModal .modal-content {
    height: 90vh;
}

#calculadoraModal .modal-body {
    display: flex;
    flex-direction: column;
}

#calculadoraModal .app {
    max-width: none;
    width: 100%;
}

#calculadoraModal .table-scroll {
    overflow-x: auto;
    overflow-y: visible;
    padding: 0 12px 20px 12px;
}

#calculadoraModal .modal-body {
    overflow: visible;
}

#calculadoraModal .modal-footer .btn-secondary {
    background-color: #8732a0;
    border-color: #8732a0;
    color: #fff;
}

    #calculadoraModal .modal-footer .btn-secondary:hover {
        background-color: #6e2882;
        border-color: #6e2882;
    }

/* Estado badges (ancladas a #calculadoraModal para ganar siempre frente a
   otro .badge del sitio, sin depender del orden de carga de los CSS) */
#calculadoraModal .badge {
    font-size: 10.5px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 12px;
    display: inline-block;
    white-space: nowrap;
}

#calculadoraModal .badge-pendiente {
    background: #fdf1de;
    color: var(--orange);
}

#calculadoraModal .badge-calculado {
    background: #e4f7ec;
    color: #1c8a4d;
}

.icon-btn {
    border: none;
    background: #f1f1f6;
    padding: 0 8px;
    height: 26px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    margin-right: 4px;
    font-weight: 600;
    color: #333;
}

    .icon-btn:hover {
        background: #e4e4ee;
    }

    .icon-btn.danger {
        color: #c0392b;
    }

        .icon-btn.danger:hover {
            background: #fbe3e3;
        }

    .icon-btn.primary {
        background: #8732a0;
        color: #fff;
    }

        .icon-btn.primary:hover {
            background: #6e2882;
        }

    .icon-btn:disabled {
        opacity: .4;
        cursor: not-allowed;
    }

.empty-cart {
    padding: 40px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

/* Inline editable cell inputs */
#pedidosTable input, #pedidosTable select {
    width: 100%;
    padding: 5px 6px;
    border: 1px solid #D9D9D6;
    border-radius: 5px;
    font-size: 12px;
    background: #fff;
    font-family: inherit;
}

    #pedidosTable input:focus, #pedidosTable select:focus {
        outline: none;
        border-color: var(--purple);
        background: #fff;
    }

    #pedidosTable select:disabled {
        background: #f1f1f4;
        color: #aaa;
        cursor: not-allowed;
        border-style: dashed;
    }

.cell-muted {
    color: var(--muted);
}

.cell-desc {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Buscador de código (autocompletar en línea) */
.code-cell {
    position: relative;
    min-width: 250px;
}

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

    .code-search-wrap input {
        flex: 1;
        min-width: 0;
    }

.icon-search-btn {
    border: 1px solid var(--border);
    background: #fbfbfd;
    width: 30px;
    height: 28px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

    .icon-search-btn:hover {
        background: #f1f1f6;
        border-color: var(--purple);
    }

.autocomplete-list {
    display: none;
    position: fixed; /* posición real la calcula JS (ver posicionarListaAutocomplete) */
    margin-top: 2px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    max-height: 230px;
    overflow-y: auto;
    box-shadow: 0 8px 20px rgba(0,0,0,.14);
    z-index: 1070; /* por encima del modal (1050) y del buscador anidado (1060) */
}

.ac-item {
    padding: 7px 10px;
    cursor: pointer;
    font-size: 12px;
    border-bottom: 1px solid #f1f1f6;
}

    .ac-item:last-child {
        border-bottom: none;
    }

    .ac-item:hover, .ac-item.hl {
        background: #f5f2ff;
    }

.ac-code {
    font-weight: 700;
    color: var(--purple);
    margin-right: 6px;
}

.ac-desc {
    color: var(--text);
}

.ac-empty, .ac-hint {
    padding: 8px 10px;
    font-size: 12px;
    color: var(--muted);
}

.desglose-row td {
    background: #f7f5ff;
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
}

.desglose-box {
    background: #fff;
    border: 1px solid #e3dbfa;
    border-radius: 8px;
    padding: 12px 16px;
    max-width: 460px;
}

    .desglose-box .titulo {
        font-size: 11px;
        font-weight: 700;
        color: var(--purple);
        text-transform: uppercase;
        margin-bottom: 8px;
        letter-spacing: .03em;
    }

.desglose-line {
    display: flex;
    justify-content: space-between;
    font-size: 12.5px;
    padding: 3px 0;
}

    .desglose-line.total {
        border-top: 1px solid var(--border);
        margin-top: 6px;
        padding-top: 8px;
        font-weight: 700;
    }

    .desglose-line .muted {
        color: var(--muted);
    }

/* Ventana modal de búsqueda con filtros */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20,20,28,.5);
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

    .modal-overlay.open {
        display: flex;
    }

.modal-box {
    background: #fff;
    border-radius: 10px;
    width: 580px;
    max-width: 92vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0,0,0,.25);
}

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

    .modal-header h2 {
        margin: 0;
        font-size: 16px;
        color: var(--purple);
    }

.modal-close {
    border: none;
    background: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    padding: 0;
}

    .modal-close:hover {
        color: var(--text);
    }

.modal-filters {
    display: flex;
    gap: 8px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}

    .modal-filters input {
        flex: 1;
        padding: 8px 10px;
        border: 1px solid var(--border);
        border-radius: 6px;
        font-size: 13px;
        font-family: inherit;
    }

    .modal-filters select {
        padding: 8px 10px;
        border: 1px solid var(--border);
        border-radius: 6px;
        font-size: 13px;
        font-family: inherit;
    }

        .modal-filters input:focus, .modal-filters select:focus {
            outline: none;
            border-color: var(--purple);
        }

.modal-results {
    overflow-y: auto;
    padding: 6px 0;
}

.modal-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    cursor: pointer;
    border-bottom: 1px solid #f4f4f7;
}

    .modal-result-item:hover {
        background: #f5f2ff;
    }

    .modal-result-item .mr-code {
        font-weight: 700;
        color: var(--purple);
        min-width: 92px;
        font-size: 12.5px;
    }

    .modal-result-item .mr-desc {
        flex: 1;
        font-size: 13px;
    }

    .modal-result-item .mr-tipo {
        font-size: 10.5px;
        padding: 2px 9px;
        border-radius: 10px;
        background: #eee;
        color: #666;
        white-space: nowrap;
    }

    .modal-result-item .mr-precio {
        font-size: 12px;
        color: var(--muted);
        white-space: nowrap;
        min-width: 80px;
        text-align: right;
    }

.modal-empty {
    padding: 26px 20px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

.modal-footer {
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--muted);
}
