/* ============================================================
   BASE STYLES — Minimal, Formal
   ============================================================ */

/* --- Variables --- */
:root {
    --bg-primary:    #f5f5f4;
    --bg-secondary:  #ffffff;
    --bg-tertiary:   #eeede9;

    --text-primary:   #1c1c1c;
    --text-secondary: #4a4a4a;
    --text-muted:     #888882;

    --border:         #d6d3cc;
    --border-strong:  #b0ada5;

    --accent:         #2563eb;
    --accent-hover:   #1d4ed8;
    --accent-light:   #eff6ff;

    --success:        #16a34a;
    --success-light:  #f0fdf4;
    --danger:         #dc2626;
    --danger-light:   #fef2f2;
    --warning:        #ca8a04;
    --warning-light:  #fefce8;

    --radius-sm: 4px;
    --radius:    6px;
    --radius-lg: 8px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow:    0 2px 6px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
    --bg-primary:    #141414;
    --bg-secondary:  #1f1f1f;
    --bg-tertiary:   #2a2a2a;

    --text-primary:   #e8e8e8;
    --text-secondary: #aaaaaa;
    --text-muted:     #666660;

    --border:         #333330;
    --border-strong:  #4a4a46;

    --accent:         #3b82f6;
    --accent-hover:   #60a5fa;
    --accent-light:   rgba(59, 130, 246, 0.08);

    --success:        #22c55e;
    --success-light:  rgba(34, 197, 94, 0.08);
    --danger:         #ef4444;
    --danger-light:   rgba(239, 68, 68, 0.08);
    --warning:        #eab308;
    --warning-light:  rgba(234, 179, 8, 0.08);

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow:    0 2px 8px rgba(0,0,0,0.35);
}

/* --- Reset --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* --- Base --- */
html {
    font-size: 15px;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background 0.2s, color 0.2s;
}

/* --- Tipografía --- */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }
h5, h6 { font-size: 0.9rem; }

p {
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

small {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ============================================================
   NAVBAR
   ============================================================ */
.navbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: var(--shadow-sm);
}

.navbar-container {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0 1.5rem;
    height: 50px;
    max-width: 100%;
}

/* --- Brand --- */
.navbar-brand {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin-right: 1rem;
    white-space: nowrap;
    flex-shrink: 0;
    text-decoration: none;
}

.navbar-brand:hover {
    text-decoration: none;
    color: var(--accent);
}

/* --- Menu list --- */
.navbar-menu {
    display: flex;
    align-items: center;
    list-style: none;
    gap: 0.1rem;
    flex: 1;
}

/* --- Item (wraps link + dropdown) --- */
.navbar-item {
    position: relative;
}

/* --- Link --- */
.navbar-link {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
    user-select: none;
}

.navbar-link:hover,
.navbar-item:hover > .navbar-link {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
}

/* --- Dropdown arrow --- */
.dropdown-arrow {
    display: inline-flex;
    align-items: center;
    opacity: 0.45;
    transition: transform 0.2s;
    font-size: 0;
    width: 10px;
    height: 10px;
}

.dropdown-arrow::before {
    content: "";
    display: block;
    width: 10px;
    height: 10px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234a4a4a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
}

[data-theme="dark"] .dropdown-arrow::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23aaaaaa' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

.navbar-item:hover > .navbar-link .dropdown-arrow {
    transform: rotate(180deg);
    opacity: 0.7;
}

/* --- Dropdown menu --- */
.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.3rem;
    z-index: 300;
}

.navbar-item.open > .dropdown-menu {
    display: block;
}

.dropdown-item {
    display: block;
    padding: 0.4rem 0.65rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
}

.dropdown-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 0.3rem 0.25rem;
}

/* --- User icon --- */
.user-icon {
    display: inline-flex;
    align-items: center;
    font-size: 0;
    width: 16px;
    height: 16px;
}

.user-icon::before {
    content: "";
    display: block;
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234a4a4a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
}

[data-theme="dark"] .user-icon::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23aaaaaa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3C/svg%3E");
}

/* --- Theme toggle --- */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
    transition: background 0.15s;
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
}

.theme-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    width: 16px;
    height: 16px;
}

