/* ============================================
   CONTROL DE RIFA — ESTILOS PÚBLICOS
   ============================================ */

.cr-board, .cr-board * {
    box-sizing: border-box;
}

.cr-board {
    --cr-green:       #1D9E75;
    --cr-green-dark:  #0F6E56;
    --cr-green-light: #E1F5EE;
    --cr-green-mid:   #9FE1CB;
    --cr-blue:        #378ADD;
    --cr-blue-dark:   #2569AC;
    --cr-blue-light:  #E6F1FB;
    --cr-amber:       #EF9F27;
    --cr-amber-dark:  #BA7517;
    --cr-amber-light: #FAEEDA;
    --cr-red:         #E24B4A;
    --cr-red-light:   #FCEBEB;
    --cr-whatsapp:    #25D366;
    --cr-whatsapp-dark: #1DA851;
    --cr-gray-50:     #F7F6F3;
    --cr-gray-100:    #EEECE7;
    --cr-gray-200:    #D4D2CB;
    --cr-gray-400:    #9B9991;
    --cr-gray-600:    #5F5D57;
    --cr-gray-800:    #2E2D2B;
    --cr-white:       #FFFFFF;
    --cr-radius-sm:   6px;
    --cr-radius-md:   10px;
    --cr-radius-lg:   16px;
    --cr-shadow-sm:   0 1px 4px rgba(0,0,0,0.07);
    --cr-shadow-md:   0 4px 16px rgba(0,0,0,0.10);

    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--cr-gray-800);
    font-size: 14px;
    line-height: 1.5;
    max-width: 1300px;
    margin: 0 auto;
    width: 100%;
}

.cr-public-header {
    background: var(--cr-white);
    border: 1px solid var(--cr-gray-100);
    border-radius: var(--cr-radius-lg);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--cr-shadow-sm);
}
.cr-public-title { font-size: 22px; font-weight: 700; margin: 0 0 6px; color: var(--cr-gray-800); word-break: break-word; }
.cr-public-desc { font-size: 14px; color: var(--cr-gray-600); margin: 0 0 10px; }
.cr-public-meta { display: flex; gap: 10px; flex-wrap: wrap; }
.cr-public-badge {
    background: var(--cr-gray-50);
    border: 1px solid var(--cr-gray-200);
    padding: 5px 12px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
    color: var(--cr-gray-600);
}

.cr-public-error {
    background: var(--cr-red-light);
    color: var(--cr-red);
    padding: 1rem;
    border-radius: var(--cr-radius-md);
    font-weight: 600;
}

/* ── STATS BAR ── */
.cr-stats-bar {
    background: var(--cr-green);
    border-radius: var(--cr-radius-lg);
    padding: 0 1.5rem;
    display: flex;
    align-items: stretch;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.cr-stat-item {
    padding: 14px 22px;
    border-right: 1px solid rgba(255,255,255,0.15);
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.cr-stat-item:last-of-type { border-right: none; }
.cr-stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.65); font-weight: 600; }
.cr-stat-value { font-size: 22px; font-weight: 700; color: var(--cr-white); letter-spacing: -.5px; }
.cr-stat-sub { font-size: 11px; color: rgba(255,255,255,.55); }
.cr-progress-wrap { flex: 1; min-width: 200px; display: flex; flex-direction: column; justify-content: center; padding: 14px 22px; gap: 4px; }
.cr-progress-label { display: flex; justify-content: space-between; font-size: 11px; color: rgba(255,255,255,.7); }
.cr-progress-bar { height: 8px; background: rgba(255,255,255,.2); border-radius: 99px; overflow: hidden; }
.cr-progress-fill { height: 100%; background: var(--cr-white); border-radius: 99px; transition: width .3s ease; }

/* ── CARD ── */
.cr-card {
    background: var(--cr-white);
    border-radius: var(--cr-radius-lg);
    border: 1px solid var(--cr-gray-100);
    box-shadow: var(--cr-shadow-sm);
    overflow: hidden;
    margin-bottom: 1.25rem;
}
.cr-card-header {
    padding: 1rem 1.25rem .75rem;
    border-bottom: 1px solid var(--cr-gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.cr-card-title { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.cr-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cr-green); display: inline-block; flex-shrink: 0; }

/* ── CONTROLS ── */
.cr-controls-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; width: 100%; }
.cr-search-box, .cr-tbl-search-box { position: relative; flex: 1; min-width: 160px; }
.cr-search-box input, .cr-tbl-search-box input {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--cr-gray-200);
    border-radius: var(--cr-radius-sm);
    font-size: 13px;
    outline: none;
    color: var(--cr-gray-800);
    background: var(--cr-white);
}
.cr-search-box input:focus, .cr-tbl-search-box input:focus { border-color: var(--cr-green); }

