:root {
  --bg: #eef1f7;
  --panel: #ffffff;
  --panel-2: #f5f6fa;
  --border: #e4e7f0;
  --text: #1f2430;
  --text-dim: #8a91a3;

  --sidebar: #101a2e;
  --sidebar-hover: #1a2740;
  --sidebar-active: #3457f0;
  --sidebar-text-dim: #93a0c2;

  --primary: #3457f0;
  --primary-hover: #2942c4;
  --success: #16a35a;
  --success-hover: #128a49;
  --danger: #e14b4b;
  --danger-hover: #c73838;
  --accent: #e0a800;
  --price: #dd5a35;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 26, 46, 0.06), 0 1px 12px rgba(16, 26, 46, 0.04);
}

* { box-sizing: border-box; }

.lucide { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; vertical-align: middle; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

/* ---------------------------------------------------------------- layout */
.app-layout {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 100vh;
}

#sidebar {
  background: var(--sidebar);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), #6f8dff);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.brand .logo .lucide { width: 20px; height: 20px; color: white; }
.brand .names { line-height: 1.15; overflow: hidden; }
.brand .names .l1 { color: #ffffff; font-weight: 700; font-size: 13px; letter-spacing: 0.4px; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .names .l2 { color: #ff8a5c; font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  color: var(--sidebar-text-dim);
  font-weight: 500;
}
.nav-link .ic { font-size: 16px; width: 18px; text-align: center; }
.nav-link .lucide { width: 17px; height: 17px; }
.nav-link:hover { background: var(--sidebar-hover); color: #ffffff; }
.nav-link.active { background: var(--sidebar-active); color: #ffffff; box-shadow: 0 4px 12px rgba(52, 87, 240, 0.35); }

.sidebar-footer {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px; margin-top: 8px; border-top: 1px solid rgba(255,255,255,0.08);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #6f8dff, var(--primary));
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; position: relative;
}
.avatar .dot {
  position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--success); border: 2px solid var(--sidebar);
}
.sidebar-footer .who { line-height: 1.2; flex: 1; overflow: hidden; }
.sidebar-footer .who .name { color: #ffffff; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .who .rol { color: var(--sidebar-text-dim); font-size: 11px; }
.icon-btn-logout { background: transparent; border: none; color: var(--sidebar-text-dim); cursor: pointer; font-size: 15px; padding: 6px; border-radius: 8px; display: flex; }
.icon-btn-logout:hover { background: var(--sidebar-hover); color: #ff8a8a; }
.icon-btn-logout .lucide { width: 16px; height: 16px; }

.content { padding: 0; overflow-x: hidden; display: flex; flex-direction: column; min-height: 100vh; }
.content-inner { padding: 22px 26px 30px; flex: 1; overflow-x: auto; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 26px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar .title { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 700; }
.topbar .title .ic { font-size: 20px; }
.topbar .title .lucide { width: 21px; height: 21px; color: var(--primary); }
.topbar .actions { display: flex; align-items: center; gap: 8px; }

/* ---------------------------------------------------------------- comun */
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 700; }

.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.grow { flex: 1; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--text);
  transition: filter 0.15s, background 0.15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn .lucide { width: 15px; height: 15px; }
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline-primary { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: var(--success-hover); }
.btn-accent { background: var(--accent); color: #241a00; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-pill { border-radius: 999px; }

input, select, textarea {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label { font-size: 12px; color: var(--text-dim); display: block; margin-bottom: 4px; }
label.inline-label { display: inline; margin: 0; }

.field { margin-bottom: 10px; }

.search-input { position: relative; }
.search-input input { width: 100%; padding-right: 40px; }
.search-input .ic { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-dim); pointer-events: none; }
.search-input .ic .lucide { width: 16px; height: 16px; }

.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  display: flex;
  box-shadow: var(--shadow);
}
.card .bar { width: 6px; flex-shrink: 0; }
.card .body { padding: 14px 16px; flex: 1; }
.card .title { font-size: 12px; color: var(--text-dim); }
.card .value { font-size: 21px; font-weight: 700; margin-top: 2px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }

.panel { background: var(--panel); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  position: sticky;
  top: 0;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--panel-2); }
tbody tr.selected { background: #e8edff; }
tbody tr.low-stock td { color: var(--danger); font-weight: 600; }
.table-wrap { max-height: 62vh; overflow: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel); box-shadow: var(--shadow); }
.text-right { text-align: right; }
.text-center { text-align: center; }

.split-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; align-items: start; }

/* ---------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card {
  background: var(--panel);
  border-radius: 18px;
  padding: 40px 34px;
  width: 340px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-card .icon {
  width: 62px; height: 62px; border-radius: 16px; margin: 0 auto;
  background: linear-gradient(135deg, var(--primary), #6f8dff);
  display: flex; align-items: center; justify-content: center; font-size: 30px;
}
.login-card .icon .lucide { width: 30px; height: 30px; color: white; }
.login-card h1 { color: var(--text); font-size: 21px; margin: 14px 0 2px; }
.login-card p.sub { color: var(--text-dim); font-size: 12px; margin: 0 0 20px; }
.login-card input { width: 100%; margin-bottom: 10px; }
.login-error { color: var(--danger); font-size: 12px; min-height: 16px; margin-bottom: 6px; }
.login-hint { color: var(--text-dim); font-size: 11px; margin-top: 10px; }

/* --------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 26, 46, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--panel); border-radius: 16px; padding: 22px;
  width: 420px; max-width: 92vw; max-height: 88vh; overflow: auto;
  box-shadow: 0 20px 60px rgba(16, 26, 46, 0.25);
}
.modal h2 { margin-bottom: 16px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------------------------------------------------------------- toast */
#toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--text); border-left: 4px solid var(--primary); color: white;
  padding: 12px 16px; border-radius: 10px; font-size: 13px; opacity: 0; transform: translateX(20px);
  transition: all 0.25s; max-width: 320px; box-shadow: 0 8px 24px rgba(16, 26, 46, 0.3);
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--success); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-green { background: #e3f7ea; color: #16833f; }
.badge-red { background: #fdeaea; color: #c73838; }

.empty { color: var(--text-dim); font-size: 13px; padding: 30px; text-align: center; }

/* ------------------------------------------------------------------ POS */
.pos-layout { display: grid; grid-template-columns: 1fr 380px; gap: 0; flex: 1; min-height: 0; }
.pos-main { padding: 18px 22px; overflow-y: auto; min-height: 0; }
.pos-cart { background: var(--panel); border-left: 1px solid var(--border); padding: 18px; display: flex; flex-direction: column; min-height: 0; }

.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 14px; font-size: 12.5px; font-weight: 600; color: var(--text);
  cursor: pointer;
}
.chip-btn:hover { background: #e9ecf5; }

.kebab-btn { background: transparent; border: none; font-size: 20px; color: var(--text-dim); cursor: pointer; padding: 6px 10px; border-radius: 8px; display: inline-flex; align-items: center; }
.kebab-btn:hover { background: var(--panel-2); }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.product-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px; cursor: pointer; text-align: center; transition: transform 0.1s, box-shadow 0.15s;
}
.product-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.product-card:active { transform: translateY(0); }
.product-card .thumb {
  width: 100%; aspect-ratio: 1; border-radius: 10px; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 34px;
}
.product-card .thumb .lucide { width: 30px; height: 30px; color: var(--primary); }
.product-card .pname { font-size: 12.5px; font-weight: 600; line-height: 1.25; height: 32px; overflow: hidden; }
.product-card .pprice { font-size: 13px; font-weight: 700; color: var(--price); margin-top: 4px; }
.product-card .pstock { font-size: 10.5px; color: var(--text-dim); margin-top: 2px; }
.product-card.disabled { opacity: 0.4; cursor: not-allowed; }

.cart-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cart-item .thumb-sm { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0; }
.cart-item .thumb-sm .lucide { width: 16px; height: 16px; color: var(--primary); }
.cart-item .del .lucide { width: 15px; height: 15px; }
.cart-item .info { flex: 1; min-width: 0; }
.cart-item .info .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item .info .qty { font-size: 11.5px; color: var(--text-dim); }
.cart-item .lineTotal { font-size: 13px; font-weight: 700; white-space: nowrap; }
.cart-item .del { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 14px; padding: 4px; }
.cart-item .del:hover { color: var(--danger); }
.cart-item .qty-input { width: 46px; padding: 3px 4px; text-align: center; font-size: 12px; border-radius: 6px; }

.cart-summary-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; padding: 5px 0; color: var(--text-dim); }
.cart-summary-row .val { color: var(--text); font-weight: 600; }
.cart-total-box {
  display: flex; justify-content: space-between; align-items: center;
  background: #eaf0ff; border-radius: 12px; padding: 12px 14px; margin-top: 6px;
}
.cart-total-box .lbl { font-size: 13px; font-weight: 600; color: var(--primary-hover); }
.cart-total-box .val { font-size: 21px; font-weight: 800; color: var(--primary); }

