/* ============================================================
   admin-utilizadores.css - Backoffice Gestão de Utilizadores
   ============================================================ */

/* ── Header: stats + controlos lado a lado ──────────────────── */
.au-header-area {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}

.au-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.au-controls .au-search-wrap {
  width: 100%;
}

.au-controls .au-search {
  width: 100%;
  box-sizing: border-box;
}

/* ── Stats row ──────────────────────────────────────────────── */
.au-stats {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.au-stat-distribuicao {
  min-width: 0;
}

.au-stat-card {
  background: var(--color-background-primary);
  border: 0.5px solid var(--color-border-secondary);
  border-radius: var(--border-radius-lg);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}

.au-stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-tertiary);
  margin-bottom: 2px;
}

.au-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1;
}

.au-stat-value.red  { color: var(--bygga-red); }
.au-stat-value.navy { color: var(--bygga-navy); }


.au-search {
  height: 32px;
  padding: 0 10px 0 32px;
  border: 0.5px solid var(--color-border-secondary);
  border-radius: var(--border-radius-md);
  background: var(--color-background-primary);
  font-size: 12px;
  color: var(--color-text-primary);
  outline: none;
  width: 200px;
  position: relative;
}

.au-search:focus { border-color: var(--bygga-red); }

.au-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.au-search-wrap i {
  position: absolute;
  left: 9px;
  font-size: 14px;
  color: var(--color-text-tertiary);
  pointer-events: none;
}

/* ── Layout: content não scrolla - só a tabela scrolla ──────── */
.au-content {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.au-content .au-table-wrap {
  flex: 1;
  min-height: 0; /* necessário para flex + overflow funcionar */
  overflow-y: auto;
  overflow-x: auto; /* a matriz de acessos tem mais colunas do que cabem no ecrã */
}

/* ── Users table ────────────────────────────────────────────── */
.au-table-wrap {
  background: var(--color-background-primary);
  border: 0.5px solid var(--color-border-secondary);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
}

.au-table {
  width: 100%;
  border-collapse: collapse;
}

.au-table th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.au-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-tertiary);
  padding: 7px 12px;
  background: var(--color-background-secondary);
  border-bottom: 0.5px solid var(--color-border-secondary);
  text-align: left;
  white-space: nowrap;
}

.au-table td {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--color-text-primary);
  border-bottom: 0.5px solid var(--color-border-tertiary);
  vertical-align: middle;
}

.au-table tr:last-child td { border-bottom: none; }

.au-table tbody tr:hover { background: var(--color-background-secondary); }

.au-user-nome {
  font-weight: 600;
  color: var(--color-text-primary);
}

.au-user-email {
  font-size: 11px;
  color: var(--color-text-tertiary);
  margin-top: 1px;
}

.au-user-codigo {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 2px;
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  vertical-align: middle;
}

/* ── Role badge ─────────────────────────────────────────────── */
.au-role-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 2px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.au-role-badge.admin-bygga   { background: var(--bygga-navy); color: #fff; }
.au-role-badge.projetista    { background: var(--color-background-secondary); color: var(--color-text-secondary); border: 0.5px solid var(--color-border-secondary); }

/* ── Status badge ───────────────────────────────────────────── */
.au-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
}

.au-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.au-status.ativo    .au-status-dot { background: #1D9E75; }
.au-status.inativo  .au-status-dot { background: var(--color-text-tertiary); }
.au-status.pendente .au-status-dot { background: #BA7517; }
.au-status.ativo    { color: #1D9E75; }
.au-status.inativo  { color: var(--color-text-tertiary); }
.au-status.pendente { color: #BA7517; }

/* ── Permissions pills ──────────────────────────────────────── */
.au-perms {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 260px;
}

.au-perm-pill {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 600;
  background: var(--color-background-secondary);
  color: var(--color-text-secondary);
  border: 0.5px solid var(--color-border-secondary);
  white-space: nowrap;
}

.au-perms-default {
  font-size: 11px;
  color: var(--color-text-tertiary);
  font-style: italic;
}

/* ── Action buttons ─────────────────────────────────────────── */
.au-actions {
  display: flex;
  gap: 5px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
}

.au-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--border-radius-md);
  border: 0.5px solid var(--color-border-secondary);
  background: var(--color-background-secondary);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 14px;
}

.au-btn-icon:hover { background: var(--color-background-tertiary); color: var(--color-text-primary); }
.au-btn-icon.danger:hover { background: var(--bygga-red-light); color: var(--bygga-red); border-color: var(--bygga-red); }

/* ── Modal ──────────────────────────────────────────────────── */
.au-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.au-modal-overlay.open { display: flex; }

.au-modal {
  background: var(--color-background-primary);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--color-border-primary);
  width: 560px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.au-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 0.5px solid var(--color-border-secondary);
}

.au-modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text-primary);
}