.cr-btn {
    padding: 9px 14px;
    border-radius: var(--cr-radius-sm);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--cr-gray-200);
    background: var(--cr-white);
    color: var(--cr-gray-600);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all .12s;
    white-space: nowrap;
    min-height: 38px;
}
.cr-btn:hover { background: var(--cr-gray-50); border-color: var(--cr-gray-400); color: var(--cr-gray-800); }
.cr-btn.active { background: var(--cr-green-light); border-color: var(--cr-green-mid); color: var(--cr-green-dark); font-weight: 600; }
.cr-btn-green { background: var(--cr-green); border-color: var(--cr-green-dark); color: var(--cr-white); font-weight: 600; }
.cr-btn-green:hover { background: var(--cr-green-dark); color: var(--cr-white); }
.cr-btn-red { color: var(--cr-red); border-color: #F09595; }
.cr-btn-red:hover { background: var(--cr-red-light); }
.cr-btn-amber { color: var(--cr-amber-dark); border-color: #FAC775; }
.cr-btn-amber:hover { background: var(--cr-amber-light); }
.cr-btn-sm { min-height: 32px; padding: 6px 12px; font-size: 12px; }
.cr-btn-link { background: transparent; border: none; color: var(--cr-blue); text-decoration: underline; min-height: auto; padding: 6px; }
.cr-btn-link:hover { background: transparent; color: var(--cr-blue-dark); }
.cr-btn:disabled { opacity: .5; cursor: not-allowed; }

.cr-btn-whatsapp {
    background: var(--cr-whatsapp);
    border-color: var(--cr-whatsapp-dark);
    color: var(--cr-white);
    font-weight: 700;
    font-size: 14px;
    width: 100%;
    padding: 13px 16px;
}
.cr-btn-whatsapp:hover:not(:disabled) { background: var(--cr-whatsapp-dark); color: var(--cr-white); }
.cr-btn-whatsapp:disabled { background: var(--cr-gray-200); border-color: var(--cr-gray-200); color: var(--cr-gray-400); }

.cr-range-row {
    display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
    padding: .75rem 1.25rem; background: var(--cr-gray-50); border-bottom: 1px solid var(--cr-gray-100);
}
.cr-range-row label { font-size: 12px; color: var(--cr-gray-600); font-weight: 500; }
.cr-range-row input[type=number] {
    width: 80px; padding: 8px; border: 1px solid var(--cr-gray-200);
    border-radius: var(--cr-radius-sm); font-size: 12px; outline: none; color: var(--cr-gray-800);
}
.cr-range-row input[type=number]:focus { border-color: var(--cr-green); }

.cr-legend-row {
    display: flex; gap: 16px; align-items: center;
    padding: .6rem 1.25rem; border-bottom: 1px solid var(--cr-gray-100);
    font-size: 12px; color: var(--cr-gray-600); flex-wrap: wrap;
}
.cr-legend-item { display: flex; align-items: center; gap: 5px; }
.cr-legend-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid transparent; flex-shrink: 0; }
.cr-sw-avail { background: var(--cr-gray-50); border-color: var(--cr-gray-200); }
.cr-sw-selected { background: var(--cr-blue); border-color: var(--cr-blue-dark); }
.cr-sw-hold { background: var(--cr-amber); border-color: var(--cr-amber-dark); }
.cr-sw-sold { background: var(--cr-green); border-color: var(--cr-green-dark); }
.cr-sw-search { background: var(--cr-amber); border-color: var(--cr-amber-dark); }
.cr-grid-count { font-size: 11px; color: var(--cr-gray-400); }

/* ── GRID ── */
.cr-grid-scroll { max-height: 460px; overflow-y: auto; padding: .75rem 1.25rem 1rem; -webkit-overflow-scrolling: touch; }
.cr-numbers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px,1fr)); gap: 5px; }
.cr-grid-loading, .cr-tbl-loading { text-align: center; padding: 2rem; color: var(--cr-gray-400); font-size: 13px; grid-column: 1/-1; }

