:root {
  --bg: #f6f5f3;
  --panel: #ffffff;
  --panel-2: #faf9f7;
  --ink: #221f1c;
  --ink-soft: #5b564e;
  --muted: #8a847a;
  --line: #e8e5e0;
  --brand: #c4531e;
  --brand-2: #a03d10;
  --brand-soft: #f9e9e0;
  --ok: #2e7d32;
  --ok-soft: #e8f4e9;
  --warn: #b07a00;
  --warn-soft: #fdf3d9;
  --bad: #c0392b;
  --bad-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 25, 20, 0.04), 0 8px 24px rgba(30, 25, 20, 0.06);
  --sidebar-w: 248px;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-2); }

/* ============ Login ============ */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background:
    radial-gradient(900px 500px at 12% -8%, rgba(196, 83, 30, 0.08), transparent 60%),
    radial-gradient(800px 500px at 105% 110%, rgba(196, 83, 30, 0.06), transparent 55%),
    var(--bg);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  padding: 36px 32px 30px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.12rem;
  color: var(--brand);
}
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--brand);
  display: inline-block;
}
.login-title { margin: 24px 0 6px; font-size: 1.45rem; letter-spacing: -0.02em; }
.login-sub { margin: 0 0 20px; color: var(--muted); }

/* ============ Layout ============ */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.main-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  color: var(--ink-soft);
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex; gap: 12px; align-items: center;
  padding: 2px 8px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.brand-dot { color: var(--brand); }
.brand-name { font-weight: 800; font-size: 1.02rem; color: var(--ink); letter-spacing: -0.01em; }
.brand-sub { font-size: 0.72rem; color: var(--muted); }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-group {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); padding: 16px 10px 6px;
}
.nav-group:first-child { padding-top: 6px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 10px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
}
.nav-link svg { width: 18px; height: 18px; opacity: 0.85; }
.nav-link:hover { background: var(--panel-2); color: var(--ink); }
.nav-link.active { background: var(--brand-soft); color: var(--brand-2); font-weight: 600; }
.nav-link.active svg { opacity: 1; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  min-height: 66px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.nav-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  cursor: pointer; color: var(--ink-soft);
}
.nav-toggle svg { width: 22px; height: 22px; }
.nav-toggle:hover { background: var(--panel-2); }
.nav-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 17, 14, 0.45);
  z-index: 55;
}
.topbar-title h1 { margin: 0; font-size: 1.25rem; letter-spacing: -0.015em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 14px; position: relative; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.95rem;
}
.user-name { font-size: 0.85rem; font-weight: 600; }
.user-role { font-size: 0.7rem; color: var(--muted); }
.noti-btn {
  position: relative;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--ink-soft);
  transition: background 0.12s;
}
.noti-btn:hover { background: var(--panel-2); }
.noti-btn svg { width: 20px; height: 20px; }
.badge {
  position: absolute; top: -6px; right: -6px;
  background: var(--bad); color: #fff;
  font-size: 0.66rem; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px var(--panel);
}
.noti-dropdown {
  position: absolute; right: 0; top: 50px;
  width: 320px; max-height: 420px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 40; padding: 10px;
}
.noti-title { font-weight: 700; padding: 6px 8px 2px; }
.noti-group { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 12px 8px 4px; }
.noti-item { padding: 7px 8px; border-bottom: 1px solid var(--line); font-size: 0.85rem; }
.noti-more { padding: 6px 8px; font-size: 0.78rem; color: var(--muted); }
.inline { display: inline; }
.icon-link { border: 0; background: none; cursor: pointer; color: var(--muted); }
.icon-link:hover { color: var(--bad); }
.icon-link svg { width: 20px; height: 20px; }

.content {
  padding: 26px 28px 42px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}
.footer {
  padding: 0 28px 26px;
  color: var(--muted); font-size: 0.76rem;
  margin-top: auto;
}

/* ============ Cards / grid ============ */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 20px;
}
.card h3 { margin: 0 0 14px; font-size: 1rem; color: var(--ink); }
.notice {
  background: var(--brand-soft);
  border-color: #efcdbe;
}
.notice h3 { color: var(--brand-2); }
.notice p { font-size: 0.88rem; }
.card h4 { margin: 18px 0 8px; font-size: 0.9rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 0; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 0; }
.grid3 > .card, .grid4 > .card { margin-bottom: 0; }
.grid-auto { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 0; }
.grid-auto > .card { margin-bottom: 0; }
.stat { padding: 18px 20px; }
.stat-label {
  font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.stat-label svg { width: 16px; height: 16px; }
.stat-value { font-size: 1.65rem; font-weight: 800; margin: 6px 0 0; letter-spacing: -0.02em; }
.stat-good .stat-value { color: var(--ok); }
.stat-warn .stat-value { color: var(--warn); }
.stat-bad .stat-value { color: var(--bad); }
.quick-actions { margin-top: 14px; }
.detail-row { display: grid; gap: 12px; margin-top: 14px; }
.muted { color: var(--muted); font-size: 0.85rem; }
.legend { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 0.85rem; color: var(--ink-soft); }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th {
  text-align: left; font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  white-space: nowrap;
}
.table td { padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--panel-2); }
.inactive-row { opacity: 0.55; }
.row-actions { display: flex; gap: 6px; align-items: center; }