.empty-cart { text-align: center; color: var(--text-dim); font-size: 13px; padding: 30px 10px; }
.empty-cart .ic { font-size: 34px; display: block; margin-bottom: 8px; }
.empty-cart .ic .lucide { width: 30px; height: 30px; margin: 0 auto; }

.pos-search-bar { display: flex; gap: 10px; margin-bottom: 16px; }
.cart-scroll { overflow-y: auto; min-height: 0; }

/* En desktop, la columna del carrito queda fija a la altura de la ventana:
   la lista de items scrollea internamente y el resumen/botones de cobro
   siempre quedan visibles, sin importar cuantos productos haya. */
@media (min-width: 1001px) {
  .content.pos-fixed { height: 100vh; overflow: hidden; }
}
.btn-cobrar-wide { flex: 1.6; }

.badge-count {
  background: var(--danger); color: white; border-radius: 999px; font-size: 10px;
  padding: 1px 6px; margin-left: 4px; font-weight: 700;
}

.pay-options { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.pay-option {
  border: 1.5px solid var(--border); border-radius: 10px; padding: 12px 6px; text-align: center;
  cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text-dim);
}
.pay-option .ic { font-size: 18px; display: block; margin-bottom: 4px; }
.pay-option .ic .lucide { width: 18px; height: 18px; margin: 0 auto; }
.pay-option.active { border-color: var(--primary); color: var(--primary); background: #eaf0ff; }

@media (max-width: 1000px) {
  .app-layout { grid-template-columns: 1fr; }
  #sidebar { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; overflow-x: auto; padding: 10px; }
  .brand { padding: 4px 10px; }
  .nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .split-2 { grid-template-columns: 1fr; }
  .pos-layout { grid-template-columns: 1fr; }
  .pos-cart { border-left: none; border-top: 1px solid var(--border); }
}
