:root {
  --navy-950: #0f172a;
  --navy-900: #141e33;
  --navy-800: #1b2a47;
  --navy-700: #24365a;
  --teal: #1fb6a6;
  --teal-dark: #159487;
  --amber: #f2a93b;
  --red: #e4574c;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --border: #e6e9ef;
  --text: #131a2a;
  --text-muted: #5b6472;
  --text-faint: #98a2b3;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page-title, .brand, .card-header h2, .modal-header h3 {
  font-family: "Sora", "Inter", sans-serif;
}

.layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 250px;
  min-width: 250px;
  background: var(--navy-950);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width 0.2s ease, min-width 0.2s ease, transform 0.2s ease;
  z-index: 30;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.brand-text { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; }
.brand { font-size: 16px; font-weight: 700; letter-spacing: 0.2px; }
.brand-text span {
  display: block;
  font-family: "Inter", sans-serif;
  font-weight: 400;
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 1px;
}

.collapse-btn {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
  border: none;
  color: #c4cbd8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.22s ease;
}

.collapse-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.collapse-btn svg { transition: transform 0.22s ease; }

.nav-scroll { flex: 1; padding: 16px 12px; overflow-y: auto; overflow-x: hidden; }

.nav-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
  color: var(--text-faint);
  padding: 14px 12px 6px;
}

.nav-section-title:first-child { padding-top: 2px; }
.nav-section-icon { display: flex; flex-shrink: 0; opacity: 0.7; }
.nav-section-icon svg { width: 13px; height: 13px; }
.nav-section-label { overflow: hidden; text-overflow: ellipsis; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #c4cbd8;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  position: relative;
  transition: background 0.15s ease, color 0.15s ease;
  cursor: pointer;
  white-space: normal;
  line-height: 1.3;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: rgba(255, 255, 255, 0.05); color: #fff; }

.nav-item.active { background: rgba(31, 182, 166, 0.14); color: #fff; }
.nav-item.active svg { opacity: 1; color: var(--teal); }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--teal);
  border-radius: 0 4px 4px 0;
}

/* Sub-ítem anidado (p.ej. "Empresa" debajo de "Configuración"): mismo
   comportamiento de nav-item, solo indentado y con texto más chico. */
.nav-subitem {
  padding-left: 28px;
  font-size: 13px;
  font-weight: 400;
  margin-top: -2px;
}
.nav-subitem svg { width: 15px; height: 15px; }
.sidebar.collapsed .nav-subitem { display: none; }

.sidebar-footer {
  padding: 14px 20px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #3f5787, var(--navy-700));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.user-meta { line-height: 1.25; min-width: 0; overflow: hidden; white-space: nowrap; }
.user-meta strong { display: block; font-size: 13px; }
.user-meta span { font-size: 11.5px; color: var(--text-faint); }

/* ---------- Sidebar contraído (solo íconos) ---------- */
.sidebar.collapsed { width: 76px; min-width: 76px; }
.sidebar.collapsed .sidebar-header { padding: 22px 0; flex-direction: column; gap: 14px; }
.sidebar.collapsed .brand-text { display: none; }
.sidebar.collapsed .collapse-btn { margin: 0 auto; }
.sidebar.collapsed .collapse-btn svg { transform: rotate(180deg); }
.sidebar.collapsed .nav-section-title {
  justify-content: center;
  padding: 12px 0 6px;
  margin: 6px 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar.collapsed .nav-section-title:first-child { border-top: none; margin-top: 0; }
.sidebar.collapsed .nav-section-icon svg { width: 16px; height: 16px; }
.sidebar.collapsed .nav-section-label { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 11px 0; }
.sidebar.collapsed .nav-item::before { left: -12px; }
.sidebar.collapsed .nav-label { display: none; }
.sidebar.collapsed .sidebar-footer { padding: 14px 0 18px; justify-content: center; }
.sidebar.collapsed .user-meta { display: none; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 66px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left { display: flex; align-items: center; gap: 16px; }

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.menu-toggle:hover { background: var(--bg); }

.crumbs { font-size: 13px; color: var(--text-faint); }
.crumbs b { color: var(--text); font-weight: 600; }

.page-title { font-size: 20px; font-weight: 700; margin: 0; }

.content { padding: 26px; flex: 1; }

/* ---------- Shared components ---------- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.card-header h2 { font-size: 15.5px; font-weight: 700; margin: 0; }

.card-body { padding: 20px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: "Inter", sans-serif;
  transition: filter 0.15s ease, background 0.15s ease;
}

.btn:hover { filter: brightness(0.96); }

.btn-primary { background: var(--teal-dark); color: #fff; }
.btn-primary:hover { background: #0e7b70; filter: none; }
.btn-secondary { background: var(--card-bg); color: var(--text); border-color: var(--border); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }

.search-input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  min-width: 220px;
  font-family: inherit;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--text-faint);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #fafbfd;
}

.data-table tbody tr:hover { background: #fafbff; }

/* Tablas con muchas columnas (p.ej. buscador de pedidos): menos padding para que
   entren sin scroll horizontal. */
.table-compact th, .table-compact td { padding: 8px 10px; }

.table-scroll { overflow-x: auto; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge-success { background: rgba(31, 182, 166, 0.13); color: var(--teal-dark); }
.badge-danger { background: rgba(228, 87, 76, 0.12); color: var(--red); }
.badge-warning { background: rgba(242, 169, 59, 0.15); color: #b5790c; }

/* ---------- Toggle switch (Métodos de pago / Zonas de envío) ---------- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: background 0.15s ease;
}
.switch-track::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: transform 0.15s ease; box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch input:checked + .switch-track { background: var(--teal); }
.switch input:checked + .switch-track::before { transform: translateX(18px); }
.switch input:disabled + .switch-track { opacity: 0.5; cursor: not-allowed; }

.input-inline {
  width: 110px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  font-family: inherit; color: var(--text);
}

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-faint); }
.empty-state h3 { margin: 0 0 6px; color: var(--text); font-family: "Sora", sans-serif; }

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--teal-dark);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  box-sizing: border-box;
}

.modal {
  background: var(--card-bg);
  border-radius: 16px;
  width: 100%;
  max-width: min(520px, 100%);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}

/* Header y footer fijos; solo el body hace scroll. Así el título y los botones
   de acción (Cancelar/Procesar) siempre quedan visibles, aunque el formulario
   sea más alto que la pantalla. */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.modal-header h3 { margin: 0; font-size: 15.5px; font-weight: 700; }

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg);
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover { background: var(--border); }

.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  flex: none;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

/* min-width:0 es necesario porque los ítems de grid/flex no se encogen por
   debajo de su contenido por defecto — sin esto, un <select> con una opción
   larga (p.ej. una descripción de catálogo SUNAT) desborda el modal en pantallas angostas. */
.form-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-field.full { grid-column: 1 / -1; }

.form-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  box-sizing: border-box;
  text-overflow: ellipsis;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus { border-color: var(--teal); background: #fff; }

.form-field textarea { resize: vertical; min-height: 70px; }

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  display: none;
}

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}

.toast {
  background: var(--navy-950);
  color: #fff;
  padding: 13px 18px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.3);
  min-width: 240px;
  animation: fadeIn 0.2s ease;
}

.toast.success { background: var(--teal-dark); }
.toast.error { background: var(--red); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Overlay (menú móvil) ---------- */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 25;
}
.overlay.show { display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.collapsed { width: 250px; min-width: 250px; }
  .menu-toggle { display: flex; }
  .collapse-btn { display: none; }
}
