:root {
  --navy-950: #071a2d;
  --navy-900: #0a2239;
  --navy-800: #153653;
  --gold: #d8ad4c;
  --gold-hover: #edc869;
  --paper: #f3f6f9;
  --surface: #ffffff;
  --line: #d9e2eb;
  --ink: #10243a;
  --muted: #627386;
  --success: #20734f;
  --danger: #b8443d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
a,
select,
input {
  border-radius: 7px;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(216, 173, 76, 0.48);
  outline-offset: 2px;
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    var(--navy-950);
  background-size: 42px 42px;
}

.auth-card {
  width: min(100%, 520px);
  padding: clamp(24px, 4vw, 38px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: white;
  background: rgba(10, 34, 57, 0.94);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
}

.back-link {
  display: inline-block;
  margin-bottom: 26px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.9rem;
  font-weight: 750;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 26px;
}

.auth-brand img,
.brand img {
  flex: none;
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.auth-card h1,
.page-heading h1 {
  margin: 0;
  letter-spacing: 0;
}

.auth-card h1 {
  font-size: clamp(1.85rem, 5vw, 2.45rem);
}

.auth-fields {
  display: grid;
  gap: 16px;
}

.auth-fields label,
.search-field {
  display: grid;
  gap: 7px;
  font-size: 0.86rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: white;
}

.primary-button,
.ghost-button,
.save-button,
.campus-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid transparent;
  font-weight: 850;
}

.primary-button,
.save-button {
  color: var(--navy-950);
  background: var(--gold);
}

.primary-button:hover,
.save-button:hover {
  background: var(--gold-hover);
}

.auth-card .primary-button {
  width: 100%;
  margin-top: 20px;
}

.ghost-button,
.campus-link {
  border-color: var(--line);
  color: var(--ink);
  background: white;
}

.status,
.panel-status,
.row-status {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.status.error,
.panel-status.error,
.row-status.error {
  color: var(--danger);
}

.status.ok,
.panel-status.ok,
.row-status.ok {
  color: var(--success);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 10px clamp(18px, 4vw, 56px);
  color: white;
  background: rgba(7, 26, 45, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.brand span,
.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.05rem;
  letter-spacing: 1.5px;
}

.brand small {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.66);
  font-size: 0.7rem;
  font-weight: 750;
}

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

.session-email {
  color: rgba(255, 255, 255, 0.74);
  font-size: 0.86rem;
  font-weight: 750;
}

.topbar .ghost-button {
  border-color: rgba(255, 255, 255, 0.2);
  color: white;
  background: rgba(255, 255, 255, 0.07);
}

.admin-main {
  width: min(calc(100% - 36px), 1500px);
  margin: 0 auto;
  padding: clamp(28px, 4vw, 54px) 0 70px;
}

.page-heading,
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.page-heading {
  margin-bottom: 28px;
}

.page-heading h1 {
  font-size: clamp(2rem, 4vw, 3.25rem);
}

.toolbar {
  padding: 18px 20px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.search-field {
  width: min(100%, 430px);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-count {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  white-space: nowrap;
}

.users-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.table-heading,
.user-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(190px, 0.9fr) minmax(160px, 0.75fr) minmax(130px, 0.55fr);
  gap: 18px;
  align-items: center;
}

.table-heading {
  min-height: 48px;
  padding: 10px 18px;
  color: var(--muted);
  background: #eaf0f5;
  font-size: 0.76rem;
  text-transform: uppercase;
}

.user-row {
  min-height: 98px;
  padding: 16px 18px;
  border-top: 1px solid var(--line);
}

.user-row:first-child {
  border-top: 0;
}

.user-identity {
  min-width: 0;
}

.user-email {
  display: block;
  overflow: hidden;
  font-size: 0.98rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-meta {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.admin-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 7px;
  border-radius: 4px;
  color: #6d531c;
  background: #f8e8bd;
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.field-label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.field-label > span {
  display: none;
}

.save-cell {
  display: grid;
  gap: 4px;
  justify-items: stretch;
}

.save-button {
  width: 100%;
}

.row-status {
  min-height: 1em;
  margin: 0;
  text-align: center;
}

.empty-state {
  margin: 0;
  padding: 44px 20px;
  color: var(--muted);
  text-align: center;
}

.panel-status {
  margin: 0;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

@media (max-width: 860px) {
  .session-email {
    display: none;
  }

  .table-heading {
    display: none;
  }

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

  .user-identity,
  .save-cell {
    grid-column: 1 / -1;
  }

  .field-label > span {
    display: block;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding-inline: 12px;
  }

  .brand small {
    display: none;
  }

  .brand img {
    width: 40px;
    height: 40px;
  }

  .account-actions .ghost-button {
    padding-inline: 11px;
  }

  .admin-main {
    width: min(calc(100% - 24px), 1500px);
  }

  .page-heading,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .campus-link,
  .search-field {
    width: 100%;
  }

  .toolbar-actions {
    justify-content: space-between;
  }

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

  .user-identity,
  .save-cell {
    grid-column: auto;
  }
}

/* Botón de facturas por usuario */
.facturas-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border: 1px solid #cdd7e0;
  border-radius: 7px;
  background: #fff;
  color: #0a2239;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}
.facturas-button:hover { background: #f0f4f8; border-color: #a9bccd; }
.facturas-button svg { width: 16px; height: 16px; }

/* Modal de facturas */
.facturas-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 26, 45, 0.55);
}
.facturas-modal[hidden] { display: none; }
.facturas-modal-card {
  width: min(520px, 100%);
  max-height: 80vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
}
.facturas-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.facturas-modal-head h2 { margin: 0; font-size: 1.1rem; color: #0a2239; }
.facturas-modal-list { display: flex; flex-direction: column; gap: 10px; }
.factura-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid #e2e9f0;
  border-radius: 9px;
  background: #fbfcfe;
}
.factura-row strong { display: block; color: #10243a; font-size: 0.95rem; }
.factura-row small { color: #65788a; font-size: 0.82rem; }
.factura-link {
  flex: none;
  font-weight: 700;
  font-size: 0.85rem;
  color: #071a2d;
  background: #f0c766;
  padding: 8px 14px;
  border-radius: 7px;
  text-decoration: none;
}
.factura-link:hover { background: #ffda7b; }
