* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --danger: #dc2626;
  --success: #16a34a;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

.app-header {
  background: var(--text);
  color: white;
  padding: 16px 0;
  margin-bottom: 20px;
}

.app-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-size: 20px;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.card h2 { margin-bottom: 6px; font-size: 18px; }
.card h3 { margin-bottom: 6px; font-size: 16px; }

.muted { color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost { background: transparent; color: #cbd5e1; border-color: #475569; }
.btn-ghost:hover { background: #1e293b; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
}
.badge-muted { background: #475569; color: #e2e8f0; }
.badge-ok { background: var(--success); color: #fff; }

input[type="text"], input[type="password"], input[type="file"], select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}

input[type="file"] { padding: 6px; }

/* Summary grid */
.grid-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.card.summary { margin-bottom: 0; text-align: center; padding: 16px; }
.summary-label { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.summary-value { font-size: 26px; font-weight: 700; margin: 4px 0; }
.summary-sub { font-size: 12px; color: var(--muted); }

.grid-upload {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

/* Filter row */
.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.filter-controls {
  display: flex;
  gap: 8px;
}
.filter-controls select { width: auto; }
.filter-controls input[type="text"] { width: 280px; }

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.table th {
  background: #f8fafc;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--primary); }
.table th.sorted { color: var(--primary); }
.sort-ind { font-size: 10px; }
.table tr:hover td { background: #f8fafc; }

.checkbox-cell { display: flex; align-items: center; justify-content: center; }
input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }

.category-select {
  padding: 4px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
  max-width: 170px;
}

.category-select[data-field="category"] {
  background: #ffffff;
  color: #16a34a;
  font-weight: 600;
  border-color: #94a3b8;
}
.category-select[data-field="category"]:focus { outline: none; border-color: #16c784; }

.category-input {
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid #94a3b8;
  font-size: 13px;
  width: 140px;
  background: #ffffff;
  color: #16a34a;
  font-weight: 600;
}
.category-input::placeholder { color: #000000; font-weight: 400; }
.category-input:focus { outline: none; border-color: #16c784; }

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 8px;
}
.pill-cuota { background: #fef3c7; color: #92400e; }
.pill-pago { background: #dcfce7; color: #166534; }
.pill-no { background: #f1f5f9; color: #64748b; }

#upload-result { border-left: 4px solid var(--primary); }
#upload-result.error { border-left-color: var(--danger); }

/* Description cell */
.desc-cell { cursor: help; position: relative; }
.desc-cell .info-hint {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  color: var(--primary);
  opacity: .7;
}

/* Info popover */
.info-popover {
  position: absolute;
  z-index: 1000;
  min-width: 240px;
  width: fit-content;
  max-width: 92vw;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
  font-size: 12px;
}
.info-popover[hidden] { display: none; }
.popover-title {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: #94a3b8;
  border-bottom: 1px solid #334155;
  padding-bottom: 6px;
  margin-bottom: 6px;
}
.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.popover-copy {
  background: #334155;
  color: #e2e8f0;
  border: 1px solid #475569;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.popover-copy { margin-left: auto; }
.popover-copy:hover { background: #475569; }
.popover-close {
  background: transparent;
  color: #94a3b8;
  border: none;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.popover-close:hover { color: #f8fafc; background: #334155; }
.popover-note {
  background: #0d3b2e;
  border: 1px solid #1c6b50;
  color: #7ee2b8;
  border-radius: 5px;
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 11px;
}
.popover-row { display: flex; gap: 12px; padding: 2px 0; }
.popover-key { color: #94a3b8; width: 90px; flex-shrink: 0; }
.popover-val { color: #f1f5f9; word-break: break-word; }

/* Raw PDF line: monospace, keep whitespace, no wrapping */
.popover-raw {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.5;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 8px;
  color: #e2e8f0;
  white-space: pre;
  overflow: hidden;
}

/* Transfer evidence photo */
.transfer-cell { gap: 6px; }
.photo-btn {
  background: transparent;
  border: 1px solid #475569;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1;
  padding: 2px 5px;
  cursor: pointer;
  opacity: .7;
}
.photo-btn:hover { opacity: 1; border-color: var(--primary); }
.photo-btn.has-photo { border-color: #16c784; background: rgba(22,199,132,.15); opacity: 1; }

/* Merge (fusionar) button on unbilled rows + dupped row styling */
.merge-btn {
  background: transparent;
  border: 1px solid #475569;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
  padding: 2px 5px;
  margin-left: 6px;
  cursor: pointer;
  opacity: .7;
}
.merge-btn:hover { opacity: 1; border-color: var(--primary); }
.row-dupped { opacity: .5; }
.cuota-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 10px;
  border-radius: 999px;
  background: #1e3a5f;
  color: #7dd3fc;
  letter-spacing: .04em;
  white-space: nowrap;
}
.dupped-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 10px;
  border-radius: 999px;
  background: #334155;
  color: #cbd5e1;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.merge-list .merge-option { display: flex; align-items: baseline; gap: 8px; cursor: pointer; }
.merge-list .merge-fate { display: block; font-size: 11px; margin-left: 24px; }
.merge-window-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; margin: 6px 0; cursor: pointer; }

.photo-modal {
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.photo-modal-box {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 18px;
  max-width: min(720px, 92vw);
  width: fit-content;
}
.photo-modal-box h3 { margin: 0 0 12px; color: #e2e8f0; }
.photo-preview {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 8px;
  display: block;
  margin-bottom: 12px;
}
.photo-modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Transfer modal */
.transfer-box { max-width: 560px; width: min(560px, 92vw); }
.transfer-summary { background: #1e293b; border: 1px solid #334155; border-radius: 8px; padding: 12px; margin-bottom: 14px; }
.transfer-total { font-size: 20px; display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.transfer-total b { color: #7ee2b8; }
.transfer-list { margin: 0; padding-left: 18px; max-height: 180px; overflow: auto; color: #cbd5e1; font-size: 13px; }
.transfer-list li { margin-bottom: 4px; }
.transfer-photo-zone { margin-bottom: 14px; }
.transfer-photo-zone p { margin: 0 0 8px; }
.photo-drop {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 1px dashed #475569; border-radius: 8px; padding: 16px;
  cursor: pointer; background: #0b1220;
}
.photo-drop:hover { border-color: var(--primary); }
/* Author display rules beat the UA [hidden] rule; keep hidden reliable. */
[hidden] { display: none !important; }
.photo-drop.dragging { border-color: var(--primary); background: #10233a; }
.photo-drop-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.photo-drop-empty .drop-icon { color: #64748b; }
.photo-drop-title { font-size: 13px; color: #cbd5e1; }
.photo-drop-hint { font-size: 12px; color: #64748b; }
.photo-drop-file { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #7ee2b8; }
.photo-drop-file .drop-icon-sm { color: #7ee2b8; }
.photo-drop-filename { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.photo-file-remove { background: none; border: 1px solid #475569; border-radius: 6px; color: #94a3b8; cursor: pointer; font-size: 11px; padding: 2px 6px; }
.photo-file-remove:hover { color: #f87171; border-color: #f87171; }
.photo-drop .photo-preview { max-height: 260px; margin: 0; }

/* Per-row comprobante modal: preview / empty drop area */
.photo-drop-target { min-height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 8px; }
.photo-drop-target.dragging { background: #10233a; outline: 2px dashed var(--primary); outline-offset: -4px; }
.photo-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; border: 1px dashed #475569; border-radius: 8px; padding: 18px; font-size: 13px; color: #cbd5e1; cursor: pointer; }
.photo-empty .drop-icon { color: #64748b; }
.photo-pdf-link { display: inline-flex; align-items: center; gap: 8px; color: #7ee2b8; font-size: 14px; padding: 10px 0; }
/* Comprobante modal: compact preview (~480p), click opens full size */
.transfer-photo-content .photo-full { display: block; }
.transfer-photo-content .photo-preview {
  max-width: min(480px, 100%);
  max-height: 360px;
  width: auto;
  height: auto;
  cursor: zoom-in;
}

/* Transfers history view */
.transfers-list { max-height: 60vh; overflow: auto; }
.transfer-card { border: 1px solid #334155; border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: #1e293b; }
.transfer-card-head { display: flex; gap: 12px; align-items: center; font-size: 14px; color: #e2e8f0; cursor: pointer; user-select: none; }
.transfer-caret { color: #64748b; font-size: 11px; width: 12px; }
.transfer-count { font-size: 12px; }
.transfer-card-head span:nth-child(2) { margin-left: auto; color: #7ee2b8; }
.transfer-photo-ind { cursor: pointer; font-size: 15px; }
.transfer-photo-ind:hover { transform: scale(1.2); }
.transfer-card .transfer-list { margin-top: 8px; font-size: 12.5px; max-height: none; }

.transfer-card-body { margin-top: 8px; padding-top: 8px; border-top: 1px solid #334155; }
.transfer-photo-inline { margin-bottom: 8px; text-align: center; }
.transfer-photo-thumb { max-width: 100%; max-height: 180px; border-radius: 6px; border: 1px solid #334155; cursor: pointer; }
.transfer-photo-thumb:hover { transform: scale(1.02); opacity: 0.9; }

.transfer-related-list { margin-top: 12px; padding-top: 12px; border-top: 1px solid #334155; }
.transfer-info { display: flex; gap: 16px; margin-bottom: 8px; font-size: 13px; color: #94a3b8; }
.transfer-list { margin: 0; padding-left: 18px; color: #cbd5e1; font-size: 13px; }
.transfer-list li { margin-bottom: 4px; }



