/* ============================================================
   Portal B2B — sistema de diseño
   ============================================================ */
:root {
    --c-bg: #f5f6f2;
    --c-surface: #ffffff;
    --c-surface-2: #f6f8f0;
    --c-border: #e6e9df;
    --c-text: #2f2f2e;
    --c-text-soft: #5e6058;
    --c-muted: #9a9d90;

    /* Paleta Ñuble Alimentos: verde lima + gris oscuro */
    --c-primary: #5f8d1f;
    --c-primary-600: #4e7619;
    --c-primary-50: #f1f7e3;
    --c-accent: #8dbe3c;
    --c-dark: #34342f;

    --c-success: #16a34a;
    --c-success-bg: #e8f7ee;
    --c-warning: #d97706;
    --c-warning-bg: #fef3e2;
    --c-danger: #dc2626;
    --c-danger-bg: #fdeaea;
    --c-info: #2563eb;
    --c-info-bg: #e8f0fe;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
    --shadow: 0 4px 16px rgba(15, 23, 42, .08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, .14);

    --sidebar-w: 260px;
    --topbar-h: 64px;

    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
    background: var(--c-bg);
    color: var(--c-text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
h1, h2, h3, h4 { font-weight: 700; letter-spacing: -.01em; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: var(--sidebar-w);
    position: fixed;
    inset: 0 auto 0 0;
    background: #34342f;
    color: #d6d8cd;
    display: flex;
    flex-direction: column;
    z-index: 60;
    transition: transform .25s ease;
}
.app-sidebar .brand {
    display: flex; align-items: center; gap: .65rem;
    padding: 1.15rem 1.25rem;
    font-weight: 800; font-size: 1.15rem; color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.app-sidebar .brand .logo {
    width: 40px; height: 40px; border-radius: 10px;
    background: #fff; padding: 4px;
    display: grid; place-items: center;
}
.app-sidebar .brand .logo img { width: 100%; height: 100%; object-fit: contain; }
.nav-section { padding: .9rem 1rem .25rem; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: #64748b; }
.app-nav {
    flex: 1; overflow-y: auto; padding-bottom: 1rem;
    /* Scrollbar fina y discreta, integrada al sidebar oscuro (Firefox) */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.18) transparent;
}
/* Scrollbar fina y discreta (Chrome/Edge/Safari) */
.app-nav::-webkit-scrollbar { width: 6px; }
.app-nav::-webkit-scrollbar-track { background: transparent; }
.app-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 999px; }
.app-nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.28); }
.app-nav .nav-link {
    display: flex; align-items: center; gap: .75rem;
    padding: .62rem 1.1rem; margin: .1rem .6rem;
    border-radius: 10px; color: #cbd5e1; font-weight: 500; font-size: .92rem;
}
.app-nav .nav-link .ico { width: 1.25rem; text-align: center; font-size: 1.05rem; }
.app-nav .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.app-nav .nav-link.active { background: var(--c-primary); color: #fff; box-shadow: var(--shadow); }
.app-nav .nav-link .badge-count {
    margin-left: auto; background: var(--c-accent); color: #1a1205;
    border-radius: 999px; font-size: .72rem; font-weight: 700; padding: .05rem .45rem;
}

/* ---------- Main ---------- */
.app-main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.app-topbar {
    height: var(--topbar-h);
    position: sticky; top: 0; z-index: 50;
    background: rgba(255,255,255,.85); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--c-border);
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.25rem;
}
.app-topbar .menu-btn { display: none; background: none; border: 0; font-size: 1.4rem; color: var(--c-text); }
.app-topbar .page-title { font-weight: 700; font-size: 1.05rem; }
.app-topbar .spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: .6rem; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--c-primary-50); color: var(--c-primary);
    display: grid; place-items: center; font-weight: 700;
}
.app-content { padding: 1.5rem; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav { display: none; }

/* ---------- Buttons ---------- */
.btn-b2b {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    border: 1px solid transparent; border-radius: 10px;
    padding: .6rem 1.05rem; font-weight: 600; font-size: .92rem; cursor: pointer;
    transition: all .15s ease; line-height: 1.1;
}
.btn-b2b:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary-b2b { background: var(--c-primary); color: #fff; }
.btn-primary-b2b:hover { background: var(--c-primary-600); }
.btn-outline-b2b { background: #fff; border-color: var(--c-border); color: var(--c-text); }
.btn-outline-b2b:hover { border-color: var(--c-primary); color: var(--c-primary); }
.btn-ghost-b2b { background: transparent; color: var(--c-text-soft); }
.btn-ghost-b2b:hover { background: var(--c-surface-2); }
.btn-danger-b2b { background: var(--c-danger-bg); color: var(--c-danger); }
.btn-sm-b2b { padding: .4rem .7rem; font-size: .82rem; }
.btn-block-b2b { width: 100%; }

/* ---------- Cards ---------- */
.card-b2b {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-b2b.pad { padding: 1.25rem; }

/* ---------- Page header ---------- */
.page-head { margin-bottom: 1.4rem; }
.page-head h1 { font-size: 1.5rem; margin: 0; }
.page-head p { color: var(--c-text-soft); margin: .25rem 0 0; }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.stat {
    background: var(--c-surface); border: 1px solid var(--c-border);
    border-radius: var(--radius); padding: 1.15rem 1.25rem;
}
.stat .label { color: var(--c-text-soft); font-size: .85rem; font-weight: 500; }
.stat .value { font-size: 1.7rem; font-weight: 800; margin-top: .35rem; }
.stat .ico { float: right; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem; background: var(--c-primary-50); }

/* ---------- Operational summaries ---------- */
.insight-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .9rem; margin-bottom: 1.2rem; }
.insight {
    background: var(--c-surface); border: 1px solid var(--c-border);
    border-radius: var(--radius-sm); padding: .95rem 1rem;
}
.insight .label { display: block; color: var(--c-text-soft); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.insight strong { display: block; margin-top: .35rem; font-size: 1.35rem; }
.section-block { margin-top: 1.5rem; }
.section-block h2 { font-size: 1.12rem; margin: 0; }
.form-section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--c-text-soft); margin: 1.1rem 0 .7rem; }

/* ---------- Product grid ---------- */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.1rem; }
.catalog-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 1.25rem; align-items: stretch; }
.cart-aside { min-width: 0; }
/* El panel sigue al hacer scroll. align-items:stretch da altura a la columna para que el sticky funcione. */
.sticky-panel { position: sticky; top: calc(var(--topbar-h) + 1rem); align-self: start; max-height: calc(100vh - var(--topbar-h) - 2rem); overflow-y: auto; }
.mini-cart-lines { display: grid; gap: .7rem; }
.mini-cart-line { display: grid; gap: .15rem; font-size: .86rem; }
.mini-cart-line strong { color: var(--c-primary); }
.product-card {
    background: var(--c-surface); border: 1px solid var(--c-border);
    border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column;
    transition: transform .15s ease, box-shadow .15s ease;
}
.product-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.product-card .thumb { aspect-ratio: 4/3; background: var(--c-surface-2) center/cover no-repeat; position: relative; }
.product-card .thumb .tag {
    position: absolute; top: .6rem; left: .6rem;
    font-size: .68rem; font-weight: 700; padding: .2rem .55rem; border-radius: 999px;
    background: rgba(255,255,255,.92); color: var(--c-text); box-shadow: var(--shadow-sm);
}
.product-card .body { padding: .85rem .95rem 1rem; display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.product-card .sku { font-size: .72rem; color: var(--c-muted); font-weight: 600; }
.product-card .name { font-weight: 600; font-size: .98rem; line-height: 1.25; }
.product-card .price { font-weight: 800; color: var(--c-primary); margin-top: auto; }
.product-card .price small { font-weight: 600; color: var(--c-text-soft); }

/* ---------- Badges ---------- */
.badge-b2b { display: inline-flex; align-items: center; gap: .3rem; font-size: .76rem; font-weight: 700; padding: .25rem .6rem; border-radius: 999px; }
.badge-success { background: var(--c-success-bg); color: var(--c-success); }
.badge-warning { background: var(--c-warning-bg); color: var(--c-warning); }
.badge-danger { background: var(--c-danger-bg); color: var(--c-danger); }
.badge-info { background: var(--c-info-bg); color: var(--c-info); }
.badge-muted { background: #eef1f5; color: var(--c-text-soft); }

/* ---------- Tables ---------- */
.table-b2b { width: 100%; border-collapse: collapse; }
.table-b2b th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--c-text-soft); padding: .7rem .85rem; border-bottom: 1px solid var(--c-border); }
.table-b2b td { padding: .8rem .85rem; border-bottom: 1px solid var(--c-border); font-size: .92rem; }
.table-b2b tr:last-child td { border-bottom: 0; }
/* Interruptor (toggle) */
.switch { position: relative; display: inline-block; width: 52px; height: 28px; flex: 0 0 52px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; cursor: pointer; background: #c9ccc2; border-radius: 999px; transition: .2s; }
.switch .slider::before { content: ""; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: var(--shadow-sm); }
.switch input:checked + .slider { background: var(--c-primary); }
.switch input:checked + .slider::before { transform: translateX(24px); }

.table-b2b th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.table-b2b th.sortable:hover { color: var(--c-primary); }
.table-b2b tr.row-overdue td { background: #fff5f5; }
.table-b2b tr.row-overdue:hover td { background: #feecec; }
.table-wrap { overflow-x: auto; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; font-size: .86rem; margin-bottom: .35rem; }
.input-b2b, .select-b2b {
    width: 100%; padding: .62rem .8rem; border: 1px solid var(--c-border);
    border-radius: 10px; font-size: .92rem; background: #fff; color: var(--c-text);
}
.input-b2b:focus, .select-b2b:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-50); }

/* ---------- Alerts ---------- */
.alert-b2b { display: flex; gap: .75rem; align-items: flex-start; padding: .9rem 1.1rem; border-radius: var(--radius-sm); font-size: .9rem; }
.alert-warning { background: var(--c-warning-bg); color: #7c4a03; }
.alert-danger { background: var(--c-danger-bg); color: #8a1c1c; }
.alert-info { background: var(--c-info-bg); color: #1e3a8a; }
.alert-success { background: var(--c-success-bg); color: #14532d; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1.2rem; }
.toolbar .grow { flex: 1; min-width: 180px; }
.chip-group { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { border: 1px solid var(--c-border); background: #fff; border-radius: 999px; padding: .4rem .85rem; font-size: .85rem; font-weight: 600; cursor: pointer; color: var(--c-text-soft); }
.chip.active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }

/* ---------- Modal ---------- */
.modal-backdrop-b2b { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; z-index: 200; padding: 1rem; overflow-y: auto; }
/* El modal nunca supera la altura de la ventana y hace scroll interno para ver todos los campos y el botón Guardar. */
.modal-b2b { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 460px; padding: 1.5rem; max-height: 92vh; overflow-y: auto; }
.modal-b2b h3 { margin-top: 0; }

/* ---------- Panel de ayuda colapsable (?) ---------- */
.help-panel { background: #f8fafc; border: 1px solid var(--c-border, #e2e8f0); border-radius: var(--radius); margin: 0 0 1.25rem; }
.help-panel > summary { cursor: pointer; padding: .85rem 1.1rem; font-weight: 600; color: var(--c-primary); list-style: none; user-select: none; }
.help-panel > summary::-webkit-details-marker { display: none; }
.help-panel[open] > summary { border-bottom: 1px solid var(--c-border, #e2e8f0); }
.help-panel .help-body { padding: .5rem 1.25rem 1rem; font-size: .92rem; line-height: 1.55; color: #334155; }
.help-panel .help-body ul { margin: .35rem 0 .75rem; padding-left: 1.15rem; }
.help-panel .help-body li { margin: .2rem 0; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 3rem 1rem; color: var(--c-text-soft); }
.empty .big { font-size: 3rem; }
.empty.compact { padding: 1.6rem 1rem; }
.empty.compact .big { font-size: 2.1rem; }

/* ---------- Auth / landing ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero { background: linear-gradient(150deg, #34342f 0%, #3f5417 60%, #5f8d1f 100%); color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: center; }
.auth-hero .brand-logo { width: 120px; background: #fff; border-radius: 16px; padding: 14px; margin-bottom: 1.5rem; }
.auth-hero .brand-logo img { width: 100%; display: block; }
.auth-hero h1 { font-size: 2.4rem; line-height: 1.1; }
.auth-hero ul { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: .8rem; }
.auth-hero li { display: flex; gap: .6rem; align-items: center; color: #d1fae5; }
.auth-panel { display: grid; place-items: center; padding: 2rem; }
.auth-card { width: 100%; max-width: 400px; }

.helper { font-size: .82rem; color: var(--c-text-soft); }
.muted { color: var(--c-text-soft); }
.flex { display: flex; }
.between { justify-content: space-between; }
.items-center { align-items: center; }
.gap { gap: .75rem; }
.mt { margin-top: 1rem; } .mt2 { margin-top: 1.5rem; }
.text-right { text-align: right; }

/* ---------- Responsive ---------- */
.nav-toggle-cb { display: none; }
.scrim { display: none; }
@media (max-width: 992px) {
    .app-sidebar { transform: translateX(-100%); }
    .nav-toggle-cb:checked ~ .app-shell .app-sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .app-main { margin-left: 0; }
    .app-topbar .menu-btn { display: block; }
    .nav-toggle-cb:checked ~ .app-shell .scrim {
        display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 55;
    }
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-hero { display: none; }
    .catalog-layout { grid-template-columns: 1fr; }
    .sticky-panel { position: static; }
}
@media (max-width: 768px) {
    .app-content { padding: 1rem; padding-bottom: 5rem; }
    .bottom-nav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 70;
        background: #fff; border-top: 1px solid var(--c-border);
        padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
        justify-content: space-around;
    }
    .bottom-nav a {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: .15rem;
        font-size: .68rem; color: var(--c-text-soft); padding: .3rem; position: relative;
    }
    .bottom-nav a .ico { font-size: 1.25rem; }
    .bottom-nav a.active { color: var(--c-primary); font-weight: 700; }
    .bottom-nav a .dot { position: absolute; top: .1rem; right: 22%; background: var(--c-accent); color:#1a1205; border-radius: 999px; font-size: .6rem; font-weight: 800; padding: 0 .3rem; }
}
