/* ============================================================================
   Mercurio — hoja de estilos principal
   Todos los estilos del proyecto viven acá: no debe haber `style=""` ni
   etiquetas <style> en el HTML.

   Índice
     1.  Variables y base
     2.  Sidebar
     3.  Layout principal
     4.  Componentes comunes
     5.  Tarjetas de estadística (stat-card)
     6.  Utilidades
     7.  Login
     8.  Vender (punto de venta)
     9.  Caja — modal de cierre
     10. Setup y error de base de datos
   ========================================================================== */

/* ----------------------------------------
   1. Variables y base
   ---------------------------------------- */
:root {
    --sb: 240px;
    --sbg: #12151c;
    --sbhover: #1e2330;
    --accent: #6366f1;
    --accentHover: #4f46e5;
}

* { box-sizing: border-box; }

body {
    background: #f1f4fb;
    font-family: 'Segoe UI', system-ui, sans-serif;
    margin: 0;
}

/* ----------------------------------------
   2. Sidebar
   ---------------------------------------- */
#sidebar {
    width: var(--sb);
    min-height: 100vh;
    background: var(--sbg);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 200;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transition: left .25s ease;
}
.sb-brand {
    background: var(--accent);
    color: #fff;
    padding: 1.1rem 1.25rem;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -.3px;
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-shrink: 0;
}