.theme-toggle-icon::before {
    content: "";
    display: block;
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234a4a4a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='5'/%3E%3Cline x1='12' y1='1' x2='12' y2='3'/%3E%3Cline x1='12' y1='21' x2='12' y2='23'/%3E%3Cline x1='4.22' y1='4.22' x2='5.64' y2='5.64'/%3E%3Cline x1='18.36' y1='18.36' x2='19.78' y2='19.78'/%3E%3Cline x1='1' y1='12' x2='3' y2='12'/%3E%3Cline x1='21' y1='12' x2='23' y2='12'/%3E%3Cline x1='4.22' y1='19.78' x2='5.64' y2='18.36'/%3E%3Cline x1='18.36' y1='5.64' x2='19.78' y2='4.22'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
}

[data-theme="dark"] .theme-toggle-icon::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23aaaaaa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z'/%3E%3C/svg%3E");
}

/* --- Mobile toggle button --- */
.navbar-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    margin-left: auto;
    align-items: center;
}

.navbar-toggle-icon {
    font-size: 0;
    display: inline-flex;
    align-items: center;
    width: 18px;
    height: 18px;
}

.navbar-toggle-icon::before {
    content: "";
    display: block;
    width: 18px;
    height: 18px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234a4a4a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='3' y1='12' x2='21' y2='12'/%3E%3Cline x1='3' y1='6' x2='21' y2='6'/%3E%3Cline x1='3' y1='18' x2='21' y2='18'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
}

[data-theme="dark"] .navbar-toggle-icon::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23aaaaaa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='3' y1='12' x2='21' y2='12'/%3E%3Cline x1='3' y1='6' x2='21' y2='6'/%3E%3Cline x1='3' y1='18' x2='21' y2='18'/%3E%3C/svg%3E");
}

/* --- Navbar Responsive --- */
@media (max-width: 900px) {
    .navbar-toggle {
        display: flex;
    }

    .navbar-container {
        flex-wrap: wrap;
        height: auto;
        padding: 0.5rem 1rem;
        position: relative;
    }

    .navbar-brand {
        flex: 1;
    }

    .navbar-menu {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        padding: 0.5rem 0;
        gap: 0.1rem;
        border-top: 1px solid var(--border);
        margin-top: 0.5rem;
    }

    .navbar-menu.open {
        display: flex;
    }

    .navbar-item {
        width: 100%;
    }

    .navbar-link {
        width: 100%;
        justify-content: space-between;
    }

    .dropdown-menu {
        position: static;
        box-shadow: none;
        border: none;
        border-left: 2px solid var(--border);
        border-radius: 0;
        margin-left: 0.75rem;
        padding: 0.2rem 0;
    }

    .navbar-item:hover > .dropdown-menu {
        display: none;
    }

    .navbar-item.open > .dropdown-menu {
        display: block;
    }

    .navbar-item.open > .navbar-link .dropdown-arrow {
        transform: rotate(180deg);
        opacity: 0.7;
    }
}

/* ============================================================
   LAYOUT
   ============================================================ */
.container {
    max-width: 100%;
    padding: 1rem 2rem;
}

.container-narrow {
    max-width: 1400px;
    margin: 0 auto;
}

/* --- Header de página --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h1 {
    font-size: 1.4rem;
    font-weight: 600;
}

.page-header .page-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-lg {
    padding: 1.5rem;
}

/* ============================================================
   GRIDS DE DASHBOARD
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

@media (max-width: 1100px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .stats-grid,
    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   STAT BLOCKS (KPIs)
   ============================================================ */
.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0.4rem 0 0;
}

.stat-value-md {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0.3rem 0 0;
}

.stat-value-sm {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0.25rem 0 0;
}

.stat-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0.4rem 0 0;
}

/* ============================================================
   LIST ROWS (proveedores, stock bajo, rankings, etc.)
   ============================================================ */
.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.list-row:first-child {
    padding-top: 0;
}

.list-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    line-height: 1.4;
}

.btn:hover {
    background: var(--bg-tertiary);
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.btn-success:hover {
    opacity: 0.9;
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover {
    opacity: 0.9;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.6rem 1.2rem;
    font-size: 0.95rem;
}

.btn:disabled,
.btn.disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* ============================================================
   TABLAS
   ============================================================ */
.table-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 500px;
}

thead {
    background: var(--bg-tertiary);
}

th {
    padding: 0.7rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--bg-tertiary);
}

td.text-right, th.text-right {
    text-align: right;
}

td.text-center, th.text-center {
    text-align: center;
}

table.table-sm th,
table.table-sm td {
    padding: 0.5rem 0.75rem;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 1rem;
    min-width: 0; /* previene overflow en grid */
}

.form-group:last-child {
    margin-bottom: 0;
}

