/* ── Variables ───────────────────────────────────────── */
:root {
  --bg:        #0f1117;
  --bg2:       #1a1d27;
  --bg3:       #22263a;
  --border:    #2e3250;
  --accent:    #4f8ef7;
  --accent-h:  #3a7ce0;
  --green:     #22c55e;
  --red:       #ef4444;
  --yellow:    #eab308;
  --orange:    #f97316;
  --purple:    #a855f7;
  --text:      #e2e8f0;
  --muted:     #94a3b8;
  --sidebar-w: 240px;
}

/* ── Reset ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.px-3 { padding-left: 12px; padding-right: 12px; }
.mb-2 { margin-bottom: 8px; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-accent { color: var(--accent); }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.font-bold { font-weight: 700; }

/* ── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Toast ───────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { padding: 12px 18px; border-radius: 8px; font-size: 13px; font-weight: 500; min-width: 240px; max-width: 360px; box-shadow: 0 4px 16px #0006; animation: slideIn .25s ease; pointer-events: auto; display: flex; align-items: center; gap: 10px; }
.toast.hide { animation: slideOut .25s ease forwards; }
.toast-success { background: #14532d; border: 1px solid var(--green); color: #bbf7d0; }
.toast-error   { background: #7f1d1d; border: 1px solid var(--red);   color: #fecaca; }
.toast-info    { background: #1e3a8a; border: 1px solid var(--accent); color: #bfdbfe; }
.toast-warn    { background: #78350f; border: 1px solid var(--yellow); color: #fde68a; }
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideOut { to { opacity: 0; transform: translateX(30px); } }

/* ── Modal ───────────────────────────────────────────── */
#modal-overlay { position: fixed; inset: 0; background: #000a; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; }
#modal-box { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
#modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
#modal-title { font-size: 16px; font-weight: 700; }
#modal-close { background: none; border: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 4px; transition: .15s; }
#modal-close:hover { background: var(--bg3); color: var(--text); }
#modal-body { padding: 20px; }

