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

:root {
  --primary: #1e6091;
  --primary-dark: #154766;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e1e5eb;
  --text: #2c3e50;
  --muted: #7f8c9b;
  --success: #27ae60;
  --warning: #f39c12;
  --danger: #c0392b;
}

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

header {
  background: var(--primary);
  color: white;
  padding: 1rem 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

header h1 {
  font-size: 1.5rem;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.user-box.hidden { display: none; }
.user-box .rol-tag {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 10px;
  background: rgba(255,255,255,0.25);
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 600;
  margin-left: 0.4rem;
}

nav { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.nav-btn {
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.nav-btn:hover { background: rgba(255,255,255,0.25); }
.nav-btn.active { background: white; color: var(--primary); font-weight: 600; }

main {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
}

h2 { font-size: 1.4rem; margin-bottom: 1rem; color: var(--primary-dark); }
h3 { font-size: 1.1rem; margin-bottom: 0.75rem; color: var(--text); }

.card {
  background: var(--card);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat {
  background: var(--card);
  border-radius: 10px;
  padding: 1.1rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
}
.stat .label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat .value { font-size: 1.7rem; font-weight: 700; margin-top: 0.25rem; color: var(--primary-dark); }
.stat.success { border-left-color: var(--success); }
.stat.success .value { color: var(--success); }
.stat.warning { border-left-color: var(--warning); }
.stat.warning .value { color: var(--warning); }
.stat.danger { border-left-color: var(--danger); }
.stat.danger .value { color: var(--danger); }

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
}
th, td { padding: 0.7rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { background: #f8fafc; font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.5px; }
tr:hover td { background: #f8fafc; }

.btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s;
  text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #95a5a6; }
.btn.secondary:hover { background: #7f8c8d; }
.btn.success { background: var(--success); }
.btn.success:hover { background: #1e8449; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #922b21; }
.btn.warning { background: var(--warning); }
.btn.warning:hover { background: #d68910; }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; font-weight: 500; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none; border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge.activo { background: #d5f5e3; color: #1e8449; }
.badge.liquidado { background: #d6eaf8; color: #1e6091; }
.badge.cancelado { background: #f5d5d5; color: #922b21; }
.badge.pago { background: #d5f5e3; color: #1e8449; }
.badge.pago-tardio { background: #fdebd0; color: #b9770e; }
.badge.sin-pago { background: #f5d5d5; color: #922b21; }
.badge.pendiente { background: #fdebd0; color: #b9770e; }
.badge.pagada { background: #d5f5e3; color: #1e8449; }
.badge.admin { background: #d6eaf8; color: #1e6091; }
.badge.capturador { background: #d5f5e3; color: #1e8449; }
.badge.observador { background: #ecf0f1; color: #555; }
.badge.empleado { background: #fdebd0; color: #b9770e; }

tfoot td { background: #f8fafc; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal.hidden { display: none; }
.modal-content { background: white; border-radius: 10px; padding: 1.75rem; max-width: 900px; width: 95%; max-height: 90vh; overflow-y: auto; position: relative; }
#modalBody { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.modal-close { position: absolute; top: 0.6rem; right: 0.85rem; background: none; border: none; font-size: 1.7rem; cursor: pointer; color: var(--muted); }

.toast { position: fixed; bottom: 2rem; right: 2rem; background: var(--text); color: white; padding: 0.85rem 1.4rem; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); z-index: 2000; font-size: 0.9rem; }
.toast.hidden { display: none; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.empty { text-align: center; padding: 2rem; color: var(--muted); }

/* Login */
.login-page {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: white;
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 380px;
}
.login-card h2 { text-align: center; margin-bottom: 0.5rem; }
.login-card p.muted { text-align: center; color: var(--muted); margin-bottom: 1.5rem; font-size: 0.9rem; }
.login-card button.btn { width: 100%; padding: 0.75rem; font-size: 1rem; }

.alert { padding: 0.85rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert.warning { background: #fdebd0; color: #b9770e; border-left: 4px solid var(--warning); }
.alert.danger { background: #f5d5d5; color: #922b21; border-left: 4px solid var(--danger); }
.alert.info { background: #d6eaf8; color: #1e6091; border-left: 4px solid var(--primary); }

.text-right { text-align: right; }
.text-muted { color: var(--muted); font-size: 0.85rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* ========= RESPONSIVE / MOBILE ========= */

/* Tablas con scroll horizontal */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
}

@media (max-width: 768px) {
  header { padding: 0.75rem 1rem; position: sticky; top: 0; z-index: 500; }
  header h1 { font-size: 1.2rem; }

  .header-top {
    gap: 0.5rem;
  }

  .user-box {
    font-size: 0.8rem;
    gap: 0.4rem;
    flex-wrap: wrap;
  }
  .user-box .btn.small {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
  }

  nav {
    gap: 0.35rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-bottom: 0.25rem;
  }
  .nav-btn {
    padding: 0.45rem 0.8rem;
    font-size: 0.8rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  main {
    padding: 0 0.75rem;
    margin: 1rem auto;
  }

  h2 { font-size: 1.2rem; }
  h3 { font-size: 1rem; }

  .grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    margin-bottom: 1rem;
  }

  .stat {
    padding: 0.75rem;
  }
  .stat .value {
    font-size: 1.3rem;
  }
  .stat .label {
    font-size: 0.7rem;
  }

  .card {
    padding: 0.85rem;
    border-radius: 8px;
  }

  /* Tablas scroll en movil */
  table {
    min-width: 500px;
  }
  th, td {
    padding: 0.5rem 0.6rem;
    font-size: 0.8rem;
    white-space: nowrap;
  }
  th {
    font-size: 0.65rem;
  }

  .form-row { grid-template-columns: 1fr; }

  .toolbar {
    gap: 0.5rem;
  }

  .btn {
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
  }
  .btn.small {
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
  }

  /* Modal fullscreen en movil */
  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    padding: 1rem;
  }
  .modal {
    align-items: stretch;
  }

  .login-card {
    padding: 1.5rem;
    margin: 0 0.5rem;
  }

  .toast {
    bottom: 1rem;
    right: 1rem;
    left: 1rem;
    text-align: center;
    font-size: 0.85rem;
  }

  .alert {
    font-size: 0.82rem;
    padding: 0.7rem 0.85rem;
  }
}

@media (max-width: 400px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .stat .value {
    font-size: 1.1rem;
  }
  header h1 { font-size: 1.05rem; }
  .user-box #userInfo { display: block; width: 100%; }
}
