:root {
  --ink: #18201b;
  --muted: #647067;
  --line: #dbe2d7;
  --paper: #f8f7f1;
  --panel: #ffffff;
  --green: #236345;
  --green-2: #174432;
  --gold: #c99432;
  --red: #a43a33;
  --blue: #315f8c;
  --shadow: 0 18px 42px rgba(31, 45, 35, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(35, 99, 69, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(35, 99, 69, 0.05) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: "Aptos", "Segoe UI", sans-serif;
}

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

.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 460px) 1fr;
}

.login-panel {
  background: var(--panel);
  padding: 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-right: 1px solid var(--line);
}

.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 0.95;
  margin: 0 0 18px;
  letter-spacing: 0;
}

.login-visual {
  position: relative;
  overflow: hidden;
  min-height: 420px;
  background:
    linear-gradient(135deg, rgba(24, 32, 27, 0.82), rgba(35, 99, 69, 0.72)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='700' viewBox='0 0 900 700'%3E%3Cg fill='none' stroke='%23f4dfaa' stroke-width='3'%3E%3Cpath d='M84 108h220v168H84zM304 108h172v168H304zM476 108h264v168H476zM84 276h158v210H84zM242 276h234v210H242zM476 276h264v210H476zM84 486h326v118H84zM410 486h330v118H410z'/%3E%3Cpath d='M84 108 42 72M304 108l-28-66M476 108l36-70M740 276l80-26M242 486l-66 84M410 486l120 96'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
}

.login-visual::after {
  content: "Bloqueado -> Vendido";
  position: absolute;
  right: 32px;
  bottom: 32px;
  color: #fff6df;
  border: 1px solid rgba(255, 246, 223, 0.6);
  padding: 12px 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.hint {
  color: var(--muted);
  line-height: 1.5;
}

.form {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 6px;
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(35, 99, 69, 0.12); }

/* Focus visible más marcado para navegación por teclado */
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 1px;
}
.btn:focus-visible, .nav button:focus-visible, .tabs button:focus-visible, .link-cell:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Validación visual — solo se aplica tras la primera interacción del usuario (:user-invalid) */
input:user-invalid, select:user-invalid, textarea:user-invalid {
  border-color: var(--red);
  background: #fdf5f4;
}
input:user-invalid:focus, select:user-invalid:focus, textarea:user-invalid:focus {
  box-shadow: 0 0 0 3px rgba(164, 58, 51, 0.12);
}

.btn {
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
  background: var(--green);
  color: white;
  font-weight: 800;
}

.btn:hover { background: var(--green-2); }
.btn.secondary { background: #e7ebdf; color: var(--ink); }
.btn.warning { background: var(--gold); color: #241704; }
.btn.danger { background: var(--red); }
.btn:disabled {
  opacity: 1;
  cursor: not-allowed;
  background: #b8c4bb;
  color: #556258;
  box-shadow: none;
}
.btn:disabled:hover { background: #b8c4bb; }
.btn.danger:disabled { background: #d2b0ad; color: #5c3937; }
.btn.warning:disabled { background: #d9c48f; color: #62501e; }
.btn.btn-sm { padding: 5px 10px; font-size: 12px; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}

.sidebar {
  background: #17231b;
  color: #f4f2e9;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar h1 {
  font-family: Georgia, "Times New Roman", serif;
  margin: 0;
  font-size: 28px;
  line-height: 1;
}

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

.nav button {
  text-align: left;
  border: 0;
  background: transparent;
  color: #dce5d7;
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
}

.nav button.active, .nav button:hover { background: rgba(255, 255, 255, 0.1); color: white; }

.userbox {
  margin-top: auto;
  font-size: 13px;
  color: #b9c6bb;
  border-top: 1px solid rgba(255,255,255,0.14);
  padding-top: 16px;
}

.content {
  padding: 28px;
  overflow: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 22px;
}

.topbar h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 36px;
}

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

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric strong {
  display: block;
  font-size: 28px;
  margin-top: 8px;
}

.metric-link { transition: transform 0.1s ease; }
.metric-link:hover { transform: translateY(-2px); border-color: var(--green); }
.metric-link small { display: block; margin-top: 6px; font-size: 11px; }

.filter-inline {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  margin-bottom: 10px;
}
.filter-inline input[type=search] {
  flex: 1;
  padding: 8px 12px;
}

.dup-warn {
  background: #fff1cf;
  color: #7b520e;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  border-left: 3px solid var(--gold);
}

.link-cell {
  background: transparent;
  border: 0;
  color: var(--green);
  cursor: pointer;
  padding: 0;
  text-align: left;
  font: inherit;
  text-decoration: underline;
}
.link-cell:hover { color: var(--green-2); }

.detail-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.metric span, .label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 800;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  gap: 16px;
  align-items: start;
}

.section-title {
  margin: 0 0 12px;
  font-size: 18px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  background: #edf1e6;
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 2px solid var(--line);
}

/* Filas alternadas para reducir fatiga visual en tablas largas */
tbody tr:nth-child(even) td {
  background: rgba(35, 99, 69, 0.025);
}

tbody tr:hover td {
  background: rgba(35, 99, 69, 0.06);
}

/* Empty state con más contexto */
tbody tr td[colspan] {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  font-style: italic;
  background: transparent;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 800;
  background: #dde9df;
  color: var(--green-2);
  border: 1px solid #b4cebc;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.pill.warn { background: #ffe7a8; color: #5e3f08; border-color: #d9a83e; }
.pill.red { background: #f5c5c2; color: #6c1e18; border-color: #c47771; }
.pill.blue { background: #cddef0; color: #1e3f5c; border-color: #6f95ba; }
.pill.gray { background: #e0e3df; color: #414944; border-color: #a9b1a9; }

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tabs button {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
}

.tabs button.active { background: var(--ink); color: white; border-color: var(--ink); }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.error { color: var(--red); font-weight: 700; min-height: 20px; }
.ok { color: var(--green); font-weight: 800; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 32, 27, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 9998;
  animation: modal-fade 0.15s ease-out;
}

.modal {
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: 560px;
  width: 100%;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

.modal-wide { max-width: 960px; }
.modal-view-content .detail-section { margin-top: 18px; }
.modal-view-content .detail-section h4 {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.modal-view-content .two > div { padding: 4px 0; }

/* Recibo imprimible */
.receipt {
  background: #fff;
  padding: 24px 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: "Aptos", "Segoe UI", sans-serif;
}
.receipt-head {
  display: flex;
  justify-content: space-between;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 12px;
  margin-bottom: 14px;
}
.receipt-head h4 { margin: 0 0 4px; font-size: 22px; font-family: Georgia, serif; }
.receipt-num { margin: 0; color: var(--muted); font-weight: 700; }

.receipt-empresa { line-height: 1.4; font-size: 13px; color: var(--ink); }
.receipt-empresa-name {
  font-family: Georgia, serif;
  font-size: 18px;
  display: block;
  margin-bottom: 4px;
}
.receipt-nota {
  margin: 16px 0 0;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}

.receipt-warning {
  background: #fff1cf;
  color: #5e3f08;
  border: 1px solid #d9a83e;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 14px;
  text-align: center;
}

@media print {
  .no-print { display: none !important; }
}
.receipt-status { text-align: right; }
.receipt-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 18px;
  font-size: 14px;
  line-height: 1.5;
}
.receipt-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
  margin-bottom: 12px;
}
.receipt-table th, .receipt-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.receipt-table .right { text-align: right; }
.receipt-table tfoot th {
  border-top: 2px solid var(--ink);
  font-size: 15px;
  background: transparent;
  color: var(--ink);
}
.receipt-meta {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  font-size: 13px;
  margin: 12px 0;
}
.receipt-void {
  border: 2px solid var(--red);
  background: #fdf1f0;
  color: var(--red);
  padding: 10px;
  border-radius: 4px;
  margin: 14px 0;
  text-align: center;
  font-size: 13px;
}
.receipt-foot {
  display: flex;
  justify-content: space-around;
  margin-top: 40px;
  font-size: 12px;
  color: var(--muted);
}
.receipt-foot .signature { text-align: center; }

@media print {
  body > *:not(.modal-backdrop) { display: none !important; }
  .modal-backdrop {
    position: static !important;
    background: transparent !important;
    padding: 0 !important;
  }
  .modal-backdrop:not(:has(.modal-printable)) { display: none !important; }
  .modal.modal-printable {
    max-width: 100% !important;
    max-height: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }
  .modal-head, .modal-foot { display: none !important; }
  .modal-body { padding: 0 !important; }
  .toast-container { display: none !important; }
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 18px; }

.modal-close {
  background: transparent;
  border: 0;
  font-size: 22px;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--ink); }

.modal-body {
  padding: 20px;
  display: grid;
  gap: 12px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

.filter-form { gap: 10px; }
.filter-form button[type=submit] { width: fit-content; }

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  max-width: 420px;
}

.toast {
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 14px;
  line-height: 1.4;
  animation: toast-in 0.18s ease-out;
}

.toast button {
  background: transparent;
  border: 0;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  opacity: 0.7;
}
.toast button:hover { opacity: 1; }

.toast-success { background: var(--green-2); }
.toast-error { background: var(--red); }
.toast-info { background: var(--blue); }

@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ─────────────────────────────────────────────────────────────
   RESPONSIVE
   Breakpoints: 1024 tablet, 768 tablet chico, 560 mobile grande, 400 mobile
   ───────────────────────────────────────────────────────────── */

/* Tablet: 3 columnas en grid, 2 en layout */
@media (max-width: 1024px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  .modal-wide { max-width: 92vw; }
}

/* Tablet chico / laptop pequeña: sidebar colapsa horizontalmente */
@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
    flex-wrap: wrap;
  }
  .sidebar h1 {
    font-size: 20px;
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .sidebar h1 br { display: none; }
  .nav {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1 1 auto;
  }
  .nav button {
    padding: 8px 12px;
    font-size: 13px;
  }
  .userbox {
    margin-top: 0;
    border-top: 0;
    padding-top: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    font-size: 12px;
    line-height: 1.2;
  }
  .userbox br { display: none; }
  .userbox strong { display: inline; }
  .userbox .btn { margin: 0 !important; }

  .layout { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-visual { display: none; }
  .login-panel { padding: 32px 24px; }
}

/* Mobile grande / tablet vertical: cards en 2 columnas */
@media (max-width: 768px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; }
  .content { padding: 20px 16px; }
  .modal-body { padding: 16px; }
  .receipt-parties { grid-template-columns: 1fr; gap: 12px; }
  .receipt-meta { grid-template-columns: 1fr; }
  .receipt-foot { flex-direction: column; gap: 24px; margin-top: 28px; }
}

/* Mobile: todo a 1 columna */
@media (max-width: 560px) {
  .grid, .two { grid-template-columns: 1fr; }
  .metric strong { font-size: 22px; }
  .topbar h2 { font-size: 24px; }
  .brand { font-size: 32px; }
  .content { padding: 16px 12px; }
  .card { padding: 14px; }
  .tabs { gap: 4px; }
  .tabs button { padding: 6px 10px; font-size: 13px; }
  .modal { max-width: 100%; border-radius: 0; }
  .modal-backdrop { padding: 0; }
  .modal-wide { max-width: 100%; }
  .modal-head { padding: 14px 16px; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
  .toast-container { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .filter-inline { flex-direction: column; align-items: stretch; gap: 8px; }
  .receipt { padding: 16px 12px; }
  .receipt-head { flex-direction: column; gap: 12px; }
  .receipt-status { text-align: left; }
}

/* Mobile chico */
@media (max-width: 400px) {
  .sidebar h1 { font-size: 18px; }
  .nav button { padding: 6px 10px; font-size: 12px; }
  .content { padding: 12px 10px; }
}

/* Scroll horizontal amable en tablas con hint visual */
.table-wrap {
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* Priorizar el scroll táctil y evitar el rebote horizontal en toda la página */
@media (max-width: 900px) {
  body { overscroll-behavior-x: none; }
}