/* ── Confirm ─────────────────────────────────────────── */
#confirm-overlay { position: fixed; inset: 0; background: #000a; z-index: 1100; display: flex; align-items: center; justify-content: center; }
#confirm-box { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 28px 24px; max-width: 360px; width: 100%; }
#confirm-msg { margin-bottom: 20px; font-size: 14px; line-height: 1.6; }
.confirm-btns { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Login ───────────────────────────────────────────── */
#login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; padding: 40px 36px; width: 100%; max-width: 380px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .icon { font-size: 40px; }
.login-logo h1 { font-size: 20px; font-weight: 700; margin-top: 8px; }
.login-logo p { color: var(--muted); font-size: 12px; margin-top: 4px; }
.login-error { background: #7f1d1d33; border: 1px solid var(--red); color: #fca5a5; padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; }
.login-ok { background: #14532d33; border: 1px solid var(--green); color: #86efac; padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; }
.login-card-wide { max-width: 460px; }
.login-switch { text-align: center; font-size: 12px; color: var(--muted); margin-top: 18px; }

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

/* ── Sidebar ─────────────────────────────────────────── */
#sidebar { width: var(--sidebar-w); min-width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; overflow-y: auto; z-index: 50; }
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.logo-icon { font-size: 26px; }
.logo-title { font-weight: 700; font-size: 14px; }
.logo-sub { font-size: 11px; color: var(--accent); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
#sidebar-nav { flex: 1; padding: 4px 0; }
.nav-group { border-bottom: 1px solid transparent; }
.nav-section {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted); padding: 10px 16px 6px; cursor: pointer; user-select: none;
}
.nav-section:hover { color: var(--text); }
.nav-section-chevron { font-size: 10px; transition: transform .15s; }
.nav-group.collapsed .nav-section-chevron { transform: rotate(-90deg); }
.nav-group-items { max-height: 600px; overflow: hidden; }
.nav-group.collapsed .nav-group-items { max-height: 0; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 6px 16px; color: var(--muted); font-size: 13px; cursor: pointer; border-left: 3px solid transparent; transition: .15s; user-select: none; }
.nav-item:hover { color: var(--text); background: var(--bg3); }
.nav-item.active { color: var(--text); background: var(--bg3); border-left-color: var(--accent); font-weight: 600; }
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
#user-info { font-size: 12px; color: var(--muted); margin-bottom: 8px; padding: 0 4px; }
#user-info strong { display: block; color: var(--text); font-size: 13px; }
.btn-logout { width: 100%; padding: 8px; background: var(--bg3); border: 1px solid var(--border); color: var(--muted); border-radius: 6px; font-size: 12px; transition: .15s; }
.btn-logout:hover { border-color: var(--red); color: var(--red); }

/* ── Main wrap ───────────────────────────────────────── */
#main-wrap { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
#topbar { background: var(--bg2); border-bottom: 1px solid var(--border); padding: 0 24px; height: 52px; display: flex; align-items: center; gap: 14px; justify-content: space-between; position: sticky; top: 0; z-index: 40; }
#page-title { font-size: 16px; font-weight: 700; margin-right: auto; }
#topbar-right { display: flex; align-items: center; gap: 10px; }
#page-content { padding: 24px; flex: 1; }
#sidebar-toggle { display: none; background: none; border: none; color: var(--text); font-size: 20px; padding: 4px 6px; border-radius: 6px; }
#sidebar-toggle:hover { background: var(--bg3); }
#sidebar-overlay { display: none; position: fixed; inset: 0; background: #000a; z-index: 45; }
#sidebar-overlay.show { display: block; }

/* ── Page header ─────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-header h2 { font-size: 18px; font-weight: 700; }

/* ── Buttons ─────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; border: none; transition: .15s; white-space: nowrap; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-danger { background: #7f1d1d; color: #fca5a5; border: 1px solid var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-success { background: #14532d; color: #4ade80; border: 1px solid #4ade8033; }
.btn-success:hover { background: var(--green); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ── Form ────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; letter-spacing: .3px; text-transform: uppercase; }
.input { width: 100%; background: var(--bg3); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: 9px 12px; outline: none; transition: border-color .15s; }
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--muted); }
select.input { cursor: pointer; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.usr-empresa-checks { max-height: 160px; overflow-y: auto; border: 1px solid var(--border); border-radius: 7px; padding: 10px 12px; background: var(--bg3); display: flex; flex-direction: column; gap: 8px; }
.usr-check-item { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }

/* ── Compras/Ventas: buscador con autocompletado + carrito ───── */
.buscador-wrap { position: relative; }
.autocomplete-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 20; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; margin-top: 4px; max-height: 220px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.autocomplete-item { padding: 9px 12px; font-size: 13px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--bg3); }
.autocomplete-price { color: var(--muted); font-size: 12px; white-space: nowrap; }
.autocomplete-empty { padding: 10px 12px; font-size: 13px; color: var(--muted); }
.autocomplete-crear { color: var(--accent); font-weight: 600; }
.selected-chip { display: inline-flex; align-items: center; gap: 8px; background: var(--bg3); border: 1px solid var(--border); border-radius: 20px; padding: 6px 8px 6px 14px; font-size: 13px; }
.chip-remove { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 50%; }
.chip-remove:hover { background: var(--red); color: #fff; }
.carrito-input { max-width: 100px; }
.carrito-lote-row td { padding-top: 0; border-top: none; }
.carrito-lote-input { max-width: 220px; }
.doc-total-row { text-align: right; font-size: 16px; margin: 14px 0; padding-top: 12px; border-top: 1px solid var(--border); }

/* ── Nueva Venta: vista de página completa (no modal) ─────────── */
.venta-layout { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.venta-main { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
.venta-sidebar { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 20px; position: sticky; top: 16px; }
.venta-total-box { text-align: center; background: var(--bg3); border: 1px solid var(--accent); border-radius: 10px; padding: 16px; margin: 16px 0; }
.venta-total-label { font-size: 11px; font-weight: 700; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; margin-bottom: 4px; }
.venta-total-monto { font-size: 36px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.btn-lg { padding: 14px; font-size: 16px; }
.section-subtitle { font-size: 15px; font-weight: 700; color: var(--text); margin: 0; }
.atajos-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; margin-bottom: 16px; font-size: 12px; color: var(--muted); }
.atajos-bar kbd { background: var(--bg3); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; font-family: inherit; font-size: 11px; font-weight: 700; color: var(--text); }
.atajos-tutorial-link { margin-left: auto; color: var(--accent); font-weight: 600; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 36px; }
.search-icon { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

/* ── Password toggle (ojito) ────────────────────────── */
.password-wrap { position: relative; }
.password-wrap .input { padding-right: 40px; }
.password-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--muted); padding: 6px; border-radius: 6px; display: flex; align-items: center; justify-content: center; transition: .15s; }
.password-toggle:hover { color: var(--text); background: var(--bg3); }
.password-toggle svg { width: 16px; height: 16px; display: block; }

/* ── Filters bar ─────────────────────────────────────── */
.filters { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters .input { width: auto; flex: 1; min-width: 160px; max-width: 260px; }

/* ── Table ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
thead th { background: var(--bg3); color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; padding: 10px 14px; text-align: left; white-space: nowrap; }
tbody td { padding: 11px 14px; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover td { background: #ffffff05; }
.td-actions { display: flex; gap: 6px; }
.empty-row td { text-align: center; padding: 48px; color: var(--muted); font-size: 13px; }

/* ── Badges ──────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; gap: 4px; }
.badge-green  { background: #14532d44; color: #4ade80; border: 1px solid #4ade8033; }
.badge-red    { background: #7f1d1d44; color: #f87171; border: 1px solid #f8717133; }
.badge-yellow { background: #78350f44; color: #fbbf24; border: 1px solid #fbbf2433; }
.badge-blue   { background: #1e3a8a44; color: #60a5fa; border: 1px solid #60a5fa33; }
.badge-purple { background: #4c1d9544; color: #c4b5fd; border: 1px solid #c4b5fd33; }
.badge-gray   { background: #1e293b; color: var(--muted); border: 1px solid var(--border); }
.badge-orange { background: #7c2d1244; color: #fb923c; border: 1px solid #fb923c33; }

/* ── Stats cards ─────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; }
.stat-card .stat-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.stat-card .stat-value { font-size: 30px; font-weight: 800; margin: 4px 0; }
.stat-card .stat-sub { font-size: 11px; color: var(--muted); }
.stat-card.green { border-color: #4ade8033; }
.stat-card.green .stat-value { color: var(--green); }
.stat-card.red { border-color: #f8717133; }
.stat-card.red .stat-value { color: var(--red); }
.stat-card.yellow { border-color: #fbbf2433; }
.stat-card.yellow .stat-value { color: var(--yellow); }
.stat-card.blue { border-color: #60a5fa33; }
.stat-card.blue .stat-value { color: var(--accent); }

/* ── Section card ────────────────────────────────────── */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.card-title { font-size: 14px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }

/* ── Spinner ─────────────────────────────────────────── */
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-page { display: flex; align-items: center; justify-content: center; height: 200px; }
.btn .spinner { width: 14px; height: 14px; border-width: 2px; }

/* ── Inventario specific ─────────────────────────────── */
.inv-select-bar { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.inv-select-bar .input { max-width: 240px; }
.stock-ok   { color: var(--green); font-weight: 700; }
.stock-low  { color: var(--yellow); font-weight: 700; }
.stock-zero { color: var(--red); font-weight: 700; }

/* ── Reportes ────────────────────────────────────────── */
.report-grid, .reports-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.report-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.report-card h4 { font-size: 14px; font-weight: 700; }
.report-card p { font-size: 12px; color: var(--muted); flex: 1; }
.mb-3 { margin-bottom: 12px; }
.stat-value.ok     { color: var(--green); }
.stat-value.warn   { color: var(--yellow); }
.stat-value.danger { color: var(--red); }

/* ── Plan banner ─────────────────────────────────────── */
.plan-banner { padding: 10px 24px; font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.plan-banner-warn   { background: #78350f88; border-bottom: 1px solid var(--yellow); color: #fde68a; }
.plan-banner-danger { background: #7f1d1d88; border-bottom: 1px solid var(--red);    color: #fecaca; }

/* ── Plan modal ──────────────────────────────────────── */
.plan-status-card { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 18px; }
.plan-info-row { display: flex; gap: 10px; font-size: 12px; margin-top: 5px; color: var(--muted); }
.plan-info-row span { min-width: 110px; }
.plan-info-row strong { color: var(--text); }
.plan-section { padding: 14px 0; border-top: 1px solid var(--border); }
.plan-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 10px; }
.plan-danger-section { padding-top: 16px; border-top: 1px solid #f8717133; }

/* ── Import Excel ────────────────────────────────────── */
.import-drop-zone { border: 2px dashed var(--border); border-radius: 10px; padding: 36px 24px; text-align: center; cursor: pointer; transition: .2s; color: var(--muted); }
.import-drop-zone:hover, .import-drop-zone.drag-over { border-color: var(--accent); background: #4f8ef710; color: var(--text); }
.import-summary { display: flex; gap: 12px; justify-content: center; margin-bottom: 4px; }
.import-stat { flex: 1; text-align: center; padding: 16px 8px; border-radius: 8px; border: 1px solid var(--border); }
.import-stat-ok  { border-color: #4ade8033; background: #14532d22; }
.import-stat-skip { border-color: var(--border); background: var(--bg3); }
.import-stat-err { border-color: #f8717133; background: #7f1d1d22; }
.import-stat-num   { font-size: 28px; font-weight: 800; }
.import-stat-ok  .import-stat-num  { color: var(--green); }
.import-stat-err .import-stat-num  { color: var(--red); }
.import-stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; font-weight: 600; margin-top: 2px; }

/* ── Tabs ────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); padding-bottom: 0; }
.tab-btn { background: none; border: none; padding: 8px 18px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; border-radius: 6px 6px 0 0; transition: .15s; }
.tab-btn:hover { color: var(--text); background: var(--bg3); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); background: none; }
.tab-panel { padding-top: 20px; }

/* ── Badges extra ────────────────────────────────────── */
.badge-ok     { background: #d1fae5; color: #065f46; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-danger { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-warn   { background: #fef3c7; color: #92400e; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.req { color: var(--red); }

/* ── Responsive (tablets y móviles) ───────────────────── */
@media (max-width: 1024px) {
  #sidebar { transform: translateX(-100%); transition: transform .25s; box-shadow: 4px 0 24px #0008; }
  #sidebar.open { transform: translateX(0); }
  #main-wrap { margin-left: 0; }
  #sidebar-toggle { display: block; }
  .venta-layout { grid-template-columns: 1fr; }
  .venta-sidebar { position: static; }
}

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