.au-modal-close {
  width: 28px;
  height: 28px;
  border-radius: var(--border-radius-md);
  border: none;
  background: var(--color-background-secondary);
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background 0.15s;
}

.au-modal-close:hover { background: var(--color-background-tertiary); }

.au-modal-body { padding: 20px; }

.au-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 0.5px solid var(--color-border-secondary);
}

/* ── Form fields ────────────────────────────────────────────── */
.au-form-group {
  margin-bottom: 16px;
}

.au-form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.au-form-input,
.au-form-select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 0.5px solid var(--color-border-secondary);
  border-radius: var(--border-radius-md);
  background: var(--color-background-primary);
  font-size: 13px;
  color: var(--color-text-primary);
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

.au-form-input:focus,
.au-form-select:focus { border-color: var(--bygga-red); }

/* ── Permissions grid ───────────────────────────────────────── */
.au-perms-section {
  margin-top: 8px;
}

.au-perms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.au-perms-hint {
  font-size: 11px;
  color: var(--color-text-tertiary);
  font-style: italic;
}

.au-perms-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.au-perm-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 0.5px solid var(--color-border-secondary);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  user-select: none;
  position: relative;
}

.au-perm-check:hover { border-color: var(--color-text-tertiary); background: var(--color-background-secondary); }


.au-perm-check-box {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--color-border-primary);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.12s;
  font-size: 10px;
  color: white;
}

.au-perm-check.checked .au-perm-check-box {
  background: var(--bygga-red);
  border-color: var(--bygga-red);
}

.au-perm-check.checked .au-perm-check-box::after { content: '✓'; }

.au-perm-check.checked { border-color: var(--bygga-red-light); }

.au-perm-info { flex: 1; }

.au-perm-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.au-perm-desc {
  font-size: 10px;
  color: var(--color-text-tertiary);
  margin-top: 1px;
}

/* ── Delete confirm ─────────────────────────────────────────── */
.au-delete-info {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px;
  background: #FFF5F5;
  border: 0.5px solid #FCA5A5;
  border-radius: var(--border-radius-md);
  margin-bottom: 16px;
}

.au-delete-info i { font-size: 22px; color: var(--bygga-red); flex-shrink: 0; margin-top: 2px; }

.au-delete-info p { font-size: 13px; line-height: 1.5; color: var(--color-text-primary); margin: 0; }

/* ── Invite pending badge ───────────────────────────────────── */
.au-invite-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 8px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 600;
  background: #FEF3C7;
  color: #92400E;
}

/* ── Empty state ────────────────────────────────────────────── */
.au-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--color-text-tertiary);
}
.au-empty i { font-size: 32px; opacity: 0.3; display: block; margin-bottom: 8px; }
.au-empty p { font-size: 13px; margin: 0; }

/* ── Toast ──────────────────────────────────────────────────── */
.au-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 16px;
  border-radius: var(--border-radius-md);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  pointer-events: none;
}

.au-toast.show { opacity: 1; transform: translateY(0); }
.au-toast.success { background: var(--bygga-teal); }
.au-toast.error   { background: var(--bygga-red); }

/* ── Danger button ──────────────────────────────────────────── */
.btn-danger {
  background: var(--bygga-red);
  color: #fff;
  border: none;
  border-radius: var(--border-radius-md);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}
.btn-danger:hover:not(:disabled) { background: var(--bygga-red-dark); }
.btn-danger:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Ghost button ───────────────────────────────────────────── */
.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: 0.5px solid var(--color-border-secondary);
  border-radius: var(--border-radius-md);
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s, color 0.15s;
}
.btn-ghost:hover { border-color: var(--color-border-primary); color: var(--color-text-primary); }

/* ── Small button modifier ──────────────────────────────────── */
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Matrix table: fixed column sizing ───────────────────────── */
.au-table .au-col-fixed { white-space: nowrap; }

.au-table th.au-col-user    { min-width: 160px; }
.au-table th.au-col-role    { min-width: 110px; }
.au-table th.au-col-status  { min-width: 70px; }
.au-table th.au-col-login   { min-width: 88px; }
.au-table th.au-col-actions { min-width: 120px; }