/* Enlaces sueltos */
.sb-link {
    color: #a8b2c1;
    padding: .55rem 1.25rem;
    display: flex;
    align-items: center;
    gap: .625rem;
    text-decoration: none;
    font-size: .85rem;
    border-left: 3px solid transparent;
    transition: all .15s;
}
.sb-link:hover { background: var(--sbhover); color: #fff; }
.sb-link.active { background: var(--sbhover); color: #fff; border-left-color: var(--accent); }
.sb-link i { width: 18px; text-align: center; opacity: .8; }

/* Botón de grupo colapsable */
.sb-group {
    width: 100%;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    color: #a8b2c1;
    padding: .55rem 1.25rem;
    display: flex;
    align-items: center;
    gap: .625rem;
    font-size: .85rem;
    cursor: pointer;
    transition: all .15s;
    text-align: left;
}
.sb-group:hover { background: var(--sbhover); color: #fff; }
.sb-group.active { color: #fff; }
.sb-group i.icon { width: 18px; text-align: center; opacity: .8; }
.sb-chevron { margin-left: auto; font-size: .7rem; transition: transform .2s; opacity: .5; }
.sb-group[aria-expanded="true"] .sb-chevron { transform: rotate(180deg); }

/* Sub-enlaces dentro de los grupos */
.sb-sub { padding-left: 0; }
.sb-sub .sb-link { padding-left: 2.75rem; font-size: .82rem; border-left: 3px solid transparent; }
.sb-sub .sb-link.active { border-left-color: var(--accent); }

/* Vender — acción principal destacada */
.sb-vender {
    background: rgba(99, 102, 241, .15);
    border-left: 3px solid var(--accent) !important;
    color: #a5b4fc !important;
    font-weight: 600;
    margin: .25rem .75rem;
    border-radius: .375rem;
    padding: .6rem 1rem !important;
}
.sb-vender:hover { background: rgba(99, 102, 241, .3) !important; color: #fff !important; }
.sb-vender.active { background: rgba(99, 102, 241, .35) !important; color: #fff !important; }

/* Pie del sidebar: usuario */
.sb-user { padding: .75rem 1.25rem; border-top: 1px solid #1e2330; margin-top: auto; flex-shrink: 0; }
.sb-user-name { color: #e2e8f0; font-size: .82rem; font-weight: 600; }
.sb-user-role { color: #5a6373; font-size: .72rem; }
.sb-logout { font-size: .75rem; }

/* ----------------------------------------
   3. Layout principal
   ---------------------------------------- */
#main { margin-left: var(--sb); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: .7rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-title { font-weight: 600; color: #111827; font-size: 1rem; }
.page-body { padding: 1.5rem; flex: 1; }

/* Botón hamburguesa: solo visible en mobile */
.btn-sb-toggle { display: none; }

/* Capa oscura al abrir el sidebar en mobile */
#sbOverlay { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 199; }
#sbOverlay.open { display: block; }

@media (max-width: 991.98px) {
    #sidebar { left: calc(-1 * var(--sb)); }
    #sidebar.open { left: 0; box-shadow: 4px 0 24px rgba(0, 0, 0, .4); }
    #main { margin-left: 0 !important; }
    .btn-sb-toggle { display: flex !important; }
    .page-body { padding: 1rem; }
}

/* ----------------------------------------
   4. Componentes comunes
   ---------------------------------------- */
.card { border: 1px solid #e5e7eb; border-radius: .5rem; box-shadow: 0 1px 3px rgba(0, 0, 0, .06); }
.card-header { background: #fff; border-bottom: 1px solid #e5e7eb; padding: .875rem 1.25rem; font-weight: 600; }

/* Tarjeta sobre fondo oscuro (totales del detalle de venta) */
.card-oscura { background: #1a1d23; color: #fff; border: none; }
.hr-clara { border-color: rgba(255, 255, 255, .2); }

table thead th {
    font-size: .75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: .5px;
    background: #f9fafb;
    border-bottom: 2px solid #e5e7eb !important;
}
.table > :not(:first-child) { border-top: none; }

.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accentHover); border-color: var(--accentHover); }
.form-label { font-weight: 500; font-size: .875rem; color: #374151; }

/* ----------------------------------------
   5. Tarjetas de estadística
   ---------------------------------------- */
.stat-card { border-radius: .5rem; padding: 1.25rem; color: #fff; display: flex; align-items: center; gap: 1rem; }
.stat-card .icon { font-size: 2rem; opacity: .8; }
.stat-card .val { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-card .lbl { font-size: .8rem; opacity: .85; margin-top: .2rem; }

/* Variantes de color */
.stat-indigo  { background: #6366f1; }
.stat-verde   { background: #10b981; }
.stat-ambar   { background: #f59e0b; }
.stat-celeste { background: #0ea5e9; }
.stat-rosa    { background: #ec4899; }

/* ----------------------------------------
   6. Utilidades
   ---------------------------------------- */
/* Se muestra/oculta desde JS agregando o quitando esta clase.
   Lleva !important para ganarle a los display de los componentes (flex, etc.). */
.oculto { display: none !important; }

/* Iconos decorativos de estados vacíos y confirmaciones */
.icono-vacio { font-size: 1.5rem; opacity: .3; }
.icono-vacio-lg { font-size: 2rem; opacity: .3; }
.icono-destacado { font-size: 2rem; }
.icono-exito { font-size: 3rem; color: #198754; margin-bottom: .5rem; }

.texto-mini { font-size: .75rem; }
.texto-ok { color: #198754; }
.texto-falta { color: #dc3545; }

/* Anchos fijos de columnas en tablas */
.col-imagen   { width: 60px; }
.col-precio   { width: 130px; }
.col-cantidad { width: 100px; }
.col-subtotal { width: 110px; }
.col-quitar   { width: 38px; }

/* Miniaturas de producto */
.miniatura { width: 46px; height: 46px; object-fit: cover; }
.miniatura-vacia { width: 46px; height: 46px; color: #9ca3af; }
.img-producto { max-height: 160px; }
.img-producto-vacia { height: 160px; color: #9ca3af; background: #f9fafb; }

/* Barras de progreso de límite de crédito.
   El ancho lo aplica includes/javascript/scripts.js desde data-porcentaje. */
.progress-limite { height: 6px; }
.progress-mini { height: 3px; width: 80px; }

/* ----------------------------------------
   7. Login
   ---------------------------------------- */
.pagina-login {
    background: #f1f4fb;
    font-family: 'Segoe UI', system-ui, sans-serif;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    width: 100%;
    max-width: 420px;
    border: 1px solid #e5e7eb;
    border-radius: .75rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .08);
    background: #fff;
    overflow: hidden;
}
.login-header { background: #6366f1; color: #fff; padding: 2rem; text-align: center; }
.login-header h1 { font-size: 1.5rem; font-weight: 700; margin: 0; }
.login-header p { margin: .5rem 0 0; opacity: .85; font-size: .9rem; }
.login-logo { font-size: 2.5rem; margin-bottom: .5rem; }
.login-body { padding: 2rem; }

.login-recaptcha { display: flex; justify-content: center; }
.login-recaptcha .g-recaptcha { line-height: 0; }
/* El widget de reCAPTCHA mide 304px fijos: lo escalamos para que no
   desborde la tarjeta de login en pantallas angostas. */
@media (max-width: 420px) {
    .login-recaptcha .g-recaptcha { transform: scale(.85); transform-origin: center top; height: 66px; }
}
@media (max-width: 360px) {
    .login-recaptcha .g-recaptcha { transform: scale(.72); height: 56px; }
}

/* ----------------------------------------
   8. Vender (punto de venta)
   ---------------------------------------- */
#searchResults {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 999;
    border: 1px solid #dee2e6;
    border-radius: .375rem;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
    max-height: 300px;
    overflow-y: auto;
}
.search-item { padding: .65rem 1rem; cursor: pointer; border-bottom: 1px solid #f0f0f0; font-size: .875rem; }
.search-item:hover { background: #f0f0ff; }
.search-item .price { color: #6366f1; font-weight: 600; }
.search-item .stock { color: #9ca3af; font-size: .78rem; }

#cartTable td { vertical-align: middle; }
.input-precio { min-width: 0; }
.input-cantidad { width: 70px; }

.total-box { background: #12151c; color: #fff; border-radius: .5rem; padding: 1.25rem; }
.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .3rem 0;
    font-size: .9rem;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.total-row:last-child { border-bottom: none; }
.total-row.big {
    font-size: 1.4rem;
    font-weight: 700;
    padding-top: .85rem;
    margin-top: .4rem;
    border-bottom: none;
    border-top: 1px solid rgba(255, 255, 255, .15);
}

.vuelto-box { background: #fff; border: 2px solid #e5e7eb; border-radius: .5rem; padding: 1rem 1.25rem; }
.vuelto-label {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: #6b7280;
    margin-bottom: .1rem;
}
.vuelto-val { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.vuelto-val.falta { color: #dc3545; }
.vuelto-val.exacto { color: #198754; }
.vuelto-val.ok { color: #198754; }
.vuelto-val.neutro { color: #6b7280; }
.vuelto-val.cc { color: #6366f1; }

/* ----------------------------------------
   9. Caja — modal de cierre
   ---------------------------------------- */
.modal-cierre {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}
.modal-cierre.abierto { display: flex; }
.modal-cierre-caja { max-width: 480px; width: 100%; margin: 1rem; }

/* ----------------------------------------
   10. Setup y error de base de datos
   ---------------------------------------- */
.setup-container { max-width: 620px; }
.db-error { font-family: sans-serif; padding: 2rem; }
.db-error h2 { color: #dc3545; }
