:root {
  --bg: #0c0c10;
  --panel: #14141a;
  --card: #1b1b23;
  --card-2: #23232d;
  --border: #2b2b36;
  --border-2: #35353f;
  --text: #ececf1;
  --muted: #9797a5;
  --primary: #7c3aed;
  --primary-h: #8b5cf6;
  --primary-soft: rgba(124, 58, 237, 0.16);
  --green: #22c55e;
  --green-bright: #4ade80;
  --green-soft: rgba(34, 197, 94, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --warning: #f59e0b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #root { height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
a { color: var(--primary-h); text-decoration: none; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 11px; font-weight: 700; font-size: 13.5px;
  transition: all 0.14s ease; white-space: nowrap; border: 1px solid transparent;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-success { background: var(--green); color: #052e12; }
.btn-success:hover { background: var(--green-bright); }
.btn-danger { background: var(--danger-soft); color: #f87171; border-color: transparent; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.22); }
.btn-ghost { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--card-2); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border-2); }
.btn-outline:hover { background: var(--card); }
.btn-outline-danger { background: transparent; color: #f87171; border-color: rgba(239, 68, 68, 0.4); }
.btn-outline-danger:hover { background: var(--danger-soft); }
.btn-lg { padding: 14px 22px; font-size: 15px; }
.btn-sm { padding: 7px 11px; font-size: 12.5px; border-radius: 9px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }

/* ---------- Auth ---------- */
.auth-screen { height: 100%; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.auth-card { width: 400px; padding: 38px; display: flex; flex-direction: column; gap: 18px; border-radius: 18px; }
.auth-logo { text-align: center; font-size: 27px; font-weight: 800; letter-spacing: -0.5px; }
.auth-sub { text-align: center; color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: flex; height: 100%; }
.sidebar {
  width: 224px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 12px;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 20px; }
.brand-logo { width: 40px; height: 40px; flex-shrink: 0; }
.brand-name-1 { font-weight: 800; font-size: 15px; line-height: 1.05; color: #fff; }
.brand-name-2 { font-weight: 800; font-size: 15px; line-height: 1.05; color: var(--green-bright); }
.brand-tagline { color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 11px;
  color: var(--muted); font-weight: 600; font-size: 13.5px;
  transition: all 0.12s ease; margin-bottom: 2px;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item svg { flex-shrink: 0; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; flex-shrink: 0; font-size: 15px; }
.user-name { font-weight: 700; font-size: 13px; color: #fff; }
.user-role { font-size: 11px; color: var(--muted); }
.logout-row { color: var(--muted); }
.logout-row:hover { color: var(--danger); background: var(--danger-soft); }

.main { flex: 1; overflow: auto; padding: 22px 26px; display: flex; flex-direction: column; }

/* ---------- POS ---------- */
.pos-wrap { flex: 1; display: flex; gap: 20px; height: calc(100vh - 46px); min-height: 0; }
.pos-main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: auto; padding-right: 4px; }
.pos-header { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.pos-title { font-size: 25px; font-weight: 800; letter-spacing: -0.3px; color: #fff; }
.pos-subtitle { color: var(--muted); font-size: 14px; margin-top: 3px; }
.pos-tagline { color: var(--green-bright); font-size: 13px; margin-top: 5px; font-style: italic; }
.pos-header-right { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.caja-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 999px; font-size: 13px; font-weight: 700;
}
.caja-pill.warn { background: var(--warning); color: #231303; }
.caja-pill.ok { background: var(--green-soft); color: var(--green-bright); border: 1px solid rgba(34,197,94,0.3); }

.type-row { display: flex; gap: 10px; align-items: stretch; margin-bottom: 16px; flex-wrap: wrap; }
.type-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-width: 128px; padding: 12px; border-radius: 12px;
  background: #131318; border: 1px solid var(--border);
  color: var(--text); font-weight: 700; font-size: 13px;
}
.type-btn:hover { border-color: var(--border-2); }
.type-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.type-btn .t-icon { font-size: 19px; }
.field { min-width: 150px; }
.field.small { min-width: 130px; }
.field .flabel { font-size: 12px; color: var(--muted); margin-bottom: 6px; text-align: left; }
.field input { height: 48px; }

.cat-pills { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 16px; }
.cat-pill {
  padding: 9px 18px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: #131318; border: 1px solid var(--border); color: var(--muted);
}
.cat-pill:hover { color: var(--text); border-color: var(--border-2); }
.cat-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.search-row { position: relative; margin-bottom: 16px; }
.search-row .s-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-row input { height: 48px; padding-left: 44px; background: #131318; }
.search-count { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; align-content: start; }
.product-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; cursor: pointer;
  transition: all 0.14s ease;
}
.product-card:hover { border-color: var(--border-2); transform: translateY(-2px); box-shadow: var(--shadow); }
.product-img {
  height: 122px; display: flex; align-items: center; justify-content: center;
  background: #23232d; font-size: 52px;
}
.product-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.product-body { padding: 13px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.product-name { font-weight: 700; font-size: 14px; color: #fff; line-height: 1.25; }
.product-price { color: var(--green); font-weight: 800; font-size: 15px; }
.add-btn {
  margin-top: auto; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px; border-radius: 10px; font-weight: 800; font-size: 13px;
  border: 1px solid rgba(34,197,94,0.4); color: var(--green-bright); background: transparent;
}
.add-btn:hover { background: var(--green-soft); border-color: var(--green); }

.pos-footer {
  margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; color: var(--muted); font-size: 12.5px;
}
.pos-footer .g { color: var(--green-bright); }

/* ---------- Cart panel ---------- */
.cart-panel { width: 368px; flex-shrink: 0; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.cart-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 12px; }
.cart-head h3 { font-size: 17px; font-weight: 800; color: #fff; }
.order-badge { background: var(--primary); color: #fff; font-weight: 800; font-size: 13px; padding: 5px 12px; border-radius: 8px; }
.cart-items { flex: 1; overflow: auto; padding: 0 16px; }
.cart-empty { text-align: center; color: var(--muted); padding: 44px 20px; }
.cart-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); }
.ci-img { width: 54px; height: 54px; border-radius: 10px; background: #23232d; display: flex; align-items: center; justify-content: center; font-size: 26px; flex-shrink: 0; }
.ci-body { flex: 1; min-width: 0; }
.ci-name { font-weight: 700; font-size: 13.5px; color: #fff; line-height: 1.3; }
.ci-unit { color: var(--green); font-size: 12.5px; margin-top: 3px; }
.ci-row { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.qty-ctl { display: flex; align-items: center; gap: 8px; }
.qty-ctl button { width: 26px; height: 26px; border-radius: 7px; background: var(--card-2); color: var(--text); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 15px; border: 1px solid var(--border); }
.qty-ctl button:hover { border-color: var(--border-2); }
.qty-ctl .q { min-width: 22px; text-align: center; font-weight: 700; }
.ci-total { font-weight: 800; font-size: 14px; color: #fff; }
.ci-edit { color: var(--muted); width: 28px; height: 28px; border-radius: 7px; display: flex; align-items: center; justify-content: center; }
.ci-edit:hover { background: var(--card-2); color: var(--text); }

.cart-totals { padding: 14px 18px; border-top: 1px solid var(--border); }
.total-row { display: flex; justify-content: space-between; padding: 5px 0; color: var(--muted); font-size: 13.5px; }
.total-row.grand { font-size: 22px; font-weight: 800; color: #fff; padding-top: 10px; padding-bottom: 12px; }
.grand .g { color: var(--green-bright); }
.cart-actions { padding: 0 18px; display: flex; flex-direction: column; gap: 10px; }
.pay-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 15px; border-radius: 13px; background: var(--green); color: #052e12; font-size: 16px; font-weight: 800; }
.pay-btn:hover { background: var(--green-bright); }
.action-row { display: flex; gap: 10px; }
.action-row .btn { flex: 1; padding: 11px; }

.open-orders { padding: 16px 18px; border-top: 1px solid var(--border); }
.oo-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 13.5px; font-weight: 700; color: #fff; }
.oo-link { color: var(--primary-h); font-size: 12.5px; cursor: pointer; }
.oo-item { display: flex; align-items: center; justify-content: space-between; padding: 12px; background: var(--card); border: 1px solid var(--border); border-radius: 11px; margin-bottom: 8px; cursor: pointer; }
.oo-item:hover { border-color: var(--border-2); }
.oo-item .l { font-weight: 600; font-size: 13px; color: #fff; }
.oo-item .r { color: var(--muted); font-size: 13px; }
.oo-item .r b { color: #fff; }

/* ---------- Generic tables / modals ---------- */
.page-title { font-size: 22px; font-weight: 800; margin-bottom: 20px; color: #fff; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); }
.table tr:hover td { background: rgba(255,255,255,0.02); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; padding: 24px; box-shadow: var(--shadow); }
.modal h3 { margin-bottom: 18px; font-size: 18px; color: #fff; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-success { background: var(--green-soft); color: var(--green-bright); }
.badge-danger { background: var(--danger-soft); color: #f87171; }
.badge-warning { background: var(--primary-soft); color: #a5b4fc; }
.badge-info { background: var(--primary-soft); color: #a5b4fc; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--card-2); border: 1px solid var(--border-2); padding: 13px 24px; border-radius: 11px; font-weight: 700; z-index: 200; box-shadow: var(--shadow); }

.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 6px; color: #fff; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
