:root {
  --bg: #0b0f17;
  --surface: #131926;
  --surface-2: #1a2234;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.15);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.14);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2f9;
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --green: #059669;
  --green-soft: rgba(5, 150, 105, 0.12);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.12);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.1);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100dvh;
  padding-bottom: 90px;
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* PIN Overlay */
.pin-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 500;
}

.pin-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 28px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}

.pin-card input {
  text-align: center;
  font-size: 1.3rem;
  letter-spacing: 0.25em;
}

.pin-error {
  color: var(--red);
  font-size: 0.85rem;
  font-weight: 600;
}

.app-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sync-pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
}

.sync-pill.syncing {
  background: var(--amber-soft);
  color: var(--amber);
}

.sync-pill.error {
  background: var(--red-soft);
  color: var(--red);
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  font-weight: 800;
  font-size: 1.35rem;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
}

.brand h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.3rem;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

/* Summary */
.summary-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.hero-card {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.08)), var(--surface);
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

.hero-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.hero-amount {
  font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 2px 0;
}

.hero-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-value {
  font-size: 1.25rem;
  font-weight: 700;
}

.kpi-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.kpi-deben .kpi-value { color: var(--accent); }
.kpi-pedir .kpi-value { color: var(--amber); }
.kpi-paid .kpi-value { color: var(--green); }

.subtotals-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.subtotal-pill {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.86rem;
  transition: border-color 0.15s, transform 0.12s;
}

.subtotal-pill:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.subtotal-pill .pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.subtotal-pill.is-pedir .pill-dot {
  background: var(--amber);
}

.subtotal-pill strong {
  font-weight: 700;
}

/* Controls & Tabs */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.tabs {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.badge {
  font-size: 0.74rem;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.tab:not(.active) .badge {
  background: var(--surface-2);
  color: var(--text-muted);
}

.search-wrap {
  display: flex;
  gap: 8px;
  flex: 1 1 260px;
  justify-content: flex-end;
}

input[type="search"],
input[type="text"],
input[type="password"],
input[type="date"],
select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.94rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus {
  border-color: var(--accent);
}

#search-input {
  flex: 1 1 180px;
  max-width: 280px;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger-ghost {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
}

.btn-danger-ghost {
  background: var(--red-soft);
  color: var(--red);
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.84rem;
}

.full-width {
  width: 100%;
}

/* Views */
.view { display: none; }
.view.active { display: block; }

.sections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  align-items: start;
}

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.section-card-header {
  padding: 14px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.section-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title-row h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.tag {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tag-deben {
  background: var(--accent-soft);
  color: var(--accent);
}

.tag-pedir {
  background: var(--amber-soft);
  color: var(--amber);
}

.section-subtotal {
  font-size: 1.15rem;
  font-weight: 800;
}

.section-actions {
  display: flex;
  gap: 4px;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.mini-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.mini-btn.accent {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

/* Entry rows */
.entry-list {
  list-style: none;
}

.entry-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: background 0.12s;
}

.entry-item:last-child {
  border-bottom: none;
}

.entry-main {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.check-btn {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  border-radius: 7px;
  border: 2px solid var(--border-strong);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  margin-top: 2px;
  color: transparent;
  transition: all 0.15s;
}

.check-btn:hover {
  border-color: var(--green);
}

.check-btn.checked {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.entry-info {
  flex: 1;
  min-width: 0;
}

.entry-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.entry-amount {
  font-weight: 700;
  font-size: 1.02rem;
}

.entry-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  word-break: break-word;
}

.entry-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.abono-bar-wrap {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.abono-bar {
  height: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.abono-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 999px;
}

.entry-proof-thumbs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.proof-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border-strong);
  cursor: pointer;
}

.entry-actions-row {
  display: flex;
  gap: 6px;
  padding-left: 34px;
  flex-wrap: wrap;
}

.empty-section {
  padding: 20px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Proofs Gallery */
.proofs-header, .paid-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.proofs-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.muted {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.proofs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.proof-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.proof-card img {
  width: 100%;
  height: 165px;
  object-fit: cover;
  cursor: pointer;
  background: var(--surface-2);
}

.proof-card-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.proof-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.proof-card-caption {
  font-size: 0.88rem;
  font-weight: 600;
}

.proof-card-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* Paid List */
.paid-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* FAB */
.fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 10px 25px rgba(99, 102, 241, 0.45);
  cursor: pointer;
  display: none;
  place-items: center;
  z-index: 50;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-sm {
  max-width: 400px;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.86rem;
  font-weight: 600;
}

.quick-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.upload-zone {
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.preview-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.preview-item {
  position: relative;
  width: 64px;
  height: 64px;
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
}

.preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--red);
  color: #fff;
  font-size: 0.8rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.abono-info {
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
}

.export-options {
  gap: 10px;
}

.file-btn {
  text-align: center;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 200;
  gap: 12px;
}

.lightbox img {
  max-width: 95vw;
  max-height: 80vh;
  border-radius: 10px;
  object-fit: contain;
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.8rem;
  cursor: pointer;
}

.lightbox-caption {
  color: #e2e8f0;
  font-size: 0.95rem;
  text-align: center;
  max-width: 600px;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: fadeUp 0.2s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 680px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .hero-add-btn {
    display: none;
  }
  .fab {
    display: grid;
  }
  .sections-grid {
    grid-template-columns: 1fr;
  }
  .search-wrap {
    width: 100%;
    justify-content: stretch;
  }
  #search-input {
    max-width: none;
  }
}
