:root {
  --canvas: #f6f7f4;
  --surface: #ffffff;
  --sidebar: #0c1b1e;
  --sidebar-hover: #162c30;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #ccfbf1;
  --text: #0f172a;
  --muted: #5b6870;
  --border: #e4e8e5;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --info: #0369a1;
  --font-display: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--canvas);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* TOASTS */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--sidebar);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(12, 27, 30, 0.22);
  border-left: 4px solid var(--primary);
}
.toast.error { border-left-color: var(--danger); }

/* AUTH SCREEN */
.auth-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
}
.auth-panel-left {
  background: var(--sidebar);
  color: #fff;
  padding: 56px 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 36px;
}
.auth-panel-left h1 {
  font-family: var(--font-display);
  font-size: 36px;
  line-height: 1.18;
  margin: 0 0 18px;
}
.auth-panel-left > p {
  color: #9fb3b8;
  font-size: 16px;
  line-height: 1.6;
  max-width: 520px;
  margin: 0 0 36px;
}
.auth-highlights { display: grid; gap: 14px; max-width: 480px; }
.highlight-item {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.09);
  padding: 14px 18px;
  border-radius: 12px;
}
.highlight-item strong { display: block; font-size: 14px; margin-bottom: 3px; color: #5eead4; }
.highlight-item span { font-size: 13px; color: #cbd5e1; }

.auth-panel-right {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.05);
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--canvas);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 24px;
}
.auth-tab {
  border: none;
  background: transparent;
  padding: 9px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form h2 { font-family: var(--font-display); margin: 0; font-size: 22px; }
.muted-text { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.full-btn { width: 100%; padding: 11px; font-size: 14px; margin-top: 6px; }

/* LAYOUT */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 272px;
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255,255,255,0.09);
}
.brand-mark {
  background: var(--primary);
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 9px 11px;
  border-radius: 10px;
  font-size: 13px;
}
.brand h1 { font-family: var(--font-display); margin: 0; font-size: 17px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: #94a3b8; }

.tenant-switcher {
  margin-top: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
}
.tenant-switcher label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  margin-bottom: 6px;
}
.tenant-switcher select {
  width: 100%;
  background: #0f2428;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 13px;
}

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 18px; flex: 1; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: #cbd5e1;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-dot { width: 6px; height: 6px; border-radius: 50%; background: transparent; }
.nav-btn:hover { background: var(--sidebar-hover); color: #fff; }
.nav-btn.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-btn.active .nav-dot { background: #5eead4; }
.nav-btn.sub { padding-left: 24px; font-size: 13px; }
.nav-accordion { display: flex; flex-direction: column; margin-top: 4px; }
.nav-group-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: transparent;
  border: none;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  padding: 9px 12px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 8px;
}
.nav-group-toggle:hover { background: rgba(255,255,255,0.04); color: #fff; }
.nav-group-toggle .chevron { transition: transform 0.15s; font-size: 12px; }
.nav-accordion:not(.open) .nav-group-toggle .chevron { transform: rotate(-90deg); }
.nav-group-items { display: none; flex-direction: column; gap: 3px; }
.nav-accordion.open .nav-group-items { display: flex; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.09);
}
.user-pill { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}
.user-meta strong { display: block; font-size: 13px; }
.user-meta span { font-size: 11px; color: #94a3b8; word-break: break-all; }

.env-badge {
  text-align: center;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.env-badge.stage { background: #fef3c7; color: #92400e; }
.db-status { font-size: 11px; color: #94a3b8; text-align: center; }

/* MAIN */
.main { flex: 1; padding: 26px 34px; overflow-x: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.topbar h2 { font-family: var(--font-display); margin: 0; font-size: 24px; }
.topbar-sub { margin: 3px 0 0; font-size: 13px; color: var(--muted); }
.topbar-actions { display: flex; gap: 10px; }

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

/* STATS & CHARTS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  border-top: 3px solid var(--primary);
}
.stat-card.success { border-top-color: var(--success); }
.stat-card.info { border-top-color: var(--info); }
.stat-card.warning { border-top-color: var(--warning); }
.stat-card.danger { border-top-color: var(--danger); }

.stat-label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 6px; }
.stat-value { font-family: var(--font-display); font-size: 28px; display: block; }
.stat-hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; display: block; }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 18px;
  margin-bottom: 20px;
}
.donut-wrap { display: flex; align-items: center; gap: 22px; }
.donut-svg { width: 155px; height: 155px; flex-shrink: 0; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.legend-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.legend-left { display: flex; align-items: center; gap: 8px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.bar-svg { width: 100%; height: 170px; }

/* CARDS & TABLES */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 20px;
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-header h3 { font-family: var(--font-display); margin: 0; font-size: 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; background: #fafbfa; font-size: 12px; }
.mono { font-family: var(--font-mono); font-size: 12px; }

.badge {
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  display: inline-block;
}
.badge.ACEPTADO { background: #dcfce7; color: #166534; }
.badge.SENT, .badge.PROCESANDO { background: #e0f2fe; color: #075985; }
.badge.CONTINGENCIA { background: #fef3c7; color: #92400e; }
.badge.RECHAZADO, .badge.ERROR, .badge.SUSPENDED, .badge.OVERDUE { background: #fee2e2; color: #991b1b; }
.badge.ACTIVE, .badge.PAID { background: #dcfce7; color: #166534; }
.badge.INACTIVE, .badge.DUE { background: #fef3c7; color: #92400e; }

.ghost-banner {
  background: #0f172a;
  color: #fef3c7;
  padding: 10px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  border-left: 4px solid #f59e0b;
}

/* FORMS */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  width: 100%;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: var(--font-body);
  background: #fff;
}
.input-with-btn {
  display: flex;
  gap: 6px;
  width: 100%;
  min-width: 0;
}
.input-with-btn input { flex: 1; min-width: 0; }
.input-with-btn .btn { flex-shrink: 0; }

.contact-search-wrap { position: relative; width: 290px; max-width: 100%; }
.contact-search-wrap input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12.5px;
}
.contact-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(12, 27, 30, 0.14);
  max-height: 210px;
  overflow-y: auto;
  z-index: 50;
}
.contact-result-item {
  padding: 8px 10px;
  font-size: 12.5px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}
.contact-result-item:last-child { border-bottom: none; }
.contact-result-item:hover { background: var(--canvas); }
.field input:focus, .field select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

.doc-type-highlight {
  background: #f0fdfa;
  border: 1.5px solid #99f6e4;
  border-radius: 12px;
  padding: 14px 16px;
}
.doc-type-bar {
  margin-bottom: 20px;
}
.doc-type-highlight label {
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 700;
}
.doc-type-highlight select {
  font-size: 15px;
  font-weight: 600;
  border-color: #5eead4;
}

.section-divider {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.cabys-helper { display: flex; gap: 8px; }
.cabys-helper input { padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 12.5px; width: 280px; }
.cabys-results {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
  background: var(--canvas);
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.cabys-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 12.5px;
  cursor: pointer;
  border: 1px solid var(--border);
}
.cabys-item:hover { border-color: var(--primary); }

.lines-container { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 12px; }
.line-row {
  display: grid;
  grid-template-columns: 1.3fr 1.8fr 0.9fr 0.7fr 1fr 0.9fr auto;
  gap: 10px;
  align-items: end;
  background: var(--canvas);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.total-bar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.totals-summary { display: flex; gap: 20px; font-size: 14px; }
.totals-summary strong { font-family: var(--font-mono); color: var(--primary); }

.btn {
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { background: #e7ece9; color: var(--text); }
.btn.ghost { background: rgba(255,255,255,0.08); color: #cbd5e1; }
.btn.danger-outline { background: #fee2e2; color: #991b1b; }
.btn.sm { padding: 6px 10px; font-size: 12px; }

.result-box {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #f1f5f9;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
}
.result-box.error { background: #fee2e2; color: #991b1b; font-family: var(--font-body); font-size: 13px; }

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 27, 30, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.modal-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(12, 27, 30, 0.25);
}

/* POS */
.pos-layout {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
  align-items: start;
}
.pos-status-bar { display: flex; align-items: center; gap: 10px; }
.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--canvas);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.pos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 12px;
}
.pos-item-btn {
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.pos-item-btn:hover { border-color: var(--primary); transform: translateY(-1px); }
.pos-item-btn strong { display: block; font-size: 13.5px; margin-bottom: 4px; }
.pos-item-btn span { font-family: var(--font-mono); font-size: 13px; color: var(--primary); font-weight: 600; }
.pos-cart-items { display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto; margin-bottom: 14px; }
.pos-cart-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--canvas);
  border-radius: 8px;
  font-size: 13px;
}
.pos-summary { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.pos-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.pos-row.total { font-size: 17px; color: var(--text); font-weight: 700; margin-top: 4px; }

/* MODAL ACCIONES & REIMPRESIÓN */
.doc-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.doc-action-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.doc-action-card:hover { border-color: var(--primary); background: #f8fafc; }
.doc-action-card strong { display: block; font-size: 13.5px; }
.doc-action-card span:not(.act-icon) { font-size: 12px; color: var(--muted); }
.act-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  flex-shrink: 0;
}
.act-icon.pdf { background: #be123c; }
.act-icon.xml { background: #15803d; }
.act-icon.resp { background: #db2777; }
.act-icon.mail { background: #0284c7; }
.act-icon.eye { background: #6d28d9; }
.act-icon.link { background: #d97706; }

.reprint-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 10px;
}
.reprint-tab {
  border: 1px solid var(--border);
  background: var(--canvas);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.reprint-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.reprint-frame {
  width: 100%;
  height: 400px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #334155;
}

@media (max-width: 960px) {
  .pos-layout { grid-template-columns: 1fr; }
}

@media (max-width: 960px) {
  .auth-screen { grid-template-columns: 1fr; }
  .auth-panel-left { display: none; }
  .layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .charts-grid { grid-template-columns: 1fr; }
  .line-row { grid-template-columns: 1fr 1fr; }
}
