:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --ink: #141414;
  --ink-soft: #6b7280;
  --line: #e8eaee;
  --line-strong: #d5d8de;
  --hover: #f6f7f9;
  --active: #eceef2;
  --ok-bg: #e8f7ef;
  --ok: #1f8a4c;
  --warn-bg: #fff6e5;
  --warn: #b76e00;
  --danger-bg: #fdecee;
  --danger: #c0392b;
  --info-bg: #eef2ff;
  --info: #3b4cca;
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.04), 0 8px 24px rgba(20, 20, 20, 0.04);
  --radius: 16px;
  --sidebar: 248px;
  --font: 'Poppins', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.app {
  min-height: 100%;
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: -0.04em;
}
.brand-text { font-weight: 700; font-size: 1.15rem; letter-spacing: -0.03em; }
.brand-sub { display: block; font-size: 0.72rem; color: var(--ink-soft); font-weight: 500; margin-top: 1px; }

.side-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--hover);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--ink-soft);
}
.side-search input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  color: var(--ink);
}
.side-search input::placeholder { color: #9aa1ad; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a, .nav button.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  color: #3a3f4a;
  font-weight: 500;
  font-size: 0.92rem;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.nav a:hover, .nav button.nav-link:hover { background: var(--hover); }
.nav a.active {
  background: var(--active);
  color: var(--ink);
  font-weight: 600;
}
.mi {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  color: inherit;
  flex: 0 0 auto;
}
.nav .mi { font-size: 20px; opacity: 0.9; }
.nav-foot {
  display: flex;
  justify-content: flex-start;
  padding: 4px 4px 2px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover {
  background: var(--hover);
  color: var(--ink);
}
.icon-btn .mi { font-size: 22px; }

.main {
  padding: 22px 28px 32px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.topbar-left { min-width: 0; }
.page-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}
.view[hidden] { display: none !important; }
.filters {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1 1 auto;
}
.nav button.nav-link.active {
  background: var(--active);
  color: var(--ink);
  font-weight: 600;
}
.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.filter-field select,
.filter-field input[type="date"] {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
  min-width: 140px;
}
.export-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.export-title {
  margin: 0 0 2px;
  font-size: 1rem;
  letter-spacing: -0.02em;
}
.export-bar .muted {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
}
.export-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px 20px 10px;
  margin-bottom: 18px;
}
.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.chart-head h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}
.chart-head .muted {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}
.chart-wrap { position: relative; width: 100%; }
.kpi-value.kpi-money {
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  word-break: break-word;
}
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c5c9d1;
}
.live-pill.on .live-dot {
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15);
}
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #222;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 0.85rem;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
}
.kpi-label {
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 500;
}
.kpi-value {
  margin-top: 8px;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}
