:root {
    --bg: #eceef2;
    --panel: #f8f9fb;
    --surface: #ffffff;
    --ink: #1f2a44;
    --muted: #8091ab;
    --accent: #ff4f2f;
    --accent-dark: #e74628;
    --line: #e1e7f0;
    --ok: #22b07d;
    --radius: 18px;
    --shadow: 0 14px 32px rgba(22, 34, 57, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Nunito Sans', sans-serif;
    background: radial-gradient(circle at top right, #dbe1ea 0%, var(--bg) 42%, #e7ebf1 100%);
    color: var(--ink);
}

h1, h2, h3 {
    font-family: 'Poppins', sans-serif;
    margin: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px 1fr;
}

.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--line);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 88px;
}

.brand-logo,
.auth-logo {
    max-width: 130px;
    width: 100%;
    height: auto;
}

.brand-fallback {
    display: none;
    font-family: 'Poppins', sans-serif;
    font-weight: 800;
    color: var(--ink);
    opacity: 0.75;
}

.menu {
    display: grid;
    gap: 10px;
}

.menu-item {
    border-radius: 16px;
    padding: 14px 16px;
    font-weight: 800;
    color: var(--muted);
    transition: all .2s ease;
}

.menu-item:hover {
    background: #f1f5fb;
    color: var(--ink);
}

.menu-item.active {
    background: var(--accent);
    color: #fff;
    box-shadow: var(--shadow);
}

.logout {
    margin-top: auto;
}

.content {
    padding: 28px;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 22px;
}

.topbar h1 {
    font-size: 2rem;
    font-weight: 900;
    text-transform: uppercase;
}

.sidebar-toggle {
    display: none;
    border: 0;
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    font-size: 1.1rem;
    padding: 8px 10px;
}

.card {
    background: var(--surface);
    border-radius: 30px;
    border: 1px solid var(--line);
    box-shadow: 0 3px 12px rgba(27, 38, 60, .04);
    padding: 26px;
}

