/* =====================================================================================================================
   El panel del administrador: un backoffice con barra lateral índigo, distinto de la tienda del cliente.
   ===================================================================================================================== */

/* ---------- Estructura ---------- */

.admin { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; background: var(--bg); }
.admin-side { display: none; }
.admin-body { display: flex; flex: 1; flex-direction: column; min-width: 0; }

.admin-top {
    position: sticky; top: 0; z-index: 60; display: flex; align-items: center; gap: 0.75rem; height: var(--header-h); padding: 0 1rem; padding-top: env(safe-area-inset-top, 0px);
    color: var(--on-ink); background: var(--ink);
}
.admin-top-brand { display: flex; flex: 1; align-items: center; gap: 0.6rem; min-width: 0; font-weight: 800; color: var(--on-ink); text-decoration: none; }
.admin-top-brand:hover { color: var(--on-ink); }
.admin-top-brand img { border-radius: 10px; }
.admin-top-brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-top-title { display: none; }
.admin-top .account-trigger { color: var(--on-ink); background: rgb(255 255 255 / 0.14); }
.admin-top .account-trigger:hover { background: rgb(255 255 255 / 0.22); filter: none; }

.admin-main { flex: 1; width: 100%; max-width: 78rem; margin: 0 auto; padding: 1.25rem 1rem calc(var(--nav-h) + var(--safe-bottom) + 1.5rem); }

@media (min-width: 1024px) {
    .admin { flex-direction: row; }
    .admin-side {
        position: sticky; top: 0; display: flex; flex: none; flex-direction: column; gap: 1.5rem; width: 16.5rem; height: 100vh; padding: 1.4rem 1rem;
        color: var(--on-ink); background: var(--ink); overflow-y: auto;
    }
    .admin-brand { display: flex; align-items: center; gap: 0.75rem; padding: 0 0.5rem; color: var(--on-ink); text-decoration: none; }
    .admin-brand:hover { color: var(--on-ink); }
    .admin-brand img { border-radius: 11px; }
    .admin-brand strong { display: block; font-size: 1.15rem; line-height: 1.15; letter-spacing: -0.02em; }
    .admin-brand small { display: block; max-width: 10rem; overflow: hidden; font-size: 0.8rem; color: var(--on-ink-muted); text-overflow: ellipsis; white-space: nowrap; }
    .admin-nav { display: flex; flex-direction: column; gap: 0.25rem; }
    .admin-link {
        display: flex; align-items: center; gap: 0.8rem; min-height: 2.9rem; padding: 0 1rem; font-weight: 700; color: var(--on-ink-muted); text-decoration: none; border-radius: 14px;
        transition: background-color 0.15s ease, color 0.15s ease;
    }
    .admin-link .icon { font-size: 1.2rem; }
    .admin-link:hover { color: var(--on-ink); background: rgb(255 255 255 / 0.08); }
    .admin-link.active { color: var(--on-brand); background: var(--brand); }
    .admin-side-note { margin: auto 0 0; padding: 1rem; font-size: 0.8rem; line-height: 1.45; color: var(--on-ink-muted); background: rgb(255 255 255 / 0.06); border-radius: 14px; }

    .admin-top { height: auto; padding: 1rem 2rem 0; color: var(--text); background: transparent; }
    .admin-top-brand { display: none; }
    .admin-top-title { display: block; flex: 1; font-size: 0.9rem; font-weight: 700; color: var(--text-muted); }
    .admin-top .account-trigger { color: var(--link); background: var(--link-soft); }
    .admin-top .account-trigger:hover { background: var(--link-soft); filter: brightness(0.96); }
    .admin-main { padding: 1.1rem 2rem 3rem; }
}