/* ============ Formularios ============ */
.form-card { margin-bottom: 20px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 0.82rem; color: var(--ink-soft); position: relative; }
.field span { font-weight: 600; }
.field input, .field select, .field-textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--panel);
}
.field input:focus, .field select:focus, .field-textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(196, 83, 30, 0.12);
}
.field-static { padding: 10px 12px; background: var(--panel-2); border-radius: 10px; border: 1px dashed var(--line); font-size: 0.92rem; }
.field-wide { grid-column: 1 / -1; }
.field-btn { display: flex; align-items: flex-end; }
.formgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.formgrid .field-wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.filter-actions { display: flex; gap: 10px; align-items: center; }
.subhead { margin: 14px 0 8px; }

/* ============ Botones ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-soft);
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--panel-2); color: var(--ink); border-color: #d8d3cc; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn-danger { background: var(--bad-soft); border-color: #f3c6c2; color: var(--bad); }
.btn-danger:hover { background: #fadcd9; }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-sm { padding: 5px 10px; font-size: 0.76rem; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }

/* ============ Tags / quantities ============ */
.qty {
  display: inline-block;
  min-width: 34px;
  padding: 3px 9px;
  border-radius: 8px;
  text-align: center;
  font-weight: 700;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}
.qty-ok { background: var(--ok-soft); color: var(--ok); border-color: #c3e0c6; }
.qty-warn { background: var(--warn-soft); color: var(--warn); border-color: #efdcb0; }
.qty-bad { background: var(--bad-soft); color: var(--bad); border-color: #f2c4c0; }
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  white-space: nowrap;
}
.tag-ok { background: var(--ok-soft); color: var(--ok); border-color: #c3e0c6; }
.tag-bad { background: var(--bad-soft); color: var(--bad); border-color: #f2c4c0; }
.tag-stage { background: var(--brand-soft); color: var(--brand-2); border-color: #efcdbe; }
.tag-role { background: #eef0f7; color: #44508c; border-color: #d8dcea; }

/* ============ Flash ============ */
.flash {
  padding: 12px 15px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  border: 1px solid;
}
.flash-ok { background: var(--ok-soft); border-color: #c3e0c6; color: var(--ok); }
.flash-error { background: var(--bad-soft); border-color: #f2c4c0; color: var(--bad); }

/* ============ Modal ============ */
.modal {
  position: fixed; inset: 0;
  background: rgba(25, 22, 18, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-card { width: 100%; max-width: 520px; margin: 0; }
.hidden { display: none !important; }

/* ============ Ventas ============ */
.sale-header-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 14px; margin-bottom: 14px; }
.sale-row {
  display: grid;
  grid-template-columns: 2fr 90px 130px 120px 76px;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  margin-bottom: 10px;
  background: var(--panel-2);
}
.sale-total {
  display: flex; justify-content: flex-end; align-items: baseline; gap: 12px;
  font-size: 1.05rem; margin-top: 14px;
  border-top: 2px solid var(--line); padding-top: 14px;
}
.sale-total b { font-size: 1.5rem; color: var(--brand); }
.sale-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 14px;
  overflow: hidden;
  background: var(--panel);
}
.sale-group-header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}
.sale-group-total { margin-left: auto; font-weight: 800; font-size: 1.05rem; }
.details-note { padding: 6px 16px; font-style: italic; }

/* ============ Responsive ============ */
@media (max-width: 1180px) {
  .grid4 { grid-template-columns: repeat(2, 1fr); }
  .formgrid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 960px) {
  .grid3, .grid-auto { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(300px, 86vw);
    height: 100vh; max-height: 100vh;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    z-index: 60;
    padding: 20px 16px;
    border-right: 1px solid var(--line);
    box-shadow: 8px 0 28px rgba(20, 17, 14, 0.18);
  }
  .sidebar.open { transform: translateX(0); }
  body.nav-open { overflow: hidden; }
  .nav-list { display: block; }
  .nav-group { display: none; }
  .nav-link { padding: 10px 12px; margin-bottom: 2px; }
  .formgrid { grid-template-columns: 1fr; gap: 12px; }
  .grid4 { grid-template-columns: 1fr 1fr; gap: 12px; }
  .grid-auto { gap: 12px; }
  .sale-row { grid-template-columns: 1fr; align-items: stretch; gap: 10px; }
  .sale-header-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: nowrap; padding: 8px 14px; min-height: 0; gap: 10px; }
  .topbar-title h1 { font-size: 1.05rem; }
  .content { padding: 18px 16px 30px; }
  .user-meta { display: none; }
  .card { padding: 16px; }
  .card, .sale-group, .table-wrap { overflow-x: auto; }
  .field input, .field select, .field-textarea, .field-static, .btn, .sale-total b { font-size: 16px; }
  .modal { padding: 12px; }
  .modal-card { max-height: 92vh; overflow-y: auto; }
  .noti-dropdown { max-width: calc(100vw - 28px); }
}
@media (max-width: 430px) {
  .grid4 { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.4rem; }
  .sale-group-header { gap: 8px; }
  .sale-group-total { margin-left: 0; }
  .footer { padding: 0 16px 22px; }
  .form-actions, .filter-actions { flex-wrap: wrap; }
}