.kpis {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.kpi p {
    margin: 8px 0 0;
    font-size: 2.1rem;
    font-weight: 900;
}

.kpi h3 {
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-size: .85rem;
}

.charts-grid {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 20px;
}

.charts-grid canvas {
    width: 100% !important;
    max-height: 420px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.search-form {
    display: flex;
    gap: 8px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: #f5f8fc;
    color: var(--ink);
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 1rem;
    font-family: 'Nunito Sans', sans-serif;
}

label span {
    display: block;
    font-size: .75rem;
    color: var(--muted);
    margin: 8px 0;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 800;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 980px;
}

th,
td {
    text-align: left;
    padding: 16px 10px;
    border-bottom: 1px solid var(--line);
}

th {
    color: var(--muted);
    text-transform: uppercase;
    font-size: .78rem;
    letter-spacing: .06em;
}

td {
    font-size: 1.25rem;
    font-weight: 700;
}

.stock-breakdown {
    min-width: 240px;
    font-size: 1.05rem;
    font-weight: 600;
    color: #2f3a4f;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    background: #edf2fa;
    color: #4079d8;
    font-size: .82rem;
    font-weight: 900;
    text-transform: uppercase;
}

.btn {
    border: 0;
    border-radius: 16px;
    padding: 12px 18px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .05em;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
}

.btn-small {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: .86rem;
}

.btn-primary {
    color: #fff;
    background: linear-gradient(180deg, #ff5838 0%, var(--accent) 100%);
}

.btn-primary:hover {
    background: linear-gradient(180deg, #ff4a29 0%, var(--accent-dark) 100%);
}

.btn:disabled {
    opacity: .72;
    cursor: not-allowed;
}

#saveStockAdjustment.is-loading {
    position: relative;
}

#saveStockAdjustment.is-loading::after {
    content: "";
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #ffffff;
    display: inline-block;
    margin-left: 8px;
    vertical-align: -2px;
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.btn-danger {
    color: #fff;
    background: #c9d2df;
}

.btn-light {
    color: var(--ink);
    background: #edf2f8;
}

.btn-light.active {
    background: var(--accent);
    color: #fff;
}

.btn-link,
.link-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-weight: 800;
    cursor: pointer;
    padding: 8px;
}

.btn-ghost {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.auth-card {
    width: min(500px, 100%);
    background: var(--surface);
    border-radius: 34px;
    padding: 34px;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
}

.auth-logo-wrap {
    display: grid;
    place-items: center;
    margin-bottom: 18px;
    min-height: 120px;
}

.auth-form {
    display: grid;
    gap: 12px;
}

.form-error {
    margin: 0;
    color: #c82344;
    font-weight: 700;
}

.muted {
    color: var(--muted);
    margin-top: 4px;
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    z-index: 40;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    backdrop-filter: blur(4px);
    background: rgba(44, 56, 79, .45);
}

.modal-content {
    position: relative;
    width: min(520px, calc(100vw - 26px));
    background: #fff;
    border-radius: 26px;
    padding: 24px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 14px;
}

.modal-close {
    position: absolute;
    right: 16px;
    top: 10px;
    border: 0;
    background: transparent;
    font-size: 1.8rem;
    color: var(--muted);
    cursor: pointer;
}

.toggle-row,
.preset-row,
.quantity-row,
.modal-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.preset-row {
    grid-template-columns: repeat(5, 1fr);
}

.quantity-row {
    grid-template-columns: 56px 1fr 56px;
    align-items: center;
}

.qty-display {
    text-align: center;
    font-family: 'Poppins', sans-serif;
    font-size: 2.1rem;
    font-weight: 900;
}

.preset {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 10px;
    padding: 8px;
    font-weight: 800;
    cursor: pointer;
}

.check-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    font-weight: 800;
    color: var(--ink);
}

.check-item input {
    width: 18px;
    height: 18px;
}

.toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-left: 5px solid var(--ok);
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: var(--shadow);
    font-weight: 800;
    z-index: 80;
}

@media (max-width: 1080px) {
    .kpis {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 10px;
    }

    .kpi {
        padding: 14px;
        border-radius: 18px;
    }

    .kpi h3 {
        font-size: .72rem;
        letter-spacing: .04em;
    }

    .kpi p {
        font-size: 2rem;
        margin-top: 4px;
        line-height: 1;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        width: 260px;
        height: 100vh;
        z-index: 50;
        transition: left .2s ease;
        box-shadow: var(--shadow);
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-toggle {
        display: inline-block;
    }

    .content {
        padding: 18px;
    }

    .topbar h1 {
        font-size: 1.5rem;
    }

    .preset-row {
        grid-template-columns: repeat(3, 1fr);
    }

    .modal-content {
        border-radius: 20px;
        padding: 16px;
    }

    .inventory-table-wrap {
        overflow: visible;
    }

    .inventory-table {
        min-width: 0;
        width: 100%;
        border-collapse: separate;
        border-spacing: 0 12px;
    }

    .inventory-table thead {
        display: none;
    }

    .inventory-table tbody,
    .inventory-table tr,
    .inventory-table td {
        display: block;
        width: 100%;
    }

    .inventory-table tr {
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 16px;
        padding: 12px;
        box-shadow: 0 2px 8px rgba(27, 38, 60, .05);
    }

    .inventory-table td {
        border-bottom: 0;
        padding: 8px 4px;
        font-size: 1rem;
        font-weight: 700;
    }

    .inventory-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 4px;
        font-size: .72rem;
        text-transform: uppercase;
        letter-spacing: .06em;
        color: var(--muted);
        font-weight: 800;
    }

    .inventory-table td[data-label="Sabor"] {
        font-size: 1.6rem;
        line-height: 1.15;
        margin-bottom: 2px;
    }

    .inventory-table td[data-label="Sabor"]::before {
        margin-bottom: 6px;
    }

    .inventory-table td[data-label="Acción"] .btn {
        width: 100%;
    }
}