/* ---------- Inicio: tarjetas de resumen ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; margin-bottom: 1.5rem; }
@media (min-width: 900px) { .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; } }
.stat-tile { display: flex; flex-direction: column; gap: 0.15rem; padding: 1rem; color: inherit; text-decoration: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); transition: transform 0.15s ease, box-shadow 0.15s ease; }
a.stat-tile:hover { color: inherit; transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.stat-tile .stat-head { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.8rem; font-weight: 700; color: var(--text-muted); }
.stat-tile .stat-icon { display: grid; place-items: center; flex: none; width: 2.1rem; height: 2.1rem; color: var(--link); background: var(--link-soft); border-radius: 10px; }
.stat-value { margin-top: 0.5rem; font-size: 1.75rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; }
.stat-hint { font-size: 0.78rem; color: var(--text-muted); }
.stat-tile.is-warn { border-color: color-mix(in srgb, var(--warning) 50%, transparent); }
.stat-tile.is-warn .stat-icon { color: var(--warning); background: var(--warning-soft); }
.stat-tile.is-ok .stat-icon { color: var(--success); background: var(--success-soft); }
.stat-tile.is-bad .stat-icon { color: var(--danger); background: var(--danger-soft); }
.admin-cards { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }
@media (min-width: 640px) { .admin-cards { grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); } }
.admin-card { display: flex; align-items: center; gap: 0.9rem; padding: 0.95rem 1rem; color: inherit; text-decoration: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); transition: transform 0.15s ease, box-shadow 0.15s ease; }
.admin-card:hover { color: inherit; transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.admin-card .stat-icon { display: grid; place-items: center; flex: none; width: 2.6rem; height: 2.6rem; font-size: 1.2rem; color: var(--on-brand); background: var(--brand); border-radius: 12px; }
.admin-card strong { display: block; }
.admin-card span.small { color: var(--text-muted); }
.erp-dot { display: inline-block; width: 0.6rem; height: 0.6rem; margin-right: 0.35rem; background: var(--border-strong); border-radius: 50%; }
.erp-dot.ok { background: var(--success); }
.erp-dot.late { background: var(--warning); }

@media (max-width: 899.98px) {
    .stat-tile { padding: 0.8rem; }
    .stat-value { font-size: 1.5rem; }
}

/* ---------- Listados ---------- */

.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.filters .form-control { flex: 1 1 14rem; }
.filters .form-select { flex: 0 0 auto; width: auto; }

.table-responsive { padding: 0.25rem 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.form-panel .table-responsive { padding: 0; background: transparent; border: 0; border-radius: 0; }
.table { --bs-table-bg: transparent; --bs-table-color: var(--text); --bs-table-border-color: var(--border); --bs-table-hover-bg: var(--surface-2); margin-bottom: 0; }
.table > :not(caption) > * > * { padding: 0.75rem 0.6rem; }
.table thead th { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); border-bottom-width: 1px; }
.thumb-cell { width: 3.5rem; }
.thumb-cell .product-thumb { width: 2.6rem; border-radius: 10px; font-size: 0.7rem; }
.row-inactive { opacity: 0.6; }
.sku-sub { display: none; }

/* ---------- Edición ---------- */

.edit-layout { display: grid; gap: 1rem; align-items: start; }
.edit-layout > * { min-width: 0; }
.edit-layout .form-panel + .form-panel { margin-top: 1rem; }
@media (min-width: 992px) { .edit-layout { grid-template-columns: minmax(0, 1fr) 22rem; } }
.image-preview { width: 6rem; }
.image-preview .product-thumb { width: 6rem; font-size: 1.4rem; border-radius: 14px; }

.credentials { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin-bottom: 0.75rem; }
.credentials dt { font-weight: 700; }
.credentials dd { margin: 0; overflow-wrap: anywhere; }
.temp-password { font-size: 1.1rem; letter-spacing: 0.05em; }
.import-warnings { max-height: 16rem; padding-left: 1.2rem; overflow-y: auto; }

/* ---------- Celular: administración más compacta ---------- */

@media (max-width: 639.98px) {
    .filters .form-control { flex-basis: 100%; }
    .filters .form-select { flex: 1 1 0; width: auto; }
    .filters.filters-inline .form-control { flex: 1 1 0; min-width: 0; }
    .hide-sm { display: none; }
    .sku-sub { display: block; margin-top: 0.1rem; font-size: 0.78rem; color: var(--text-muted); }
    .table > :not(caption) > * > * { padding: 0.65rem 0.4rem; }
}

/* ---------- Enlace de acceso de un cliente ---------- */