.kpi-meta {
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--ink-soft);
  font-weight: 500;
}
.kpi-meta strong { color: var(--ok); font-weight: 600; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 12px;
  flex-wrap: wrap;
}
.panel-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.panel-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--hover);
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 220px;
  color: var(--ink-soft);
}
.search input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  color: var(--ink);
}
.btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:hover { background: var(--hover); }
.btn-dark {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.btn-dark:hover { background: #000; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
th, td {
  text-align: left;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
  font-size: 0.9rem;
}
th {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
  background: #fbfbfc;
  border-top: 0;
}
tbody tr { transition: background 0.15s ease; }
tbody tr:hover { background: #fafbfc; }
tbody tr.flash {
  animation: flashIn 1.2s ease;
}
@keyframes flashIn {
  0% { background: #eef7ff; }
  100% { background: transparent; }
}

.cell-muted { color: var(--ink-soft); font-size: 0.82rem; }
.cell-strong { font-weight: 600; }
.money { font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.client {
  display: flex;
  align-items: center;
  gap: 12px;
}
.client-av {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #edf0f4;
  color: #374151;
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: 0.78rem;
  flex: 0 0 auto;
}
.client-name { font-weight: 600; line-height: 1.2; }
.client-sub { color: var(--ink-soft); font-size: 0.78rem; margin-top: 2px; }

.status-select {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 7px 28px 7px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.status-select.status-pendiente,
.status-badge.status-pendiente { background-color: var(--warn-bg); color: var(--warn); }
.status-select.status-en-proceso,
.status-badge.status-en-proceso { background-color: var(--info-bg); color: var(--info); }
.status-select.status-entregado,
.status-badge.status-entregado { background-color: var(--ok-bg); color: var(--ok); }
.status-select.status-cancelado,
.status-badge.status-cancelado { background-color: var(--danger-bg); color: var(--danger); }

.panel-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 500;
  gap: 12px;
  flex-wrap: wrap;
}
.pager-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.pager-size {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.pager-size select {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 7px 10px;
  background: #fff;
  color: var(--ink);
}
.pager {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.pager button {
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 10px;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0 10px;
}
.pager button:hover:not(:disabled) { background: var(--hover); }
.pager button.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.pager button:disabled {
  opacity: 0.45;
  cursor: default;
}

.empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--ink-soft);
}
.empty strong { display: block; color: var(--ink); margin-bottom: 6px; font-size: 1.05rem; }

/* Login */
.login-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 15% 10%, rgba(20,20,20,0.05), transparent 60%),
    radial-gradient(700px 380px at 90% 80%, rgba(20,20,20,0.04), transparent 55%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 34px 32px 28px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 14px 0 6px;
  font-size: 1.7rem;
  letter-spacing: -0.04em;
}
.login-card p {
  margin: 0 0 22px;
  color: var(--ink-soft);
  font-size: 0.92rem;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  background: #fff;
}
.field input:focus { border-color: #111; box-shadow: 0 0 0 3px rgba(20,20,20,0.08); }
.login-error {
  display: none;
  margin-bottom: 12px;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  font-weight: 500;
}
.login-error.show { display: block; }
.login-card .btn-dark { width: 100%; justify-content: center; margin-top: 6px; padding: 12px; }

/* Modal */
.modal-root[hidden] { display: none !important; }
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 20, 0.38);
  backdrop-filter: blur(2px);
}
.modal {
  position: relative;
  width: min(560px, 100%);
  max-height: min(86vh, 820px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(20, 20, 20, 0.18);
  animation: modalIn 0.18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-kicker {
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.modal-title {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
  font-weight: 700;
}
.modal-body { padding: 18px 20px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
  background: var(--surface);
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}
.detail-card {
  background: var(--hover);
  border-radius: 14px;
  padding: 12px 14px;
}
.detail-card.full { grid-column: 1 / -1; }
.detail-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.detail-label .mi { font-size: 16px; }
.detail-value {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.35;
  word-break: break-word;
}
.detail-section-title {
  margin: 0 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.products-list {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 14px;
}
.product-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
}
.product-row:first-child { border-top: 0; }
.product-name { font-weight: 600; }
.product-meta { color: var(--ink-soft); font-size: 0.78rem; margin-top: 2px; }
.totals {
  display: grid;
  gap: 8px;
  padding: 4px 2px 0;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--ink-soft);
  font-weight: 500;
}
.totals-row.grand {
  color: var(--ink);
  font-weight: 700;
  font-size: 1.05rem;
  padding-top: 8px;
  border-top: 1px dashed var(--line-strong);
  margin-top: 4px;
}
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #f4f6f8; }
.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.edit-field { display: flex; flex-direction: column; gap: 6px; }
.edit-field.full { grid-column: 1 / -1; }
.edit-field label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.edit-field input,
.edit-field select,
.edit-field textarea {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  background: #fff;
  width: 100%;
}
.edit-field textarea { min-height: 72px; resize: vertical; }
.edit-field input:focus,
.edit-field select:focus,
.edit-field textarea:focus {
  border-color: #111;
  box-shadow: 0 0 0 3px rgba(20,20,20,0.08);
}
.edit-products { display: grid; gap: 8px; margin-bottom: 12px; }
.edit-product {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 0.9fr auto;
  gap: 8px;
  align-items: center;
}
.btn-icon-danger {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}
.col-more { width: 64px; text-align: center; }
td.col-more { text-align: center; }
.more-wrap { position: relative; display: inline-flex; }
.more-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}
.more-btn:hover,
.more-wrap.open .more-btn {
  background: var(--hover);
  color: var(--ink);
}
.more-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 180px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(20, 20, 20, 0.12);
  padding: 6px;
  z-index: 20;
  display: none;
}
.more-wrap.open .more-menu { display: grid; gap: 2px; }
.more-menu button {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.86rem;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
}
.more-menu button:hover { background: var(--hover); }
.more-menu .mi { font-size: 18px; color: var(--ink-soft); }
.modal-history { width: min(520px, 100%); }
.audit-list { margin-top: 0; }
.audit-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #fbfbfc;
}
.audit-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-weight: 500;
  margin-bottom: 6px;
}
.audit-meta strong { color: var(--ink); font-weight: 600; }
.audit-change {
  font-size: 0.82rem;
  margin: 3px 0;
  color: #374151;
}
.audit-change em { font-style: normal; color: var(--ink-soft); }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
  }
  .side-search { display: none; }
  .nav {
    display: flex;
    flex-direction: row;
    gap: 6px;
    flex: 1;
    justify-content: flex-end;
  }
  .nav .nav-link span:not(.mi) { display: none; }
  .nav .nav-link {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    border-radius: 999px;
  }
  .nav-foot { padding: 0; }
  .main { padding: 16px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .edit-grid { grid-template-columns: 1fr; }
  .edit-product { grid-template-columns: 1fr; }
}
