/* ================================================================
   TEMA CLARO (por defecto) + MODO NOCTURNO con html[data-tema="oscuro"]
   Sidebar siempre oscuro (como el original).
   ================================================================ */
:root {
    --fondo: #eef2f7;
    --tarjeta: #ffffff;
    --texto: #0f172a;
    --texto-suave: #64748b;
    --borde: #e2e8f0;
    --hover: #f1f5f9;
    --primario: #2563eb;
    --acento: #8b5cf6;
    --exito: #10b981;
    --alerta: #f59e0b;
    --naranja: #f97316;
    --peligro: #ef4444;
    --sombra: 0 4px 20px -2px rgb(0 0 0 / .06), 0 0 3px rgb(0 0 0 / .03);
    /* Sidebar (oscuro en ambos temas) */
    --sb-fondo: #0f172a;
    --sb-item: #94a3b8;
    --sb-activo-bg: #1e293b;
    --sb-borde: #1e293b;
    --sb-card: #1e293b;
    /* Badges */
    --badge-rojo-bg: #fee2e2;  --badge-rojo-tx: #dc2626;
    --badge-verde-bg: #d1fae5; --badge-verde-tx: #059669;
}
html[data-tema="oscuro"] {
    --fondo: hsl(222, 47%, 7%);
    --tarjeta: hsl(222, 47%, 11%);
    --texto: hsl(210, 40%, 98%);
    --texto-suave: hsl(215, 20%, 62%);
    --borde: hsl(222, 30%, 18%);
    --hover: hsl(222, 47%, 14%);
    --sombra: 0 8px 30px -4px rgb(0 0 0 / .3);
    --sb-fondo: hsl(222, 47%, 9%);
    --sb-borde: hsl(222, 30%, 16%);
    --sb-card: hsl(222, 40%, 14%);
    --badge-rojo-bg: hsl(0 84% 60% / .15);   --badge-rojo-tx: #f87171;
    --badge-verde-bg: hsl(160 84% 39% / .15); --badge-verde-tx: #34d399;
}

* { box-sizing: border-box; margin: 0; }
body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--fondo);
    color: var(--texto);
    min-height: 100vh;
    display: flex;
    transition: background .2s, color .2s;
}