.cr-num-btn {
    height: 40px; border-radius: var(--cr-radius-sm); border: 1px solid var(--cr-gray-200);
    background: var(--cr-gray-50); color: var(--cr-gray-600); font-size: 12px;
    cursor: pointer; transition: all .1s; user-select: none; position: relative;
    font-variant-numeric: tabular-nums;
}
.cr-num-btn.cr-est-avail:hover { border-color: var(--cr-blue); background: var(--cr-blue-light); color: var(--cr-blue-dark); transform: scale(1.07); z-index: 2; font-weight: 600; }

.cr-num-btn.cr-est-selected {
    background: var(--cr-blue); border-color: var(--cr-blue-dark); color: var(--cr-white); font-weight: 700;
    box-shadow: 0 0 0 2px rgba(55,138,221,.25);
}
.cr-num-btn.cr-est-selected:hover { background: var(--cr-blue-dark); transform: scale(1.07); z-index: 2; }

.cr-num-btn.cr-est-hold {
    background: var(--cr-amber); border-color: var(--cr-amber-dark); color: #4A2E02; font-weight: 600; cursor: not-allowed;
}
.cr-num-btn.cr-est-sold {
    background: var(--cr-green); border-color: var(--cr-green-dark); color: var(--cr-white); font-weight: 600; cursor: not-allowed;
}
/* En modo admin, los números ocupados sí se pueden volver a abrir para editarlos */
.cr-board[data-modo="admin"] .cr-num-btn.cr-est-hold,
.cr-board[data-modo="admin"] .cr-num-btn.cr-est-sold { cursor: pointer; }
.cr-board[data-modo="admin"] .cr-num-btn.cr-est-hold:hover,
.cr-board[data-modo="admin"] .cr-num-btn.cr-est-sold:hover { transform: scale(1.07); z-index: 2; filter: brightness(.94); }

.cr-num-btn.cr-hl { outline: 2px solid var(--cr-amber); outline-offset: -2px; }
.cr-num-btn.cr-hidden { display: none; }

/* ── SELECCIÓN DEL COMPRADOR ── */
.cr-selection-body { padding: 1rem 1.25rem 1.25rem; }
.cr-selected-chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 34px; margin-bottom: .85rem; }
.cr-selection-empty { font-size: 13px; color: var(--cr-gray-400); }
.cr-chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--cr-blue-light); color: var(--cr-blue-dark);
    border: 1px solid #BFDBF5; border-radius: 99px; padding: 6px 6px 6px 12px;
    font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.cr-chip-remove {
    border: none; background: rgba(37,105,172,.12); color: var(--cr-blue-dark);
    width: 20px; height: 20px; border-radius: 50%; cursor: pointer; font-size: 11px;
    display: inline-flex; align-items: center; justify-content: center; padding: 0; line-height: 1;
}
.cr-chip-remove:hover { background: rgba(37,105,172,.25); }
.cr-selection-total-row {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--cr-gray-50); border-radius: var(--cr-radius-md); padding: 12px 16px;
    font-size: 14px; color: var(--cr-gray-600);
}
.cr-selection-total-row strong { font-size: 18px; color: var(--cr-gray-800); }

/* ── FORMULARIO ── */
.cr-form-body { padding: 1rem 1.25rem 1.25rem; display: flex; flex-direction: column; gap: 12px; }
.cr-form-field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--cr-gray-600); margin-bottom: 5px; }
.cr-form-field input {
    width: 100%; padding: 12px 12px; border: 1px solid var(--cr-gray-200); border-radius: var(--cr-radius-sm);
    font-size: 15px; outline: none; color: var(--cr-gray-800); font-family: inherit;
}
.cr-form-field input:focus { border-color: var(--cr-blue); }
.cr-form-hint { font-size: 12px; color: var(--cr-gray-400); margin: 2px 0 0; line-height: 1.5; }
.cr-form-error { color: var(--cr-red); font-size: 13px; font-weight: 600; margin: 0; display: none; }

