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

:root {
  --bg:        #f4f6fa;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --ink:       #1a202c;
  --ink-soft:  #718096;
  --accent:    #3b82f6;
  --accent-h:  #2563eb;
  --green:     #10b981;
  --red:       #ef4444;
  --orange:    #f59e0b;
  --radius:    10px;
  --shadow:    0 1px 4px rgba(0,0,0,.08);
  --sidebar-w: 220px;
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: .95rem; }

/* ── Pages ── */
.page { min-height: 100vh; }
.page.hidden { display: none !important; }

/* ── Login ── */
.login-box {
  max-width: 380px; margin: 80px auto; background: var(--surface);
  border-radius: 16px; padding: 40px; box-shadow: 0 4px 24px rgba(0,0,0,.1);
}
.login-box h1 { font-size: 1.8rem; margin-bottom: 4px; }
.login-sub { color: var(--ink-soft); margin-bottom: 28px; font-size: .9rem; }

/* ── App layout ── */
#page-app { display: flex; }

.sidebar {
  width: var(--sidebar-w); background: var(--ink); color: #e2e8f0;
  min-height: 100vh; display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; z-index: 100;
}
.sidebar-logo { padding: 24px 20px 16px; font-size: 1.1rem; font-weight: 700; color: #fff; }
.nav-item {
  display: block; padding: 12px 20px; cursor: pointer; transition: background .15s;
  color: #cbd5e0; text-decoration: none; font-size: .9rem;
}
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.1); color: #fff; }
.nav-logout { color: #fc8181; }
.sidebar-spacer { flex: 1; }

.content { margin-left: var(--sidebar-w); padding: 32px; flex: 1; max-width: calc(100vw - var(--sidebar-w)); }

/* ── Sections ── */
.section { display: none; }
.section.active { display: block; }
.section-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-head .section-title { margin-bottom: 0; }
.subsection-title { font-size: 1rem; font-weight: 600; margin: 28px 0 14px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; font-size: .8rem; }

/* ── Balance ── */
.balance-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; margin-bottom: 8px; }
.balance-card {
  background: var(--surface); border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow); border-left: 4px solid transparent;
}
.card-pendiente { border-color: var(--accent); }
.card-cobrado   { border-color: var(--green); }
.card-vencido   { border-color: var(--red); }
.balance-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin-bottom: 8px; }
.balance-monto { font-size: 1.6rem; font-weight: 700; }
.card-pendiente .balance-monto { color: var(--accent); }
.card-cobrado   .balance-monto { color: var(--green); }
.card-vencido   .balance-monto { color: var(--red); }
.balance-cant { font-size: .82rem; color: var(--ink-soft); margin-top: 4px; }

/* ── Table ── */
.tabla-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { background: var(--bg); padding: 12px 16px; text-align: left; font-weight: 600; color: var(--ink-soft); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); }
td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.td-actions { display: flex; gap: 8px; }

/* ── Status badges ── */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.badge-pendiente { background: #dbeafe; color: #1d4ed8; }
.badge-cobrado   { background: #d1fae5; color: #065f46; }
.badge-vencido   { background: #fee2e2; color: #991b1b; }

/* ── Filters ── */
.filters { display: flex; gap: 12px; margin-bottom: 16px; }
.filters select, .filters input { flex: 1; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: 8px; font-size: .88rem;
  font-weight: 600; cursor: pointer; border: none; transition: background .15s, transform .1s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-ghost { background: var(--bg); color: var(--ink); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-danger { background: #fee2e2; color: var(--red); }
.btn-danger:hover { background: #fecaca; }
.btn-full { width: 100%; justify-content: center; }
.btn-green { background: #d1fae5; color: #065f46; }
.btn-green:hover { background: #a7f3d0; }

/* ── Fields ── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: .9rem; background: var(--surface);
  color: var(--ink); outline: none; transition: border-color .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=file] { border: 1px dashed var(--border); padding: 8px; cursor: pointer; }
textarea { resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Modal ── */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface); border-radius: 14px; width: 100%;
  max-width: 520px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,.2); padding: 28px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.modal-head h3 { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--ink-soft); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ── Hint / err ── */
.hint { font-size: .8rem; color: var(--ink-soft); margin-top: 4px; }
.err  { color: var(--red); font-size: .85rem; margin-top: 10px; }
.hidden { display: none !important; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 28px; right: 28px; z-index: 9999;
  background: var(--ink); color: #fff; padding: 13px 22px;
  border-radius: 10px; font-size: .88rem; box-shadow: 0 4px 16px rgba(0,0,0,.2);
  animation: slideUp .25s ease;
}
.toast.toast-ok  { background: var(--green); }
.toast.toast-err { background: var(--red); }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Factura link ── */
.factura-link { font-size: .8rem; color: var(--accent); text-decoration: none; }
.factura-link:hover { text-decoration: underline; }

/* ── Empty state ── */
.empty-state { padding: 48px; text-align: center; color: var(--ink-soft); }
.empty-state p { font-size: 1rem; }

@media (max-width: 768px) {
  .balance-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar { width: 60px; }
  .sidebar-logo, .nav-item span { display: none; }
  .content { margin-left: 60px; padding: 16px; }
}
