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

:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1a2233;
  --muted: #6b7488;
  --border: #e5e8f0;
  --border-strong: #d3d8e4;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #e6f4f2;
  --danger: #dc2626;
  --success: #16a34a;
  --amber: #92400e;
  --amber-soft: #fdf0d5;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(26, 34, 51, .05), 0 4px 16px rgba(26, 34, 51, .04);
  --row-hover: #f7f9fc;
}

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: 1240px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- Auth gate ---------- */
.auth-buttons { display: flex; gap: 8px; }
.auth-buttons .btn { flex: 1; }
.auth-token-box { margin-top: 14px; font-size: 12.5px; }
.auth-token-box summary { cursor: pointer; }
.auth-token-box .stack { margin-top: 8px; }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(20, 27, 45, .92);
  backdrop-filter: blur(8px);
  color: white;
  padding: 14px 0;
  margin-bottom: 24px;
}

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

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.01em;
}

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

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

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

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

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

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s;
}

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(15, 118, 110, .3); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost { background: transparent; color: #cbd5e1; border-color: rgba(255, 255, 255, .25); }
.btn-ghost:hover { background: rgba(255, 255, 255, .1); }

.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.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; }

/* ---------- Inputs ---------- */
input[type="text"], input[type="password"], input[type="file"], select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

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

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

