:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --ink: #111827;
  --muted: #64748b;
  --line: #d5dde8;
  --line-strong: #c4cedb;
  --blue: #1557c0;
  --green: #0f7a55;
  --amber: #a76512;
  --red: #b9342f;
  --violet: #5b50c8;
  --shadow: 0 14px 32px rgba(15, 23, 42, .08);
  --shadow-soft: 0 6px 18px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
  background: #ffffff;
  color: var(--ink);
  font-family: "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 22px;
  background: linear-gradient(135deg, #f6f7fb 0%, #eef4ff 55%, #f7f2ff 100%);
}

.login-card {
  width: min(430px, 100%);
  display: grid;
  gap: 16px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.brand.large {
  padding: 0 0 14px;
}

.login-card h1 {
  font-size: 26px;
  margin-bottom: 6px;
}

.login-card p {
  margin-bottom: 0;
  line-height: 1.45;
}

.demo-users {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.demo-users button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--ink);
  font-weight: 700;
}

.sidebar {
  background: #ffffff;
  color: var(--ink);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
  position: sticky;
  top: 0;
  border-right: 1px solid #e5e7eb;
  max-height: 100vh;
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 8px 12px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #6d28d9, #2563eb);
  color: #ffffff;
  border-radius: 10px;
  font-weight: 900;
}

.brand strong { display: block; font-size: 20px; letter-spacing: 0; font-style: italic; }
.brand span { color: var(--muted); font-size: 12px; }

.nav { display: grid; gap: 2px; }

.nav::before {
  content: "PLAN BASICO";
  color: #6b7280;
  font-size: 11px;
  letter-spacing: .08em;
  padding: 10px 0 6px;
}

.nav-btn {
  text-align: left;
  border: 0;
  color: #1f2937;
  background: transparent;
  border-radius: 5px;
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 600;
}

.nav-btn:hover, .nav-btn.active {
  background: #f1ebff;
  color: #5521c9;
  box-shadow: inset 3px 0 0 #7c3aed;
}