.access-box { flex: 1; min-width: 0; }
.access-link { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.access-link .form-control { flex: 1 1 14rem; min-width: 0; font-size: 0.85rem; color: var(--text); background: var(--surface); }

/* ---------- Stock: físico, reservado y disponible ---------- */

.stock-summary { display: flex; flex-direction: column; gap: 0.35rem; margin: 0 0 0.9rem; }
.stock-summary > div { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.stock-summary dt { font-weight: 500; color: var(--text-muted); }
.stock-summary dd { margin: 0; font-weight: 800; font-variant-numeric: tabular-nums; }
.stock-summary .is-available { padding-top: 0.45rem; border-top: 2px solid var(--border); }
.stock-summary .is-available dt { font-weight: 700; color: var(--text); }
.stock-summary .is-available dd { font-size: 1.35rem; color: var(--link); }
.stock-help { margin: -0.25rem 0 0.9rem; }
.cell-sub { display: block; margin-top: 0.1rem; font-size: 0.75rem; font-weight: 400; color: var(--text-muted); }
@media (max-width: 639.98px) { .cell-sub.hide-sm { display: none; } }

/* ---------- Pedidos y correos ---------- */

.subnav { display: inline-flex; gap: 0.25rem; padding: 0.25rem; background: var(--surface-2); border-radius: 999px; }
.subnav-link { display: inline-flex; align-items: center; gap: 0.4rem; min-height: 2.25rem; padding: 0 1rem; font-weight: 700; font-size: 0.9rem; color: var(--text-muted); text-decoration: none; border-radius: 999px; }
.subnav-link:hover { color: var(--text); }
.subnav-link.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow-sm); }
.subnav-row { margin: -0.4rem 0 1rem; }

.order-help { margin: -0.4rem 0 1rem; }
.status-filter { display: flex; gap: 0.5rem; padding: 0.15rem 0 0.7rem; margin-bottom: 0.25rem; overflow-x: auto; scrollbar-width: none; }
.status-filter::-webkit-scrollbar { display: none; }
.order-link { font-weight: 800; text-decoration: none; }
.link-btn { padding: 0; font: inherit; font-weight: 700; color: var(--link); text-align: left; background: none; border: 0; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.order-title { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem; margin: 0; }
.order-sum { padding-top: 0.9rem; font-size: 1.05rem; }
.order-sum strong { margin-left: 0.5rem; font-size: 1.3rem; }
.table tfoot td { border-bottom: 0; }

.history { display: flex; flex-direction: column; gap: 0; margin: 0; padding: 0; list-style: none; }
.history li { position: relative; padding: 0 0 1.1rem 1.5rem; border-left: 2px solid var(--border-strong); margin-left: 0.4rem; }
.history li:last-child { padding-bottom: 0; border-left-color: transparent; }
.history li::before { content: ""; position: absolute; top: 0.35rem; left: -0.46rem; width: 0.8rem; height: 0.8rem; background: var(--link); border: 2px solid var(--surface); border-radius: 50%; }
.history-who { margin-left: 0.4rem; font-size: 0.85rem; color: var(--text-muted); }
.history-when { font-size: 0.8rem; color: var(--text-muted); }
.history .step-note { display: block; margin-top: 0.3rem; padding: 0.4rem 0.7rem; font-size: 0.9rem; background: var(--surface-2); border-radius: var(--radius-sm); }

.order-emails { display: flex; flex-direction: column; gap: 0.8rem; margin: 0 0 0.75rem; padding: 0; }
.order-emails li { padding-bottom: 0.8rem; border-bottom: 1px solid var(--border); }
.order-emails li:last-child { padding-bottom: 0; border-bottom: 0; }

.drawer-wide { width: min(44rem, 100vw); }
.email-meta { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.9rem 1.25rem; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.email-meta > div { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.6rem; }
.email-preview { flex: 1; width: 100%; min-height: 20rem; border: 0; background: #faf7f2; }

/* La navegación interna (Productos · Listas · Promociones) se desliza en pantallas chicas en vez de cortarse */
.subnav { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.subnav::-webkit-scrollbar { display: none; }
.subnav-link { flex: none; white-space: nowrap; }
.promo-customers li { padding: 0.35rem 0; border-top: 1px solid var(--border); }
.promo-customers li:first-child { border-top: 0; }

/* =====================================================================================================================
   Estadísticas del panel de administración
   ===================================================================================================================== */

.analytics { margin: 0 0 2rem; }
.analytics-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 0.75rem; margin-bottom: 0.75rem; }
.analytics-head > div:first-child { flex: 1 1 14rem; min-width: 0; }
.analytics-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.analytics-top { flex: none; margin: 0; }
.analytics-top .form-select { width: auto; }

/* Período */
.period-bar { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.9rem; }
.period-chips { display: flex; gap: 0.4rem; padding: 0.1rem 0 0.3rem; overflow-x: auto; scrollbar-width: none; }
.period-chips::-webkit-scrollbar { display: none; }
.period-chip {
    display: inline-flex; flex: none; align-items: center; gap: 0.4rem; min-height: 2.25rem; padding: 0 0.9rem; font-size: 0.88rem; font-weight: 700; color: var(--text);
    white-space: nowrap; cursor: pointer; background: var(--surface); border: 1.5px solid var(--border); border-radius: 999px;
}
.period-chip:hover { border-color: var(--link); }
.period-chip.active { color: var(--link); background: var(--link-soft); border-color: var(--link); }
.period-custom { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem; }
.period-custom label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.78rem; font-weight: 700; color: var(--text-muted); }

/* Pestañas */
.dash-tabs { display: flex; gap: 0.25rem; width: max-content; max-width: 100%; margin-bottom: 1rem; padding: 0.25rem; overflow-x: auto; scrollbar-width: none; background: var(--surface-2); border-radius: 999px; }
.dash-tabs::-webkit-scrollbar { display: none; }
.dash-tab {
    display: inline-flex; flex: none; align-items: center; gap: 0.4rem; min-height: 2.4rem; padding: 0 1rem; font-size: 0.9rem; font-weight: 700; color: var(--text-muted);
    white-space: nowrap; cursor: pointer; background: transparent; border: 0; border-radius: 999px;
}
.dash-tab:hover { color: var(--text); }
.dash-tab.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow-sm); }
.dash-body { transition: opacity 0.15s ease; }
.dash-body.is-loading { opacity: 0.55; pointer-events: none; }