label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
input[type="tel"],
input[type="url"],
select,
textarea {
    width: 100%;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

input[type="text"]:hover,
input[type="email"]:hover,
input[type="password"]:hover,
input[type="number"]:hover,
input[type="date"]:hover,
input[type="search"]:hover,
input[type="tel"]:hover,
input[type="url"]:hover,
select:hover,
textarea:hover {
    border-color: var(--border-strong);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* El ícono nativo del datepicker no se ve bien en dark mode sin esto */
input[type="date"] {
    color-scheme: light;
}

[data-theme="dark"] input[type="date"] {
    color-scheme: dark;
}

input:disabled,
select:disabled,
textarea:disabled,
input[readonly],
select[readonly],
textarea[readonly] {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.75;
}

/* ============================================================
   CHECKBOXES
   ============================================================ */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 19px;
    height: 19px;
    margin: 0;
    flex-shrink: 0;
    border: 1.5px solid var(--border-strong);
    border-radius: 4px;
    background: var(--bg-secondary);
    cursor: pointer;
    position: relative;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

input[type="checkbox"]:hover {
    border-color: var(--accent);
}

input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

input[type="checkbox"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-light), 0 0 0 1px var(--accent);
}

input[type="checkbox"]:disabled {
    background: var(--bg-tertiary);
    border-color: var(--border);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Cuando un form-group contiene un checkbox, lo acomodamos en fila
   (checkbox + label a la par) en vez de apilado como los demás campos */
.form-group:has(input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.form-group:has(input[type="checkbox"]) label {
    order: 2;
    margin: 0;
    cursor: pointer;
}

.form-group:has(input[type="checkbox"]) input[type="checkbox"] {
    order: 1;
}

.form-help {
    font-size: 0.775rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.form-error {
    font-size: 0.775rem;
    color: var(--danger);
    margin-top: 0.15rem;
}

.form-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.form-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    padding-top: 1rem;
    margin-top: 1rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

/* ============================================================
   FILTER BAR — campos en línea (ej. rango de fechas + botón)
   ============================================================ */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.9rem;
}

.filter-bar .form-group {
    margin-bottom: 0;
    min-width: 150px;
}

@media (max-width: 640px) {
    .filter-bar {
        width: 100%;
    }

    .filter-bar .form-group {
        flex: 1 1 140px;
    }

    .filter-bar .btn {
        flex: 1 1 100%;
    }
}

/* ============================================================
   SELECT2 — fix de desbordamiento
   El truco es usar position:relative + overflow:hidden en el
   contenedor padre, y forzar width/max-width via CSS con mayor
   especificidad que el style inline que inyecta Select2.
   ============================================================ */

/* Contenedor raíz de Select2 */
.select2-container {
    max-width: 100% !important;
    min-width: 10em;
    box-sizing: border-box !important;
}

/* Cuando está dentro de un form-group */
.form-group .select2-container {
    width: 100% !important;
    max-width: 100% !important;
}

/* El span interno que Select2 renderiza también puede desbordarse */
.select2-container .select2-selection {
    box-sizing: border-box !important;
    max-width: 100% !important;
}

/* El texto renderizado dentro del select no debe empujar el ancho */
.select2-container--default .select2-selection--single .select2-selection__rendered {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    box-sizing: border-box;
}

/* Multiple: los tags tampoco deben romper el layout */
.select2-container--default .select2-selection--multiple {
    overflow: hidden;
}

/* Dropdown: se posiciona fuera del flujo, necesita z-index alto pero
   no afecta el ancho del trigger */
.select2-container--default .select2-dropdown {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    z-index: 1050;
    box-sizing: border-box;
}

.select2-container--default .select2-results__option {
    color: var(--text-primary) !important;
    padding: 0.45rem 0.75rem;
    font-size: 0.875rem;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: var(--accent) !important;
    color: white !important;
}

.select2-container--default .select2-results__option[aria-selected="true"] {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    background: var(--bg-primary) !important;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary) !important;
    padding: 0.4rem 0.65rem;
    font-size: 0.875rem;
    width: 100%;
    box-sizing: border-box;
}

.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    min-height: 36px;
    box-sizing: border-box !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--text-primary) !important;
    line-height: 34px;
    padding: 0 0.75rem;
    font-size: 0.875rem;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 34px;
}

