:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --border: #e5e7eb;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.container { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.muted { color: var(--muted); font-size: 0.9em; }

/* ---------- barra superior ---------- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 0.6rem 1rem; flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; }
.topbar nav { display: flex; gap: 0.75rem; flex: 1; }
.topbar nav a { color: var(--primary); text-decoration: none; font-weight: 500; }
.logout-form { display: flex; align-items: center; gap: 0.5rem; margin: 0; }
.who { font-weight: 600; }

/* ---------- campana de notificaciones ---------- */
.bell {
  position: relative; text-decoration: none; font-size: 1.25rem;
  padding: 0.2rem 0.35rem; border-radius: 50%; line-height: 1;
}
.bell:hover { background: #f3f4f6; }
.bell-dot {
  position: absolute; top: 0; right: 0; width: 11px; height: 11px;
  background: var(--danger); border: 2px solid var(--card); border-radius: 50%;
  animation: bell-pulse 2s infinite;
}
@keyframes bell-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.25); }
}

/* ---------- botones ---------- */
.btn {
  display: inline-block; border: none; cursor: pointer;
  padding: 0.55rem 1rem; border-radius: var(--radius);
  font-size: 0.95rem; text-decoration: none; text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-link { background: none; color: var(--primary); }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.btn-block { width: 100%; }
.inline { display: inline; margin: 0; }

/* ---------- login ---------- */
.login-box {
  max-width: 380px; margin: 8vh auto; background: var(--card);
  padding: 2rem; border-radius: var(--radius); box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  text-align: center;
}
.login-box h1 { margin-top: 0; }
.login-box form { text-align: left; }

/* ---------- formularios ---------- */
label { display: block; margin: 0.8rem 0; font-weight: 500; }
input[type=text], input[type=password], input[type=date],
input[type=number], select {
  width: 100%; padding: 0.55rem; margin-top: 0.25rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 1rem; background: #fff;
}
input[type=file] { margin-top: 0.25rem; width: 100%; }
label.checkbox { font-weight: 400; }
label.checkbox input { width: auto; margin-right: 0.4rem; }
.expense-form {
  max-width: 520px; background: var(--card); padding: 1.5rem;
  border-radius: var(--radius); border: 1px solid var(--border);
}
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.2rem; }
small { display: block; margin-top: 0.2rem; }