.cr-confirmacion { display: none; padding: 1.25rem; text-align: center; }
.cr-confirmacion.cr-open { display: block; }
.cr-confirmacion-icon { font-size: 34px; margin-bottom: 4px; }
.cr-confirmacion h3 { margin: 0 0 6px; font-size: 17px; }
.cr-confirmacion p { color: var(--cr-gray-600); font-size: 13.5px; margin: 0 0 14px; }
.cr-mensaje-preview {
    width: 100%; resize: none; border: 1px solid var(--cr-gray-200); border-radius: var(--cr-radius-sm);
    padding: 10px 12px; font-size: 12.5px; color: var(--cr-gray-600); background: var(--cr-gray-50);
    margin-bottom: 12px; font-family: inherit;
}
.cr-confirmacion-actions { display: flex; gap: 10px; margin-bottom: 12px; }
.cr-confirmacion-actions .cr-btn { flex: 1; }

/* ── BARRA FLOTANTE MÓVIL ── */
.cr-sticky-bar {
    display: none;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 9999;
    background: var(--cr-gray-800); color: var(--cr-white);
    padding: 12px 16px; align-items: center; justify-content: space-between; gap: 12px;
    box-shadow: 0 -4px 16px rgba(0,0,0,.18);
    transform: translateY(100%); transition: transform .22s ease;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.cr-sticky-bar.cr-show { transform: translateY(0); }
.cr-sticky-bar span { font-size: 13px; font-weight: 600; }

/* ── TABLE ── */
.cr-table-toolbar { display: flex; gap: 8px; align-items: center; padding: .75rem 1.25rem; border-bottom: 1px solid var(--cr-gray-100); background: var(--cr-gray-50); flex-wrap: wrap; }
.cr-table-wrap { overflow: auto; max-height: 440px; -webkit-overflow-scrolling: touch; }
table.cr-excel { width: 100%; min-width: 720px; border-collapse: collapse; font-size: 12.5px; }
table.cr-excel thead th {
    position: sticky; top: 0; background: var(--cr-gray-50); border: 1px solid var(--cr-gray-100);
    padding: 8px 10px; text-align: left; font-weight: 600; color: var(--cr-gray-600);
    font-size: 11px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; z-index: 1;
}
table.cr-excel tbody tr:hover { background: var(--cr-blue-light); }
table.cr-excel tbody tr.cr-row-sold { background: var(--cr-green-light); }
table.cr-excel tbody tr.cr-row-sold:hover { background: #C5EDE0; }
table.cr-excel tbody tr.cr-row-hold { background: var(--cr-amber-light); }
table.cr-excel tbody tr.cr-row-hold:hover { background: #F7DFB0; }
table.cr-excel td { border: 1px solid var(--cr-gray-100); padding: 7px 10px; vertical-align: middle; color: var(--cr-gray-800); }
table.cr-excel td.cr-num-cell { font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
table.cr-excel td.cr-comprador-cell, table.cr-excel td.cr-nota-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cr-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.cr-badge-sold { background: var(--cr-green-light); color: var(--cr-green-dark); border: 1px solid var(--cr-green-mid); }
.cr-badge-hold { background: var(--cr-amber-light); color: var(--cr-amber-dark); border: 1px solid #F3C889; }
.cr-badge-avail { background: var(--cr-gray-50); color: var(--cr-gray-600); border: 1px solid var(--cr-gray-200); }

.cr-tbl-editar {
    padding: 5px 12px; font-size: 11px; font-weight: 600; cursor: pointer; border-radius: var(--cr-radius-sm);
    border: 1px solid var(--cr-gray-200); background: var(--cr-white); color: var(--cr-gray-600);
}
.cr-tbl-editar:hover { background: var(--cr-blue-light); border-color: var(--cr-blue); color: var(--cr-blue-dark); }

.cr-bottom-actions { display: flex; justify-content: flex-end; padding: .5rem 0 1.5rem; }

/* ── TOAST ── */
.cr-toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
    background: var(--cr-gray-800); color: var(--cr-white); padding: 10px 20px;
    border-radius: var(--cr-radius-md); font-size: 13px; font-weight: 500; z-index: 99999;
    transition: transform .22s ease; box-shadow: var(--cr-shadow-md); max-width: 90vw; text-align: center; pointer-events: none;
}
.cr-toast.cr-show { transform: translateX(-50%) translateY(0); }

/* ── MODAL ── */
.cr-modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 99998; align-items: center; justify-content: center; padding: 16px; }
.cr-modal-bg.cr-open { display: flex; }
.cr-modal-box { background: var(--cr-white); border-radius: var(--cr-radius-lg); padding: 1.75rem; width: 100%; max-width: 400px; box-shadow: var(--cr-shadow-md); max-height: 90vh; overflow-y: auto; }
.cr-modal-box h3 { font-size: 16px; font-weight: 700; margin: 0 0 8px; }
.cr-modal-box p { font-size: 13px; color: var(--cr-gray-600); margin: 0 0 1.25rem; line-height: 1.6; }
.cr-modal-field { margin-bottom: 12px; }
.cr-modal-field label { display: block; font-size: 12px; font-weight: 600; color: var(--cr-gray-600); margin-bottom: 4px; }
.cr-modal-field input, .cr-modal-field textarea {
    width: 100%; padding: 10px 10px; border: 1px solid var(--cr-gray-200); border-radius: var(--cr-radius-sm);
    font-size: 14px; outline: none; font-family: inherit; color: var(--cr-gray-800);
}
.cr-modal-field input:focus, .cr-modal-field textarea:focus { border-color: var(--cr-green); }
.cr-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 1rem; }

.cr-estado-selector { display: flex; gap: 6px; }
.cr-estado-opt {
    flex: 1; padding: 9px 6px; border-radius: var(--cr-radius-sm); border: 1px solid var(--cr-gray-200);
    background: var(--cr-white); color: var(--cr-gray-600); font-size: 12px; font-weight: 600; cursor: pointer;
}
.cr-estado-opt[data-estado="disponible"].active { background: var(--cr-gray-100); border-color: var(--cr-gray-400); color: var(--cr-gray-800); }
.cr-estado-opt[data-estado="apartado"].active { background: var(--cr-amber-light); border-color: var(--cr-amber-dark); color: var(--cr-amber-dark); }
.cr-estado-opt[data-estado="vendido"].active { background: var(--cr-green-light); border-color: var(--cr-green-dark); color: var(--cr-green-dark); }

.cr-color-sold { color: var(--cr-white); }
.cr-color-hold { color: var(--cr-white); }
.cr-color-avail { color: var(--cr-white); }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
    table.cr-excel td.cr-comprador-cell, table.cr-excel td.cr-nota-cell { max-width: 140px; }
}

@media (max-width: 700px) {
    .cr-board { font-size: 13.5px; }
    .cr-public-header { padding: 1rem; }
    .cr-public-title { font-size: 19px; }
    .cr-stats-bar { padding: 0; border-radius: var(--cr-radius-md); }
    .cr-stat-item { padding: 10px 14px; border-right: none; border-bottom: 1px solid rgba(255,255,255,.15); flex: 1 1 45%; }
    .cr-progress-wrap { flex: 1 1 100%; padding: 10px 14px; }
    .cr-numbers-grid { grid-template-columns: repeat(auto-fill, minmax(42px,1fr)); gap: 4px; }
    .cr-num-btn { height: 38px; font-size: 11px; }
    .cr-card-header { padding: .85rem 1rem .65rem; }
    .cr-controls-row { gap: 6px; }
    .cr-controls-row .cr-filter-btn { flex: 1 1 auto; }
    .cr-search-box { flex: 1 1 100%; }
    .cr-range-row { padding: .65rem 1rem; }
    .cr-range-row input[type=number] { width: 70px; }
    .cr-legend-row { padding: .5rem 1rem; gap: 10px; font-size: 11px; }
    .cr-grid-scroll { padding: .6rem .75rem .85rem; max-height: 400px; }
    .cr-selection-body, .cr-form-body { padding: .85rem 1rem 1rem; }
    .cr-confirmacion { padding: 1rem; }
    .cr-confirmacion-actions { flex-direction: column; }
    .cr-table-toolbar { padding: .65rem 1rem; }
    .cr-bottom-actions { padding: .5rem 1rem 1.5rem; justify-content: stretch; }
    .cr-bottom-actions .cr-btn { width: 100%; }
    .cr-sticky-bar { display: flex; }
    .cr-modal-box { padding: 1.25rem; }
}

@media (max-width: 420px) {
    .cr-numbers-grid { grid-template-columns: repeat(auto-fill, minmax(36px,1fr)); }
    .cr-num-btn { height: 36px; font-size: 10.5px; }
    .cr-stat-item { flex: 1 1 100%; border-bottom: 1px solid rgba(255,255,255,.15); }
}
