/* === Tokens === */
:root {
  --bg: #f6f7fb;
  --bg-card: #ffffff;
  --border: #e4e7ee;
  --ink: #1e2436;
  --ink-soft: #57607a;
  --ink-faint: #8a92a8;
  --primary: #4f46e5;
  --primary-soft: #eef0ff;
  --primary-deep: #3a32b8;
  --accent: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 22, 36, 0.04), 0 4px 12px rgba(15, 22, 36, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }
input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* evita auto-zoom iOS */
}

/* === Layout app === */
#layout-root {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.brand-mark {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 18px;
}
.brand-text .brand-name { font-weight: 600; font-size: 15px; }
.brand-text .brand-sub { color: var(--ink-faint); font-size: 12px; }
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--ink-soft);
  font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--bg); color: var(--ink); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-weight: 600;
}
.nav-icon { font-size: 18px; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 14px; }
.user-card {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.user-avatar {
  width: 34px; height: 34px;
  background: var(--primary-soft);
  color: var(--primary-deep);
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 600;
}
.user-name { font-size: 14px; font-weight: 500; }
.user-role { font-size: 12px; color: var(--ink-faint); }
.btn-logout {
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--ink-soft);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.btn-logout:hover { background: var(--bg); color: var(--ink); }

.content { padding: 32px 40px; max-width: 1200px; }
.page-title { font-size: 22px; font-weight: 600; margin: 0 0 6px; }
.page-sub { color: var(--ink-faint); margin: 0 0 24px; }

/* === Cards === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 13px; color: var(--ink-faint); margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 28px; font-weight: 600; margin: 0; }

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

/* === Botones === */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn:hover { background: var(--primary-deep); }
.btn-secondary {
  background: var(--bg-card);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); }

/* === Login page === */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #f6f7fb 0%, #eef0ff 100%);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  width: 380px;
  max-width: 92vw;
  box-shadow: 0 4px 24px rgba(15, 22, 36, 0.08);
}
.login-brand {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 24px;
}
.login-brand .brand-mark { width: 44px; height: 44px; font-size: 22px; }
.login-title { font-size: 18px; font-weight: 600; }
.login-sub { color: var(--ink-faint); font-size: 13px; }
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.form-group select, .form-group input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border .15s, box-shadow .15s;
  background: #fff;
}
.form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.login-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}
.login-btn {
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  font-size: 15px;
}

/* === Tablas === */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.tbl thead th {
  background: var(--bg);
  color: var(--ink-soft);
  font-weight: 600;
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.tbl tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.tbl tbody tr:hover {
  background: rgba(79, 70, 229, .04);
}
.tbl .r { text-align: right; }
.tbl code {
  font-family: ui-monospace, monospace;
  font-size: 13px;
  color: var(--ink-soft);
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  opacity: .55;
  transition: opacity .15s;
}
.btn-icon:hover { opacity: 1; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-borrador  { background: #e5e7eb; color: #4b5563; }
.badge-emitida   { background: #dbeafe; color: #1d4ed8; }
.badge-cobrada   { background: #d1fae5; color: #047857; }
.badge-impagada  { background: #fee2e2; color: #b91c1c; }
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-pagada    { background: #d1fae5; color: #047857; }

/* === Form controls (filtros header) === */
.form-control {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
}

.form-section {
  font-size: 12px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 18px 0 8px;
  font-weight: 600;
}

/* === Resumen importes === */
.resumen {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--ink-soft);
}
.resumen b { color: var(--ink); font-weight: 600; }

/* === Modal === */
.modal-shell {
  position: fixed; inset: 0;
  background: rgba(15, 22, 36, 0.55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn .15s ease;
}
.modal-card {
  background: #fff;
  border-radius: 14px;
  width: 640px;
  max-width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(15, 22, 36, .18);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 17px; margin: 0; }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* === Responsive === */
@media (max-width: 720px) {
  #layout-root {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    padding: 12px;
    overflow-x: auto;
  }
  .sidebar-brand { display: none; }
  .sidebar-nav { flex-direction: row; flex: 1; }
  .nav-item { padding: 8px 10px; }
  .nav-label { display: none; }
  .sidebar-foot { display: none; }
  .content { padding: 20px 16px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
