:root {
  --bg: #f5f4f8;
  --surface: #ffffff;
  --surface-2: #f0eef5;
  --text: #1b1726;
  --muted: #6b6680;
  --border: #e3e0ec;
  --accent: #7c3aed;
  --accent-2: #6d28d9;
  --accent-soft: #efe7fe;
  --accent-ink: #ffffff;
  --good: #0f8a5f;
  --good-soft: #e1f5ec;
  --bad: #c62a3a;
  --bad-soft: #fde8ea;
  --warn: #b25e00;
  --warn-soft: #fff1dc;
  --shadow: 0 1px 2px rgba(20, 10, 40, .05), 0 4px 16px rgba(20, 10, 40, .05);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #110f17;
    --surface: #1b1823;
    --surface-2: #24202f;
    --text: #ece9f4;
    --muted: #9c96b0;
    --border: #2f2a3d;
    --accent: #9b6bff;
    --accent-2: #b08bff;
    --accent-soft: #2a2140;
    --accent-ink: #12051f;
    --good: #3fcf94;
    --good-soft: #15302a;
    --bad: #ff6b7a;
    --bad-soft: #3a1c22;
    --warn: #ffb547;
    --warn-soft: #3a2a14;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.55rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.shell > div { min-width: 0; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; font-size: 1.1rem; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 1.1rem;
}
.brand small { display: block; font-weight: 500; font-size: .75rem; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .ico { width: 22px; text-align: center; }
.nav .badge-count {
  margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px;
  font-size: .72rem; padding: 1px 7px; font-weight: 700;
}
.sidebar .me { margin-top: auto; border-top: 1px solid var(--border); padding: 14px 8px 0; font-size: .9rem; }
.sidebar .me b { display: block; }
.main { padding: 28px 32px 60px; min-width: 0; }
.topbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.25);
  }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px;
  }
  .topbar .title { font-weight: 700; }
  .main { padding: 18px 16px 60px; }
}

/* ---------- components ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 600; font-size: .9rem;
  cursor: pointer; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.good { color: var(--good); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 9px; font-size: .8rem; border-radius: 8px; }
.btn.lg { padding: 13px 20px; font-size: 1rem; }
.btn:disabled { opacity: .55; cursor: wait; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; min-width: 0;
}
.card > h2 { margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card.flush { padding: 0; }
.card.flush > h2 { padding: 18px 20px 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.kpi .value { font-size: 1.55rem; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .sub { color: var(--muted); font-size: .8rem; }
.kpi.warn { border-color: var(--warn); background: var(--warn-soft); }
.kpi.warn .value { color: var(--warn); }
.kpi.good .value { color: var(--good); }
.kpi.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.kpi.accent .label, .kpi.accent .sub { color: inherit; opacity: .85; }
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 1.2rem; }
  .kpi.accent, .kpi.warn { grid-column: 1 / -1; }
  .kpi.accent .value, .kpi.warn .value { font-size: 1.6rem; }
}

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + * { margin-top: 18px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
td.r, th.r { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
tr.cancelled td { opacity: .5; text-decoration: line-through; }
tr.cancelled td.keep { text-decoration: none; }
td .wrap { white-space: normal; min-width: 160px; display: block; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.pos { color: var(--good); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }
.owe { color: var(--warn); font-weight: 700; }

.empty { padding: 30px 16px; text-align: center; color: var(--muted); }
.empty.error { color: var(--bad); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.alert { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: .85rem; font-weight: 600; }
.field small { color: var(--muted); font-size: .78rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
@media (max-width: 560px) { .row-2, .row-3 { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-weight: 500; }
.check input { width: auto; }
.form-error { color: var(--bad); background: var(--bad-soft); padding: 9px 12px; border-radius: 10px; font-weight: 600; font-size: .88rem; margin: 0 0 12px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { margin: 0; min-width: 150px; flex: 0 1 190px; }

.calc { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; background: var(--surface-2); border-radius: 12px; padding: 12px; margin-bottom: 14px; }
.calc div { display: flex; flex-direction: column; }
.calc span { font-size: .75rem; color: var(--muted); font-weight: 600; }
.calc b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
@media (max-width: 480px) { .calc { grid-template-columns: 1fr; } .calc div { flex-direction: row; justify-content: space-between; align-items: center; } }
.hint { font-size: .82rem; color: var(--muted); margin: -4px 0 14px; }
.hint.warn { color: var(--warn); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; background:
  radial-gradient(1000px 500px at 10% -10%, var(--accent-soft), transparent), var(--bg); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .brand { justify-content: center; padding-bottom: 8px; }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 22px; }
.auth .btn { width: 100%; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 5, 20, .5); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .12s ease; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 640px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 6px; position: sticky; top: 0; background: var(--surface); }
.modal form, .modal .body { padding: 10px 20px 20px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
@keyframes fade { from { opacity: 0; } }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.25); animation: fade .15s ease; }
.toast.error { background: var(--bad); color: #fff; }

/* ---------- chart ---------- */
.chart svg { width: 100%; height: 200px; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar:hover { fill: var(--accent-2); }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--border); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }

/* ---------- inventory cards (vendedor) ---------- */
.inv-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.inv-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface); }
.inv-card .name { font-weight: 700; }
.inv-card .qty { font-size: 1.8rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.inv-card.out .qty { color: var(--muted); }
.inv-card dl { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin: 8px 0 0; font-size: .85rem; }
.inv-card dt { color: var(--muted); }
.inv-card dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.profile { display: flex; gap: 14px; align-items: center; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 800; font-size: 1.2rem; flex: none; }
