/* =========================================================
   Mercado Familia Sastoque Giraldo
   Paleta cálida inspirada en Claude · cabecera terracota
   ========================================================= */

:root {
    --bg:          #FAF9F5;
    --panel:       #F0EEE6;
    --panel-hover: #E9E5DA;
    --card:        #FFFDF8;
    --ink:         #1F1E1C;
    --muted:       #6B6862;
    --line:        #D9D4C5;
    --accent:      #D97757;
    --accent-dark: #BE5F41;
    --accent-soft: #F6E3DA;
    --danger:      #B4543F;

    --header:      #C6603F;
    --header-2:    #B04E2F;
    --cream:       #FBF3EA;
    --cream-soft:  #F6D9CB;

    --radius:      12px;
    --shadow:      0 1px 2px rgba(31, 30, 28, .05), 0 6px 18px rgba(31, 30, 28, .05);
}

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

body {
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.55;
    padding: 10px 24px 40px;
    max-width: 1180px;
    margin: 0 auto;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Cabecera ---------- */
.topbar {
    position: sticky;
    top: 10px;
    z-index: 50;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    margin-bottom: 22px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--header), var(--header-2));
    color: var(--cream);
    box-shadow: 0 10px 28px rgba(176, 78, 47, .22);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.brand-icon {
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .18));
}

.brand-text { min-width: 0; }

.brand-text h1 {
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 500;
    font-size: clamp(1.35rem, 2.6vw, 1.85rem);
    letter-spacing: -.015em;
    line-height: 1.15;
    color: #FFF8F1;
}

.brand-text p {
    font-size: .8rem;
    color: var(--cream-soft);
    letter-spacing: .02em;
    margin-top: 2px;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* ---------- Controles ---------- */
select, input[type="text"], input[type="search"] {
    font: inherit;
    font-size: .88rem;
    padding: 9px 12px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--card);
    color: var(--ink);
    outline: none;
}
select:focus, input:focus {
    box-shadow: 0 0 0 3px rgba(251, 243, 234, .55);
}