.card.summary {
  margin-bottom: 0;
  text-align: center;
  padding: 18px 16px;
}
.summary-label { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); font-weight: 600; }
.summary-value { font-size: 27px; font-weight: 700; margin: 6px 0 2px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.summary-sub { font-size: 12px; color: var(--muted); }

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

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

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

/* ---------- Table ----------
   Fixed layout: the th nth-child widths below define the grid, the
   description column absorbs the rest. (width:100% on a td would have made
   the table wider than the card, so the row borders ran past its edge.) */
.table {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}
.table th, .table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.table th {
  background: transparent;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.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 tbody tr { transition: background .1s; }
.table tbody tr:hover td { background: var(--row-hover); }

/* Column sizing (table-layout: fixed): description (2) takes what is left */
.table th:nth-child(1) { width: 110px; }
.table th:nth-child(3) { width: 135px; }
.table th:nth-child(4) { width: 190px; }
.table th:nth-child(5) { width: 120px; }
.table th:nth-child(6) { width: 140px; }

td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* NOTE: keep td.checkbox-cell as a table-cell (display:flex on a td stops it
   stretching to the row height and its border renders misaligned). */
.checkbox-cell { text-align: center; white-space: nowrap; }
.checkbox-cell input[type="checkbox"] { vertical-align: middle; margin-right: 6px; }
.checkbox-cell .photo-btn { vertical-align: middle; }
input[type="checkbox"] { width: 17px; height: 17px; cursor: pointer; accent-color: var(--primary); }

/* Table selects (Tipo / Categoría) rendered as visible compact chips */
.category-select {
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: #fff;
  font-size: 13.5px;
  width: auto;
  min-width: 108px;
  max-width: 170px;
  transition: border-color .12s;
}
.category-select:hover { border-color: var(--primary); }

.category-select[data-field="category"] {
  color: #16a34a;
  font-weight: 600;
  width: 100%;
  min-width: 140px;
}
.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 ----------
   One stable line: text + badges + actions right after the text (never
   pinned to the far edge), comment chip on its own content-sized line. */
.desc-cell { cursor: help; overflow: hidden; }
.desc-main {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.desc-text {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.desc-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.desc-cell .info-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 1px solid var(--primary);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  font-style: italic;
  color: var(--primary);
  opacity: .5;
}
.desc-cell .info-hint:hover { opacity: 1; }

/* Ghost icon buttons (inline SVG): quiet until hovered, tinted when they
   carry state. SVG icons never clip like emoji glyphs did. */
.photo-btn, .comment-btn, .merge-btn, .discard-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  flex-shrink: 0;
  cursor: pointer;
  opacity: .55;
  transition: opacity .12s, background .12s, border-color .12s, color .12s;
}
.photo-btn:hover, .comment-btn:hover, .merge-btn:hover, .discard-btn:hover {
  opacity: 1;
  background: #eef1f7;
  border-color: var(--border);
  color: var(--text);
}
.photo-btn.has-photo { border-color: #16c784; background: rgba(22, 199, 132, .14); color: #047857; opacity: 1; }
.comment-btn.has-comment { border-color: #f59e0b; background: rgba(245, 158, 11, .14); color: #b45309; opacity: 1; }
.table tbody tr:hover .photo-btn,
.table tbody tr:hover .comment-btn,
.table tbody tr:hover .merge-btn,
.table tbody tr:hover .discard-btn { opacity: .9; }

/* Comment chip under the description: content-sized, ellipsized when long */
.comment-chip {
  display: inline-block;
  margin-top: 3px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--amber);
  background: var(--amber-soft);
  border-radius: 7px;
  padding: 0 8px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Comment modal */
.comment-box .comment-input {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  font: inherit;
  margin: 8px 0 12px;
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #475569;
  border-radius: 8px;
  padding: 8px 10px;
}
.comment-box .comment-input:focus { outline: none; border-color: var(--primary); }
.comment-txn-info { font-size: 13px; margin: 6px 0 2px; }

/* ---------- Row states & badges ---------- */
.row-dupped { opacity: .5; }
.cuota-badge {
  display: inline-block;
  padding: 1px 7px;
  font-size: 10px;
  border-radius: 999px;
  background: #1e3a5f;
  color: #7dd3fc;
  letter-spacing: .04em;
  white-space: nowrap;
  flex-shrink: 0;
}
.dupped-badge {
  display: inline-block;
  padding: 1px 7px;
  font-size: 10px;
  border-radius: 999px;
  background: #334155;
  color: #cbd5e1;
  text-transform: uppercase;
  letter-spacing: .04em;
  flex-shrink: 0;
}
.forecast-badge {
  display: inline-block;
  padding: 1px 7px;
  font-size: 10px;
  border-radius: 999px;
  background: #42310a;
  color: #fcd34d;
  letter-spacing: .04em;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---------- Info popover ----------
   Fixed sane width; long raw lines wrap instead of breaking the layout. */
.info-popover {
  position: absolute;
  z-index: 1000;
  width: min(620px, 92vw);
  max-width: 92vw;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  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;
  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; min-width: 0; }

/* Unbilled original absorbed by a manual merge (shown inside the popover) */
.popover-merged {
  margin: 6px 0;
  padding: 6px 8px 8px;
  border: 1px dashed #475569;
  border-radius: 6px;
  background: rgba(148, 163, 184, .08);
}
.popover-merged + .popover-merged { margin-top: -2px; }
.popover-merged-head {
  color: #cbd5e1;
  font-size: 11px;
  margin-bottom: 4px;
}

/* Raw PDF line: monospace, wraps; collapsed to 2 lines until clicked */
.popover-raw {
  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: 4px;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: zoom-in;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.popover-raw:hover { border-color: #475569; }
.info-popover.raw-expanded .popover-raw {
  cursor: zoom-out;
  display: block;
  -webkit-line-clamp: unset;
  max-height: 40vh;
  overflow: auto;
}
.popover-raw-hint { font-size: 10.5px; text-align: right; margin-bottom: 6px; cursor: pointer; }
.popover-raw-hint:hover { color: #cbd5e1; }

/* ---------- Merge modal ---------- */
.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; }

/* ---------- Modals ---------- */
.photo-modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.photo-modal-box {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 20px;
  max-width: min(720px, 92vw);
  width: fit-content;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .35);
}
.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; margin-top: 14px; }
.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: 10px; 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-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: 10px; 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: 10px; 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; }

/* ---------- Pendientes del período (full-page view) ---------- */
.period-page { display: flex; flex-direction: column; }
.period-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.period-head h3 { margin-bottom: 2px; }
.period-head .muted { font-size: 12.5px; }
.period-head button { margin-left: auto; }
.period-total {
  position: sticky;
  top: 64px;
  z-index: 40;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--primary-soft);
  box-shadow: var(--shadow);
}
.period-total .summary-label { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.period-total .summary-value { font-size: 26px; font-weight: 700; }
.period-total .summary-sub { font-size: 12.5px; color: var(--muted); }
.period-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.period-table { width: 100%; }
.period-table tbody tr { border-bottom: 1px solid var(--border); }
.period-table tbody tr:hover { background: var(--row-hover); }
.period-row-off { color: var(--muted); }
.period-row-off .desc-text, .period-row-off td.num { opacity: .65; }
.period-row-off .num { text-decoration: line-through; }