.sidebar-foot {
  margin-top: auto;
  color: var(--muted);
  background: #f7f9fc;
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.role-card {
  display: grid;
  gap: 8px;
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}

.user-card {
  display: grid;
  gap: 5px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.user-card span,
.user-card small {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-card > span:first-child {
  color: #475569;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.user-card strong {
  font-size: 15px;
}

.user-card .ghost-btn {
  min-height: 34px;
}

.role-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.role-card select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.sidebar-foot strong { color: var(--ink); }

.shell {
  min-width: 0;
  border-top: 1px solid #e5e7eb;
  padding: 30px 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 26px;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

.page-title {
  display: flex;
  align-items: center;
  gap: 14px;
}

.page-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #efe7ff;
  color: #6d28d9;
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 26px; font-weight: 800; }
h2 { margin-bottom: 4px; font-size: 17px; font-weight: 800; }
p { color: var(--muted); }
.role-note { margin: 6px 0 0; }

.top-actions, .form-actions { display: flex; gap: 10px; align-items: center; }

.primary-btn, .ghost-btn, .icon-btn {
  border-radius: 7px;
  min-height: 38px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

.primary-btn { background: #6d28d9; color: white; }
.primary-btn:hover { background: #5b21b6; }
.ghost-btn { background: white; color: var(--ink); border-color: var(--line-strong); }
.ghost-btn:hover, .icon-btn:hover { border-color: var(--blue); color: var(--blue); }
.icon-btn { width: 40px; padding: 0; background: white; border-color: var(--line-strong); color: var(--ink); }

.view { display: none; }
.view.active { display: block; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.finance-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 18px;
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--blue);
}

.kpi span, .kpi small { color: var(--muted); font-size: 12px; }
.kpi strong { display: block; font-size: 26px; margin: 8px 0 2px; letter-spacing: 0; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.4fr .8fr;
  gap: 16px;
}

.create-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.create-head h2 { margin-bottom: 4px; font-size: 22px; }
.create-head p { margin-bottom: 0; }

.create-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.create-main {
  display: grid;
  gap: 14px;
}

.step-panel {
  box-shadow: var(--shadow-soft);
}

.step-title {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
}

.step-title strong { font-size: 15px; }
.step-title span { color: var(--muted); font-size: 13px; }

.product-picker {
  display: grid;
  gap: 10px;
  max-height: 340px;
  overflow: auto;
  padding-right: 4px;
}

.product-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
}

.product-row.selected {
  background: #f4efff;
  border-color: #a855f7;
}

.product-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #5521c9;
  background: #f1ebff;
  font-weight: 900;
}

.product-row strong,
.product-row span {
  display: block;
}

.product-row small {
  color: var(--muted);
}

.order-summary {
  position: sticky;
  top: 18px;
}

.summary-box {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.summary-product {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: center;
}

.summary-line {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.summary-total {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-size: 18px;
  font-weight: 800;
}

.full-width {
  width: 100%;
  margin-top: 8px;
}

.row-actions {
  display: inline-flex;
  gap: 5px;
  white-space: nowrap;
}

.small-btn {
  min-height: 32px;
  padding: 0 8px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.small-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.wide { grid-row: span 2; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-head.compact { margin-bottom: 10px; }

.table-wrap { overflow: auto; border: 1px solid #e5e7eb; border-radius: 8px; background: white; }

table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 10px; text-align: left; border-bottom: 1px solid #e5e7eb; white-space: nowrap; }
th { background: #ffffff; color: #111827; font-size: 13px; text-transform: none; font-weight: 800; }
tbody tr:hover td { background: #f9fbfe; }
tr:last-child td { border-bottom: 0; }

.orders-table table {
  table-layout: fixed;
  min-width: 0;
}

@media (min-width: 981px) {
  .orders-table { overflow-x: hidden; }
}

.orders-table th,
.orders-table td {
  padding: 11px 6px;
}

.orders-table th:nth-child(1), .orders-table td:nth-child(1) { width: 85px; }
.orders-table th:nth-child(2), .orders-table td:nth-child(2) { width: 85px; }
.orders-table th:nth-child(3), .orders-table td:nth-child(3) { width: 95px; }
.orders-table th:nth-child(4), .orders-table td:nth-child(4) { width: 165px; }
.orders-table th:nth-child(5), .orders-table td:nth-child(5) { width: 110px; }
.orders-table th:nth-child(6), .orders-table td:nth-child(6) { width: 76px; }
.orders-table th:nth-child(7), .orders-table td:nth-child(7) { width: 116px; }
.orders-table th:nth-child(8), .orders-table td:nth-child(8) { width: 122px; }
.orders-table th:nth-child(9), .orders-table td:nth-child(9) { width: 118px; }
.orders-table th:nth-child(10), .orders-table td:nth-child(10) { width: 92px; }

.collections-table table {
  min-width: 980px;
}

.collections-table th,
.collections-table td {
  padding: 12px 8px;
}

.collections-table th:nth-child(1), .collections-table td:nth-child(1) { width: 95px; }
.collections-table th:nth-child(2), .collections-table td:nth-child(2) { width: 170px; }
.collections-table th:nth-child(3), .collections-table td:nth-child(3) { width: 135px; }
.collections-table th:nth-child(4), .collections-table td:nth-child(4) { width: 90px; }
.collections-table th:nth-child(5), .collections-table td:nth-child(5) { width: 90px; }
.collections-table th:nth-child(6), .collections-table td:nth-child(6) { width: 90px; }
.collections-table th:nth-child(7), .collections-table td:nth-child(7) { width: 110px; }
.collections-table th:nth-child(8), .collections-table td:nth-child(8) { width: 120px; }
.collections-table th:nth-child(9), .collections-table td:nth-child(9) { width: 150px; }

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 800;
}

.channel-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 7px;
  padding: 4px 8px;
  background: #dbeafe;
  color: #1459d9;
  font-size: 11px;
  font-weight: 800;
}

.shipment {
  display: inline-flex;
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 800;
}

.ship-neutral { background: #f3f4f6; color: #374151; }
.ship-ok { background: #dcfce7; color: #128047; }

.pay-method {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.pay-method b {
  width: 20px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #22c55e;
  color: white;
  font-size: 10px;
}

.st-pending { background: #fff7e5; color: var(--amber); border: 1px solid #f2d59a; }
.st-registered { background: #eaf1ff; color: var(--blue); border: 1px solid #c5d8ff; }
.st-transit { background: #f0eeff; color: var(--violet); border: 1px solid #d6d0ff; }
.st-destination { background: #e3f8ee; color: var(--green); border: 1px solid #b9e7d2; }
.st-delivered { background: #eaf8f3; color: var(--green); border: 1px solid #b9e7d2; }
.st-observed { background: #fff0ee; color: var(--red); border: 1px solid #ffc6c1; }
.pay-paid { background: #eaf8f3; color: var(--green); border: 1px solid #b9e7d2; }
.pay-partial { background: #fff7e5; color: var(--amber); border: 1px solid #f2d59a; }
.pay-pending { background: #eaf1ff; color: var(--blue); border: 1px solid #c5d8ff; }
.pay-overdue { background: #fff0ee; color: var(--red); border: 1px solid #ffc6c1; }

.pipeline { display: grid; gap: 10px; }
.pipe-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar { height: 9px; background: #e6edf6; border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), #4f8cff); border-radius: inherit; }

.activity { display: grid; gap: 10px; }
.activity-item { border-left: 3px solid var(--blue); padding-left: 10px; font-size: 13px; color: var(--muted); }
.activity-item strong { display: block; color: var(--ink); margin-bottom: 3px; }

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: end;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.orders-actions-bar {
  display: flex;
  align-items: end;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: nowrap;
}

.orders-actions-bar label {
  min-width: 132px;
}

.orders-actions-bar .toolbar-actions {
  flex-wrap: nowrap;
}

.orders-actions-bar .ghost-btn,
.orders-actions-bar .primary-btn {
  padding: 0 12px;
  white-space: nowrap;
}

.orders-actions-bar label span,
.orders-search span {
  display: none;
}

.filter-btn {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  color: #111827;
  padding: 0 13px;
  font-weight: 800;
  white-space: nowrap;
}

.orders-search {
  width: 100%;
  margin-bottom: 24px;
}

.orders-search input {
  width: 100%;
  min-height: 40px;
}

.bulk-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: -10px 0 16px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.bulk-panel strong {
  margin-right: auto;
  color: #0f172a;
}

.bulk-panel select {
  min-height: 38px;
}

.order-check,
#selectAllOrders {
  width: 16px;
  height: 16px;
  accent-color: #6d28d9;
}

.action-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: #111827;
  border-radius: 6px;
  font-weight: 900;
}

.action-icon:hover {
  background: #f3f4f6;
  color: #2563eb;
}

.action-icon.edit {
  color: #2563eb;
}

label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 40px;
  padding: 9px 11px;
  color: var(--ink);
  background: white;
}

textarea { resize: vertical; }
.search { min-width: 320px; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.mini-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 3px 10px rgba(15, 23, 42, .04);
}

.mini-card strong { display: block; margin-bottom: 5px; }
.mini-card span { color: var(--muted); display: block; font-size: 13px; line-height: 1.5; }

.automation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.automation-card {
  display: grid;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.report-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  background: white;
}

.report-card h3 {
  margin: 0;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}

.report-card table {
  min-width: 520px;
}

.backup-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.security-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.audit-list {
  max-height: 560px;
  overflow: auto;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 17, 27, .56);
  display: grid;
  place-items: center;
  padding: 22px;
  z-index: 20;
}

.modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 44px);
  overflow: auto;
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal.small { width: min(520px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.full { grid-column: 1 / -1; }
.form-actions { justify-content: space-between; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #141a25;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 30;
}

@media (max-width: 980px) {
  body { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; position: relative; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid, .dashboard-grid, .automation-grid, .finance-kpis, .create-grid, .report-grid, .security-grid { grid-template-columns: 1fr; }
  .order-summary { position: static; }
}

@media (max-width: 620px) {
  .shell { padding: 16px; }
  .topbar, .panel-head { align-items: stretch; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .search { min-width: 100%; }
  .toolbar-actions, .top-actions, .backup-actions { width: 100%; }
  .toolbar-actions .ghost-btn, .top-actions .primary-btn, .backup-actions button { width: 100%; }
  .nav { grid-template-columns: 1fr; }
  .demo-users { grid-template-columns: 1fr; }
}