/* Cifras */
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; margin-bottom: 1rem; }
.kpi-grid-3 .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
@media (min-width: 900px) {
    .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
    .kpi-grid-3 .kpi:last-child:nth-child(odd) { grid-column: auto; }
}
.kpi { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; padding: 0.9rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.kpi-head { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.8rem; font-weight: 700; color: var(--text-muted); }
.kpi .stat-icon { display: grid; flex: none; place-items: center; width: 2.1rem; height: 2.1rem; color: var(--link); background: var(--link-soft); border-radius: 10px; }
.kpi.is-warn .stat-icon { color: var(--warning); background: var(--warning-soft); }
.kpi.is-ok .stat-icon { color: var(--success); background: var(--success-soft); }
.kpi.is-bad .stat-icon { color: var(--danger); background: var(--danger-soft); }
.kpi-value { margin-top: 0.4rem; font-size: 1.55rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.kpi-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem 0.5rem; margin-top: 0.15rem; font-size: 0.78rem; color: var(--text-muted); }
.kpi-delta { padding: 0.05rem 0.45rem; font-size: 0.74rem; font-weight: 800; border-radius: 999px; }
.kpi-delta.up { color: var(--success); background: var(--success-soft); }
.kpi-delta.down { color: var(--danger); background: var(--danger-soft); }
.kpi-delta.flat { color: var(--text-muted); background: var(--surface-2); }

/* Paneles y listas */
.dash-panel { margin-bottom: 1rem; }
.dash-panel h2 { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.9rem; }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: 1rem; margin-bottom: 1rem; }
.dash-grid > .dash-panel { margin: 0; }
@media (min-width: 900px) {
    .dash-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .dash-grid.dash-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.dash-list { display: flex; flex-direction: column; margin: 0; padding: 0; }
.dash-list li { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.55rem 0; border-top: 1px solid var(--border); }
.dash-list li:first-child { padding-top: 0; border-top: 0; }
.dash-list li.stacked { flex-wrap: wrap; row-gap: 0.1rem; }
.dash-list li.stacked .share-bar { flex: 0 0 100%; margin-top: 0; }
.dash-list li.total { border-top-width: 2px; }
.dash-list-main { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
.dash-list-value { flex: none; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.dash-sub { display: flex; align-items: center; gap: 0.4rem; margin: 0 0 0.5rem; font-size: 0.85rem; font-weight: 800; }
.badge-count { padding: 0.05rem 0.5rem; font-size: 0.74rem; font-weight: 800; color: var(--warning); background: var(--warning-soft); border-radius: 999px; }
.attention-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
@media (min-width: 900px) { .attention-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.5rem 2rem; } }

.share-bar { display: block; height: 0.32rem; margin-top: 0.3rem; overflow: hidden; background: var(--surface-2); border-radius: 999px; }
.share-bar > span { display: block; height: 100%; background: var(--link); border-radius: inherit; }
td .share-bar { min-width: 4rem; max-width: 9rem; margin-left: auto; }

/* Estado de los pedidos */
.stack-bar { display: flex; height: 0.9rem; margin-bottom: 0.8rem; overflow: hidden; background: var(--surface-2); border-radius: 999px; }
.stack-bar .seg { display: block; min-width: 3px; height: 100%; }
.seg-pendiente { background: var(--warning); }
.seg-confirmado { background: var(--info); }
.seg-facturado { background: var(--teal); }
.seg-preparando { background: var(--link); }
.seg-listo { background: var(--success); }
.seg-enviado { background: var(--violet); }
.seg-entregado { background: var(--success); opacity: 0.6; }
.seg-cancelado { background: var(--danger); }

/* Rankings */
.dash-table .rank-col { width: 2.4rem; padding-right: 0; }
.rank { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; font-size: 0.8rem; font-weight: 800; color: var(--text-muted); background: var(--surface-2); border-radius: 50%; }
.rank-1 { color: #3b2a00; background: #ffc933; }
.rank-2 { color: #ffffff; background: #4b5563; }
.rank-3 { color: #ffffff; background: #8a5a2b; }

/* Gráfico de barras */
.chart-caption { min-height: 1.4rem; margin: 0 0 0.6rem; font-size: 0.85rem; color: var(--text-muted); }
.chart-wrap { position: relative; padding-top: 0.5rem; }
.chart-max { position: absolute; top: 0; left: 0; z-index: 1; padding: 0 0.3rem 0 0; font-size: 0.7rem; font-weight: 700; color: var(--text-muted); background: var(--surface); }
.chart-plot {
    display: flex; align-items: flex-end; gap: 2px; height: 11rem; border-bottom: 1px solid var(--border-strong, var(--border));
    background: repeating-linear-gradient(to top, transparent 0, transparent calc(25% - 1px), var(--border) calc(25% - 1px), var(--border) 25%);
}
.chart-col { display: flex; flex: 1; align-items: flex-end; min-width: 0; height: 100%; padding: 0; cursor: pointer; background: transparent; border: 0; }
.chart-bar { display: block; width: 100%; background: var(--link); border-radius: 3px 3px 0 0; opacity: 0.55; transition: opacity 0.1s ease; }
.chart-col:hover .chart-bar, .chart-col.is-selected .chart-bar { opacity: 1; }
.chart-col.is-selected .chart-bar { background: var(--brand); }
.chart-bar.is-zero { height: 1px !important; background: var(--border-strong, var(--border)); opacity: 1; }
.chart-axis { display: flex; justify-content: space-between; margin-top: 0.3rem; font-size: 0.72rem; color: var(--text-muted); }

/* Ventas por día de la semana */
.week-bars { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.4rem; margin: 0; padding: 0; }
.week-col { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; min-width: 0; }
.week-value { max-width: 100%; overflow: hidden; font-size: 0.68rem; font-weight: 700; color: var(--text-muted); text-overflow: ellipsis; white-space: nowrap; }
.week-track { display: flex; align-items: flex-end; width: 100%; height: 7rem; overflow: hidden; background: var(--surface-2); border-radius: 8px; }
.week-bar { display: block; width: 100%; background: var(--link); border-radius: 8px 8px 0 0; opacity: 0.6; }
.week-col.is-best .week-bar { background: var(--brand); opacity: 1; }
.week-col.is-best .week-value { color: var(--text); }
.week-label { font-size: 0.78rem; font-weight: 700; }
@media (max-width: 479.98px) { .week-value { font-size: 0.6rem; } .week-bars { gap: 0.25rem; } }

@media (max-width: 639.98px) {
    .analytics-head { align-items: flex-start; }
    .kpi { padding: 0.8rem; }
    .kpi-value { font-size: 1.3rem; }
    .chart-plot { height: 9rem; }
}