/* ---------- alertas y badges ---------- */
.alert { padding: 0.8rem 1rem; border-radius: var(--radius); margin: 1rem 0; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert ul { margin: 0; padding-left: 1.2rem; }
.badge {
  padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
}
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-revisado { background: #dbeafe; color: #1e40af; }
.badge-liquidado { background: #d1fae5; color: #065f46; }

/* ---------- balance ---------- */
.balance-card {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius);
  padding: 0.9rem 1.2rem; margin: 1rem 0;
}
.balance-even { background: #ecfdf5; border-color: #a7f3d0; }

/* ---------- dashboard KPIs ---------- */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.9rem; margin: 1rem 0 1.5rem;
}
.kpi-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  display: flex; flex-direction: column; gap: 0.25rem;
}
.kpi-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.kpi-label { color: var(--muted); font-size: 0.88rem; }
.kpi-warn { border-color: #fcd34d; background: #fffbeb; }
.kpi-warn .kpi-value { color: #b45309; }
.kpi-balance { border-color: #bfdbfe; background: #eff6ff; }
.kpi-balance .kpi-value { color: var(--primary-dark); }
.kpi-balance form { margin-top: 0.5rem; }
.btn-settle { background: #0d9488; color: #fff; }
.btn-settle:hover { background: #0f766e; }

/* ---------- banner activar notificaciones ---------- */
.notif-banner {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.8rem; flex-wrap: wrap;
  background: #eef2ff; border: 1px solid #c7d2fe; border-radius: var(--radius);
  padding: 0.8rem 1.1rem; margin: 1rem 0 0.2rem;
}
.notif-actions { display: flex; gap: 0.5rem; }

/* ---------- banner ajuste pendiente ---------- */
.settle-banner {
  background: #fefce8; border: 2px solid #facc15; border-radius: var(--radius);
  padding: 1rem 1.2rem; margin: 1rem 0;
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap;
}
.settle-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

/* ---------- botón ticket ---------- */
.btn-ticket {
  background: #ecfeff; color: #0e7490; border: 1px solid #a5f3fc;
  text-decoration: none;
}
.btn-ticket:hover { background: #cffafe; }

/* ---------- badges de ajustes ---------- */
.badge-aj-propuesto { background: #fef3c7; color: #92400e; }
.badge-aj-confirmado { background: #d1fae5; color: #065f46; }
.badge-aj-cancelado { background: #f3f4f6; color: #6b7280; }
.row-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
#ajuste { scroll-margin-top: 5rem; }

/* ---------- visor de adjuntos ---------- */
.viewer-bar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.7rem 1rem; margin: 1rem 0;
}
.viewer-info { flex: 1; display: flex; flex-direction: column; min-width: 140px; }
.viewer-body { text-align: center; }
.viewer-body img {
  max-width: 100%; height: auto; border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: 0 2px 12px rgba(0,0,0,0.12);
}
.viewer-body iframe {
  width: 100%; height: 75vh; border: 1px solid var(--border);
  border-radius: var(--radius); background: #fff;
}

/* ---------- filtros ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.9rem 1rem; margin-bottom: 1rem;
}
.filters label { margin: 0; flex: 1 1 140px; font-size: 0.9rem; }
.filters .btn { flex: 0 0 auto; }

/* ---------- cabecera y tabla ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.table-wrap { overflow-x: auto; }
table {
  width: 100%; border-collapse: collapse; background: var(--card);
  border-radius: var(--radius); overflow: hidden;
}
th, td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); text-align: left; }
th { background: #f9fafb; font-size: 0.85rem; text-transform: uppercase; color: var(--muted); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: 0.6rem; }
th.th-actions { text-align: right; }
td.empty { text-align: center; color: var(--muted); padding: 2rem; }
section { margin-top: 2rem; }

/* ---------- grupos de periodo (resumen mensual/semanal) ---------- */
.pgroup {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 0.9rem; overflow: hidden;
}
.pgroup-title {
  background: #f9fafb; padding: 0.55rem 1rem; font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.pgroup-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.55rem 1rem; border-bottom: 1px solid var(--border);
}
.pgroup-row:last-child { border-bottom: none; }
.pname { flex: 1; font-weight: 500; }
.pn { color: var(--muted); font-size: 0.88em; }
.ptotal { font-weight: 600; min-width: 90px; text-align: right; }
.pgroup-sum { background: #f9fafb; }
.pgroup-sum .ptotal { color: var(--primary-dark); }

/* ---------- móvil: tabla en tarjetas ---------- */
@media (max-width: 720px) {
  table thead { display: none; }
  table { background: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr {
    position: relative;
    border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 0.8rem; background: var(--card);
    padding: 0.5rem 0 0.6rem; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  }
  td { border: none; padding: 0.3rem 0.9rem; text-align: left !important; }
  td[data-l]::before { content: attr(data-l) ": "; font-weight: 600; color: var(--muted); }
  /* acciones flotantes en la esquina superior derecha, lejos del ticket */
  td.actions {
    position: absolute; top: 0.45rem; right: 0.6rem;
    width: auto; padding: 0; margin: 0;
    display: flex; gap: 0.6rem;
  }
  td.actions .btn {
    margin-left: 0; padding: 0.35rem 0.6rem; font-size: 0.85rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  }
  /* hueco para que la primera línea no quede debajo de los botones */
  tr td:first-child { padding-right: 9.5rem; }
  td.ticket-cell { padding-top: 0.45rem; }
  td.ticket-cell .btn-ticket { display: inline-block; padding: 0.5rem 0.9rem; }

  /* KPIs: cuadrícula 2x2 compacta */
  .kpis { grid-template-columns: 1fr 1fr; gap: 0.6rem; margin: 0.8rem 0 1.2rem; }
  .kpi-card { padding: 0.75rem 0.85rem; border-radius: 12px; }
  .kpi-value { font-size: 1.25rem; }
  .kpi-label { font-size: 0.78rem; line-height: 1.25; }
  .kpi-balance form { margin-top: 0.4rem; }
  .kpi-balance .btn { width: 100%; }

  .page-head h1 { font-size: 1.4rem; margin: 0.4rem 0; }
  .settle-banner { flex-direction: column; align-items: stretch; }
  .topbar { gap: 0.5rem; }
}