.estado {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .74rem;
    font-weight: 600;
    padding: 6px 11px;
    border-radius: 999px;
    background: rgba(251, 243, 234, .14);
    color: var(--cream-soft);
    border: 1px solid rgba(251, 243, 234, .28);
    white-space: nowrap;
    cursor: default;
    user-select: none;
}
.estado::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    flex: 0 0 auto;
}
.estado-conectando { color: #F6D9CB; }
.estado-local      { color: #F0C9B8; }
.estado-guardando  { color: #FFE9C9; }
.estado-guardado   { color: #DCEBC8; }
.estado-error      { color: #FFD3C7; cursor: pointer; background: rgba(255, 209, 190, .2); }

.btn {
    font: inherit;
    font-size: .86rem;
    font-weight: 600;
    padding: 9px 14px;
    border-radius: 9px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, transform .05s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--cream);
    color: #8E3F24;
}
.btn-primary:hover { background: #fff; }

.btn-ghost {
    background: rgba(251, 243, 234, .12);
    color: var(--cream);
    border-color: rgba(251, 243, 234, .5);
}
.btn-ghost:hover { background: rgba(251, 243, 234, .22); }

.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-icon svg { width: 15px; height: 15px; flex: 0 0 auto; }

.sep {
    width: 1px;
    height: 22px;
    background: rgba(251, 243, 234, .35);
    margin: 0 2px;
}

.carrito-pie {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 14px;
}

.btn-undo {
    background: var(--accent-soft);
    color: var(--accent-dark);
    border-color: #EBC9BB;
}
.btn-undo:hover { background: #F1D3C6; }

.btn-danger {
    margin-top: 0;
    background: transparent;
    color: var(--danger);
    border-color: var(--line);
    align-self: flex-start;
}
.btn-danger:hover { background: #F7E9E4; border-color: var(--danger); }

/* ---------- Layout (carrito primero) ---------- */
.grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
    gap: 22px;
    align-items: start;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.panel-carrito {
    position: sticky;
    top: 112px;
    max-height: calc(100vh - 140px);
}

/* ---------- Encabezado de panel + buscador ---------- */
.panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
}

.panel-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.panel-title h2 {
    font-family: Georgia, serif;
    font-weight: 500;
    font-size: 1.18rem;
    letter-spacing: -.01em;
    white-space: nowrap;
}

.count { font-size: .76rem; color: var(--muted); white-space: nowrap; }

.buscar {
    width: 190px;
    max-width: 100%;
    font-size: .82rem;
    padding: 8px 11px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 999px;
}
.buscar::placeholder { color: #A29E94; }

.hint {
    font-size: .78rem;
    color: var(--muted);
    margin: 6px 0 14px;
}
.hint strong { color: var(--ink); font-weight: 600; }

/* ---------- Categorías (acordeón) ---------- */
.categorias {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    max-height: calc(100vh - 290px);
    padding-right: 4px;
}

.cat-group {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 4px 12px 10px;
    transition: border-color .15s, background .15s, box-shadow .15s;
}

.cat-head {
    display: flex;
    align-items: center;
    gap: 6px;
}
.cat-toggle {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 0 8px;
    background: none;
    border: none;
    border-radius: 0;
    cursor: pointer;
    font: inherit;
    color: var(--ink);
    text-align: left;
    min-width: 0;
}
.cat-toggle:hover h3 { color: var(--accent-dark); }
.cat-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 6px;
}
.cat-delete {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity .12s, color .12s, background .12s;
}
.cat-delete svg { width: 14px; height: 14px; }
.cat-group:hover .cat-delete,
.cat-delete:focus-visible { opacity: 1; pointer-events: auto; }
.cat-delete:hover { background: #F7E9E4; color: var(--danger); }

.cat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.chevron {
    width: 13px;
    height: 13px;
    flex: 0 0 auto;
    color: var(--muted);
    transition: transform .18s;
}
.colapsada .chevron { transform: rotate(-90deg); }

.cat-head h3 {
    font-size: .74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    transition: color .12s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cat-count {
    font-size: .70rem;
    color: var(--muted);
    background: var(--panel);
    border-radius: 999px;
    padding: 1px 8px;
    flex: 0 0 auto;
}

.cat-products {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-height: 34px;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
}
.cat-group.colapsada .cat-products { display: none; }

/* Durante la búsqueda las categorías se muestran siempre abiertas */
.categorias.buscando .cat-head { cursor: default; }
.categorias.buscando .chevron { opacity: .35; }

/* ---------- Producto ---------- */
.producto {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--bg);
    cursor: grab;
    user-select: none;
    font-size: .9rem;
    transition: background .12s, border-color .12s, opacity .12s;
}
.producto:hover {
    background: var(--accent-soft);
    border-color: #EBC9BB;
}
.producto.dragging { opacity: .45; cursor: grabbing; }
.producto.en-carrito { opacity: .5; }

.prod-nombre { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.prod-acciones {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 0 0 auto;
    opacity: 0;
    pointer-events: none;
    transition: opacity .12s;
}
.producto:hover .prod-acciones,
.prod-acciones:focus-within { opacity: 1; pointer-events: auto; }

.prod-mover,
.prod-eliminar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-size: .8rem;
    line-height: 1;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background .12s, color .12s;
}
.prod-eliminar svg { width: 13px; height: 13px; }
.prod-mover:hover { background: #fff; color: var(--accent-dark); }
.prod-eliminar:hover { background: #F7E9E4; color: var(--danger); }

/* Zona activa al arrastrar */
.cat-group.drop-activo {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 0 3px rgba(217, 119, 87, .15);
}
.cat-group.drop-activo .cat-products { border-top-color: var(--accent); }

/* ---------- Carrito agrupado ---------- */
.carrito-grupos {
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    flex: 1;
    min-height: 60px;
    padding: 2px;
    border-radius: 10px;
    transition: background .15s, box-shadow .15s;
}

.panel-carrito.drop-activo .carrito-grupos {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 2px var(--accent);
}

.carrito-grupo .cat-head {
    border-bottom: 1px dashed var(--line);
    margin-bottom: 6px;
}
.carrito-grupo .cat-toggle { padding: 5px 0 6px; }
.carrito-grupo .cat-count { background: var(--card); }
.carrito-grupo.colapsada .carrito-lista { display: none; }
.carrito-grupos.buscando .cat-toggle { cursor: default; }
.carrito-grupos.buscando .chevron { opacity: .35; }

.carrito-lista {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.carrito-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    background: var(--card);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: 9px;
    cursor: pointer;
    font-size: .9rem;
    transition: background .12s, border-color .12s;
}
.carrito-item:hover { background: #FFF7F2; }

.carrito-item .nombre { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.carrito-item .quitar {
    font: inherit;
    font-size: .9rem;
    line-height: 1;
    padding: 2px 6px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.carrito-item .quitar:hover { background: #F7E9E4; color: var(--danger); }

/* ---------- Estados vacíos ---------- */
.empty {
    font-size: .82rem;
    color: var(--muted);
    font-style: italic;
    padding: 10px 6px;
    list-style: none;
}

/* ---------- Modal ---------- */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(31, 30, 28, .38);
    backdrop-filter: blur(2px);
    animation: fade .12s ease-out;
}

@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.modal {
    width: 100%;
    max-width: 380px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 22px;
    box-shadow: 0 20px 50px rgba(31, 30, 28, .22);
}

.modal h3 {
    font-family: Georgia, serif;
    font-weight: 500;
    font-size: 1.12rem;
    margin-bottom: 4px;
}

.modal .modal-sub {
    font-size: .8rem;
    color: var(--muted);
    margin-bottom: 16px;
}

.modal label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    margin-bottom: 14px;
}

.modal label input,
.modal label select {
    display: block;
    width: 100%;
    margin-top: 6px;
    font-weight: 400;
    border: 1px solid var(--line);
}

.pin-error {
    font-size: .78rem;
    color: #A63D28;
    min-height: 1.1em;
    margin: -4px 0 12px;
}

.modal .acciones {
    flex-wrap: wrap;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 6px;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translate(-50%, 12px);
    background: var(--ink);
    color: #FAF9F5;
    font-size: .84rem;
    padding: 10px 16px;
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(31, 30, 28, .28);
    opacity: 0;
    transition: opacity .18s, transform .18s;
    z-index: 200;
    pointer-events: none;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Scrollbars ---------- */
.categorias::-webkit-scrollbar,
.carrito-grupos::-webkit-scrollbar { width: 8px; }
.categorias::-webkit-scrollbar-thumb,
.carrito-grupos::-webkit-scrollbar-thumb {
    background: #D5CFBF;
    border-radius: 8px;
}
.categorias::-webkit-scrollbar-track,
.carrito-grupos::-webkit-scrollbar-track { background: transparent; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    body { padding: 8px 14px 32px; }
    .grid { grid-template-columns: 1fr; }
    .panel-carrito { position: static; max-height: none; }
    .categorias { max-height: none; }
    .topbar { position: static; }
    .actions { width: 100%; }
    .actions select { flex: 1 1 100%; }
    .buscar { width: 100%; }
}

@media (max-width: 720px) {
    .estado { order: 3; flex: 1 1 100%; justify-content: center; }
}

@media (max-width: 620px) {
    .btn-icon .btn-label { display: none; }
    .btn-icon { padding: 9px 11px; }
}

@media (hover: none) {
    .prod-acciones { opacity: 1; pointer-events: auto; }
    .cat-delete { opacity: 1; pointer-events: auto; }
}

@media (max-width: 480px) {
    .brand-icon { width: 38px; height: 38px; }
    .topbar { padding: 14px; border-radius: 14px; }
    .actions .btn { flex: 1 1 auto; justify-content: center; }
}