/* ── Matrix: permission column headers (rotated) ────────────── */
.au-table th.au-col-perm {
  width: 22px;
  min-width: 22px;
  max-width: 22px;
  padding: 0 0 8px 0;
  vertical-align: bottom;
  text-align: center;
  height: 96px;
  position: sticky;
  top: 0;
  z-index: 2;
  border-right: 0.5px solid var(--color-border-tertiary);
}

.au-table th.au-col-perm > span {
  display: block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-tertiary);
  line-height: 28px;
}

/* ── Matrix: permission cell ────────────────────────────────── */
.au-perm-cell {
  padding: 0 !important;
  text-align: center;
  width: 22px;
  border-right: 0.5px solid var(--color-border-tertiary);
}

/* ── Matrix: toggle button ──────────────────────────────────── */
.au-perm-toggle {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border-secondary);
  background: transparent;
  cursor: pointer;
  transition: all 0.14s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  outline: none;
  vertical-align: middle;
}

.au-perm-toggle.on {
  background: var(--bygga-red);
  border-color: var(--bygga-red);
}

.au-perm-toggle.on::after {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
}

.au-perm-toggle.off {
  background: transparent;
  border-color: var(--color-border-secondary);
}

.au-perm-toggle.off:hover {
  border-color: var(--color-text-tertiary);
  background: var(--color-background-secondary);
}

.au-perm-toggle.on:hover {
  background: var(--bygga-red-dark);
  border-color: var(--bygga-red-dark);
}

/* Deviates from role defaults */
.au-perm-toggle.perm-extra {
  background: var(--bygga-teal);
  border-color: var(--bygga-teal);
}

.au-perm-toggle.perm-extra:hover {
  opacity: 0.85;
}

.au-perm-toggle.perm-removed {
  border-color: var(--bygga-red-light);
  background: var(--bygga-red-light);
}

.au-perm-toggle.saving {
  opacity: 0.45;
  cursor: wait;
  pointer-events: none;
}

/* ── Matrix: toggle-all header button ──────────────────────── */
.au-perm-all-btn {
  display: block;
  width: 16px;
  height: 16px;
  margin: 4px auto 0;
  border-radius: 2px;
  border: 0.5px solid var(--color-border-secondary);
  background: transparent;
  cursor: pointer;
  padding: 0;
  color: var(--color-text-tertiary);
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  transition: all 0.14s;
  flex-shrink: 0;
}

.au-perm-all-btn:hover {
  border-color: var(--bygga-red);
  color: var(--bygga-red);
  background: var(--bygga-red-light);
}

.au-perm-all-btn.saving {
  opacity: 0.45;
  cursor: wait;
  pointer-events: none;
}

/* ── Custom perms badge (★ next to role) ────────────────────── */
.au-custom-badge {
  display: inline-flex;
  font-size: 9px;
  color: var(--bygga-teal);
  margin-left: 4px;
  vertical-align: middle;
  cursor: default;
}

/* ── Status dot standalone (dot-ativo / dot-pendente / dot-inativo) ─── */
.au-status-dot.dot-ativo    { background: #1D9E75; }
.au-status-dot.dot-pendente { background: var(--amber, #BA7517); }
.au-status-dot.dot-inativo  { background: var(--color-text-tertiary); }

/* ── Self badge ("Eu") ──────────────────────────────────────── */
.au-self-badge {
  display: inline-flex;
  align-items: center;
  height: 16px;
  padding: 0 5px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 600;
  background: var(--bygga-red-light);
  color: var(--bygga-red);
  vertical-align: middle;
  margin-left: 5px;
}

/* ── Row: utilizador inativo ────────────────────────────────── */
.au-row-inativo td { opacity: 0.5; }

/* ── User name in table ─────────────────────────────────────── */
.au-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
}

/* ── Permissions grid in modals (label+checkbox pairs) ──────── */
.au-perms-grid-modal {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 4px;
}

.au-perm-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  border: 0.5px solid var(--color-border-secondary);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  color: var(--color-text-secondary);
  transition: border-color 0.12s, background 0.12s;
}

.au-perm-item:hover { border-color: var(--color-text-tertiary); background: var(--color-background-secondary); }

.au-perm-item input[type="checkbox"] { accent-color: var(--bygga-red); flex-shrink: 0; }