/* ================= SIDEBAR (siempre oscuro) ================= */
.sidebar {
    width: 240px;
    min-height: 100vh;
    background: var(--sb-fondo);
    padding: 16px 12px;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 20;
}
.sb-marca {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px 18px;
    border-bottom: 1px solid var(--sb-borde);
    margin-bottom: 14px;
}
.sb-marca img { width: 44px; height: 44px; object-fit: contain; border-radius: 9px; }
.sb-marca .t1 { color: #fff; font-weight: 700; font-size: .98rem; line-height: 1.2; }
.sb-marca .t2 { color: #60a5fa; font-size: .62rem; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; }
.sidebar nav { flex: 1; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    color: var(--sb-item);
    text-decoration: none;
    font-size: .92rem;
    margin-bottom: 4px;
    border-left: 3px solid transparent;
    transition: all .15s;
}
.sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar nav a:hover { background: var(--sb-activo-bg); color: #e2e8f0; }
.sidebar nav a.activo {
    background: var(--sb-activo-bg);
    color: #fff;
    font-weight: 600;
    border-left-color: var(--primario);
}
.sb-usuario {
    background: var(--sb-card);
    border-radius: 14px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}
.sb-usuario .datos { flex: 1; min-width: 0; }
.sb-usuario .nom { color: #fff; font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-usuario .rol { color: var(--sb-item); font-size: .74rem; }
.sb-usuario a { color: var(--sb-item); display: flex; }
.sb-usuario a:hover { color: #f87171; }
.sb-usuario a svg { width: 18px; height: 18px; }

.avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: #3b82f6;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .8rem;
    color: #fff;
    flex-shrink: 0;
}

/* ================= CONTENIDO ================= */
.contenido { margin-left: 240px; flex: 1; padding: 0 0 60px; max-width: 100%; }
.interior { padding: 20px 28px; max-width: 1240px; }

/* Barra superior blanca */
.barra-top {
    background: var(--tarjeta);
    border-bottom: 1px solid var(--borde);
    padding: 14px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.barra-top h1 { font-size: 1.22rem; font-weight: 700; }
.top-derecha { display: flex; align-items: center; gap: 14px; }
.btn-tema {
    background: none;
    border: none;
    color: var(--texto-suave);
    cursor: pointer;
    padding: 7px;
    border-radius: 9px;
    display: flex;
}
.btn-tema:hover { background: var(--hover); color: var(--texto); }
.btn-tema svg { width: 20px; height: 20px; }
html[data-tema="oscuro"] .icono-luna { display: none; }
html:not([data-tema="oscuro"]) .icono-sol { display: none; }
.top-usuario { display: flex; align-items: center; gap: 10px; }
.top-usuario .datos { text-align: left; line-height: 1.25; }
.top-usuario .nom { font-size: .88rem; font-weight: 700; }
.badge-rol {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: .7rem;
    font-weight: 700;
    color: var(--primario);
}
.badge-rol svg { width: 11px; height: 11px; }
.subtitulo-pagina { color: var(--texto-suave); font-size: .88rem; margin-bottom: 18px; }

/* ================= FILTROS DE TIEMPO ================= */
.filtros-tiempo { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.filtros-tiempo a {
    padding: 7px 16px;
    border-radius: 9px;
    border: 1px solid var(--borde);
    background: var(--tarjeta);
    color: var(--texto-suave);
    text-decoration: none;
    font-size: .84rem;
    font-weight: 500;
    transition: all .15s;
}
.filtros-tiempo a:hover { border-color: var(--primario); color: var(--texto); }
.filtros-tiempo a.activo { background: var(--primario); border-color: var(--primario); color: #fff; font-weight: 600; }

/* ================= TARJETAS DE ESTADÍSTICAS ================= */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
    background: var(--tarjeta);
    border-radius: 12px;
    padding: 18px 18px 15px;
    box-shadow: var(--sombra);
    border-left: 4px solid var(--primario);
    position: relative;
}
.stat.b-azul    { border-left-color: #3b82f6; }
.stat.b-verde   { border-left-color: #10b981; }
.stat.b-violeta { border-left-color: #8b5cf6; }
.stat.b-naranja { border-left-color: #f97316; }
.stat .cabecera { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.stat .etiqueta { font-size: .84rem; color: var(--texto-suave); font-weight: 500; }
.stat .icono {
    width: 38px; height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat .icono svg { width: 18px; height: 18px; }
.icono.azul    { background: hsl(217 91% 60% / .12); color: #3b82f6; }
.icono.verde   { background: hsl(160 84% 39% / .12); color: #10b981; }
.icono.violeta { background: hsl(258 90% 66% / .12); color: #8b5cf6; }
.icono.naranja { background: hsl(25 95% 53% / .12);  color: #f97316; }
.stat .valor { font-size: 1.55rem; font-weight: 800; font-variant-numeric: tabular-nums; margin-bottom: 8px; }
.stat .comparacion { display: flex; align-items: center; gap: 7px; font-size: .76rem; color: var(--texto-suave); }
.badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: 7px;
    font-size: .74rem;
    font-weight: 700;
}
.badge svg { width: 11px; height: 11px; }
.badge.rojo  { background: var(--badge-rojo-bg);  color: var(--badge-rojo-tx); }
.badge.verde { background: var(--badge-verde-bg); color: var(--badge-verde-tx); }

/* ================= PANELES ================= */
.fila-paneles { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.fila-paneles.mitades { grid-template-columns: 1fr 1fr; }
.panel {
    background: var(--tarjeta);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--sombra);
    margin-bottom: 18px;
}
.panel h2 { font-size: 1.02rem; font-weight: 700; margin-bottom: 16px; }
.grafico-caja { position: relative; height: 260px; }

/* Lista de ventas recientes */
.lista-ventas .item { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-radius: 10px; }
.lista-ventas .item:hover { background: var(--hover); }
.lista-ventas .info { flex: 1; min-width: 0; }
.lista-ventas .info .nombre { font-size: .9rem; font-weight: 600; }
.lista-ventas .info .detalle { font-size: .78rem; color: var(--texto-suave); }
.lista-ventas .lado { text-align: right; }
.lista-ventas .lado .monto { font-size: .9rem; font-weight: 700; color: var(--exito); }
.lista-ventas .lado .fecha { font-size: .76rem; color: var(--texto-suave); }

.todo-orden { text-align: center; padding: 34px 10px; }
.todo-orden .circulo {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: hsl(160 84% 39% / .12);
    color: var(--exito);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}
.todo-orden .circulo svg { width: 28px; height: 28px; }
.todo-orden .t1 { font-weight: 700; margin-bottom: 3px; }
.todo-orden .t2 { font-size: .84rem; color: var(--texto-suave); }

/* ================= TABLAS ================= */
.tabla-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { padding: 11px 9px; text-align: left; border-bottom: 1px solid var(--borde); }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .6px; color: var(--texto-suave); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: var(--hover); }
.vacio { text-align: center; color: var(--texto-suave); padding: 28px; }
code { background: var(--hover); padding: 2px 7px; border-radius: 6px; font-size: .82rem; }

/* ================= CHIPS ================= */
.chip { font-size: .72rem; font-weight: 600; padding: 3px 11px; border-radius: 20px; white-space: nowrap; display: inline-block; }
.chip.vigente, .chip.activo, .chip.active, .chip.pagado { background: var(--badge-verde-bg); color: var(--badge-verde-tx); }
.chip.vencido, .chip.inactivo, .chip.inactive { background: var(--badge-rojo-bg); color: var(--badge-rojo-tx); }
.chip.porvencer, .chip.pendiente { background: hsl(38 92% 50% / .15); color: #d97706; }
html[data-tema="oscuro"] .chip.porvencer, html[data-tema="oscuro"] .chip.pendiente { color: #fbbf24; }
.chip.vendido, .chip.compartida { background: hsl(258 90% 66% / .13); color: #7c3aed; }
html[data-tema="oscuro"] .chip.vendido, html[data-tema="oscuro"] .chip.compartida { color: #a78bfa; }
.chip.privada { background: hsl(217 91% 60% / .13); color: #2563eb; }
html[data-tema="oscuro"] .chip.privada { color: #60a5fa; }

/* ================= FORMULARIOS ================= */
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.campo { display: flex; flex-direction: column; gap: 5px; }
.campo label { font-size: .77rem; color: var(--texto-suave); }
.campo input, .campo select, .campo textarea {
    padding: 9px 12px;
    border: 1px solid var(--borde);
    border-radius: 9px;
    font-size: .9rem;
    background: var(--fondo);
    color: var(--texto);
    font-family: inherit;
}
.campo input:focus, .campo select:focus, .campo textarea:focus {
    outline: 2px solid hsl(217 91% 60% / .35);
    border-color: var(--primario);
}
.acciones-form { grid-column: 1 / -1; display: flex; gap: 10px; margin-top: 4px; }

button, .btn {
    padding: 9px 20px;
    border: none;
    border-radius: 9px;
    background: var(--primario);
    color: #fff;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: filter .15s, transform .1s;
}
button:hover, .btn:hover { filter: brightness(1.1); }
button:active, .btn:active { transform: scale(.98); }
.btn-sec { background: var(--tarjeta); color: var(--texto-suave); border: 1px solid var(--borde); }
.btn-peligro { background: var(--peligro); }
.btn-wsp { background: #16a34a; }
.btn-mini { padding: 5px 12px; font-size: .78rem; }

.aviso { padding: 11px 15px; border-radius: 10px; margin-bottom: 16px; font-size: .88rem; }
.aviso.ok { background: var(--badge-verde-bg); color: var(--badge-verde-tx); }
.aviso.error { background: var(--badge-rojo-bg); color: var(--badge-rojo-tx); }

.acc a { text-decoration: none; font-size: .8rem; margin-right: 8px; color: var(--texto-suave); }
.acc a:hover { color: var(--primario); }
.acc a.rojo:hover { color: var(--peligro); }

/* ================= LOGIN ================= */
body.pagina-login { background: var(--sb-fondo); }
.login-caja {
    margin: auto;
    width: 100%;
    max-width: 390px;
    background: var(--tarjeta);
    border-radius: 18px;
    padding: 34px 30px;
    box-shadow: 0 20px 60px rgb(0 0 0 / .35);
    text-align: center;
}
.login-caja img { max-width: 130px; margin-bottom: 8px; }
.login-caja h1 { font-size: 1.25rem; margin-bottom: 4px; }
.login-caja p { color: var(--texto-suave); font-size: .85rem; margin-bottom: 22px; }
.login-caja .campo { margin-bottom: 14px; text-align: left; }
.login-caja button { width: 100%; justify-content: center; margin-top: 6px; }

/* ================= RESPONSIVE ================= */
@media (max-width: 900px) {
    .sidebar { width: 100%; min-height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px 10px; }
    .sb-marca { border: none; margin: 0; padding: 0 10px 0 2px; }
    .sb-marca img { width: 34px; height: 34px; }
    .sb-marca .textos { display: none; }
    .sidebar nav { display: flex; }
    .sidebar nav a { white-space: nowrap; margin: 0 2px; padding: 8px 11px; border-left: none; }
    .sidebar nav a span { display: none; }
    .sb-usuario { margin: 0; padding: 6px; background: none; }
    .sb-usuario .datos { display: none; }
    .sb-usuario .avatar { display: none; }
    body { flex-direction: column; }
    .contenido { margin-left: 0; }
    .interior { padding: 16px 13px; }
    .barra-top { padding: 12px 14px; }
    .fila-paneles, .fila-paneles.mitades { grid-template-columns: 1fr; }
}