.select2-container--default .select2-results__option--disabled {
    color: var(--text-muted) !important;
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.55rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.badge-default  { background: var(--bg-tertiary); color: var(--text-secondary); }
.badge-primary  { background: var(--accent-light); color: var(--accent); }
.badge-success  { background: var(--success-light); color: var(--success); }
.badge-danger   { background: var(--danger-light); color: var(--danger); }
.badge-warning  { background: var(--warning-light); color: var(--warning); }
.badge-muted    { background: var(--bg-tertiary); color: var(--text-muted); }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.9rem 1rem;
    border-radius: var(--radius);
    border: 1px solid;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.alert-success { background: var(--success-light); border-color: var(--success); color: var(--success); }
.alert-danger  { background: var(--danger-light);  border-color: var(--danger);  color: var(--danger);  }
.alert-warning { background: var(--warning-light); border-color: var(--warning); color: var(--warning); }
.alert-info    { background: var(--accent-light);  border-color: var(--accent);  color: var(--accent);  }

.alert p { color: inherit; margin: 0; }

/* ============================================================
   TOASTS
   ============================================================ */
.toast {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    background: var(--text-primary);
    color: var(--bg-secondary);
    padding: 0.7rem 1.1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 9999;
    max-width: 340px;
}

.toast.success { background: var(--success); color: white; }
.toast.error   { background: var(--danger);  color: white; }
.toast.warning { background: var(--warning); color: white; }

/* ============================================================
   PAGINACIÓN
   ============================================================ */
.pagination {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    padding: 1rem 0;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    text-decoration: none;
    transition: all 0.15s;
}

.pagination a:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
}

.pagination .current {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    font-weight: 600;
}

.pagination .disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-muted);
    gap: 0.5rem;
}

.empty-state-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 1rem;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.875rem;
    color: var(--text-muted);
    max-width: 320px;
}

/* ============================================================
   DIVIDER
   ============================================================ */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1rem 0;
}

/* ============================================================
   UTILIDADES
   ============================================================ */
.text-muted     { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-success   { color: var(--success) !important; }
.text-danger    { color: var(--danger) !important; }
.text-warning   { color: var(--warning) !important; }
.text-accent    { color: var(--accent) !important; }
.text-center    { text-align: center; }
.text-right     { text-align: right; }
.text-bold      { font-weight: 600; }
.text-sm        { font-size: 0.8rem; }

.flex           { display: flex; }
.flex-between   { display: flex; justify-content: space-between; align-items: center; }
.flex-center    { display: flex; align-items: center; gap: 0.5rem; }
.flex-wrap      { flex-wrap: wrap; }
.gap-1          { gap: 0.5rem; }
.gap-2          { gap: 1rem; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }

.w-full { width: 100%; }

/* ============================================================
   MODAL
   ============================================================ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    backdrop-filter: blur(2px);
}

.modal.hidden {
    display: none;
}

#modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 520px;
    max-height: 88vh;
    overflow-y: auto;
    padding: 1.5rem;
    position: relative;
    /* Crítico: el modal tiene ancho definido, así Select2 mide bien */
    box-sizing: border-box;
}

/* ============================================================
   RESPONSIVE GLOBAL
   ============================================================ */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .form-grid-2,
    .form-grid-3 {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    th, td {
        padding: 0.55rem 0.75rem;
        font-size: 0.82rem;
    }

    .navbar {
        padding: 0 1rem;
    }

    .form-actions {
        justify-content: stretch;
    }

    .form-actions .btn {
        flex: 1;
        justify-content: center;
    }

    .toast {
        left: 1rem;
        right: 1rem;
        max-width: none;
        bottom: 1rem;
    }
}

@media (max-width: 600px) {
    #modal-content {
        max-width: 100%;
        max-height: 92vh;
        padding: 1.25rem;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        box-sizing: border-box;
    }
}

/* Sizing your bell icon */
.bell-icon {
    width: 1rem;
    height: 1rem;
    color: var(--text-secondary);
}

.dropdown-item-text {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

/* Notification timestamp styling */
.dropdown-item-time {
    font-style: normal;
    font-size: 0.60rem;
    color: var(--text-muted);
}

/* Empty state styling */
.dropdown-empty {
    padding: 24px 16px;
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
    background-color: var(--bg-secondary);
}

/* ============================================================
   AJUSTE DE STOCK — extras puntuales de la vista
   ============================================================ */
.stock-items {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 0.75rem;
    margin-bottom: 1rem;
}

.stock-item {
    cursor: pointer;
}

td .btn + .btn {
    margin-left: 0.4rem;
}

#modal-content.modal-lg {
    max-width: 760px;
}

.stock-items-lg {
    max-height: 55vh;
}

.form-error ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
