/* ============================================================
   IAM — Identity & Access Management
   White-label: sobrescreva --brand-* via <style> no <head>
   ============================================================ */

:root {
  /* ── Brand (white label — defaults ECO Medical Center) ── */
  --brand-primary:   #004d43;
  --brand-light:     #e8f5f3;
  --brand-mid:       #007a6b;

  /* ── Brand (fonte/texto/estados de botão — sobrescritos via
     templates/iam/_brand_style.html a partir de IAM_BRAND_*) ── */
  --brand-font:          'Poppins', sans-serif;
  --brand-text:          #1e293b;
  --brand-btn-text:      #ffffff;
  --brand-hover:         var(--brand-mid);
  --brand-hover-text:    #ffffff;
  --brand-disabled:      #cbd5e1;
  --brand-disabled-text: #64748b;

  /* ── UI tokens ─────────────────────────────────────────── */
  --bg:        #f3f4f6;
  --paper:     #ffffff;
  --ink:       var(--brand-text);
  --muted:     #64748b;
  --border:    #e2e8f0;
  --radius:    10px;
  --shadow:    0 2px 8px rgba(0,0,0,.08);

  --danger:    #ef4444;
  --warning:   #f59e0b;
  --success:   #10b981;
  --info:      #3b82f6;

  --sidebar-w: 240px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--brand-font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}

/* ── Login ─────────────────────────────────────────────────── */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-mid) 100%);
}

.login-card {
  background: var(--paper);
  border-radius: 16px;
  padding: 40px 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--brand-primary);
}

.login-brand-name {
  font-weight: 600;
  font-size: 16px;
  color: var(--brand-primary);
}

.login-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 24px;
  color: var(--ink);
}

.login-form .form-group { margin-bottom: 16px; }

.login-divider {
  text-align: center;
  margin: 20px 0;
  position: relative;
  color: var(--muted);
  font-size: 12px;
}

.login-divider::before, .login-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 38%;
  height: 1px;
  background: var(--border);
}

.login-divider::before { left: 0; }
.login-divider::after  { right: 0; }

.login-oauth {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s, border-color .15s;
  cursor: pointer;
  width: 100%;
}

.btn-oauth:hover { background: var(--bg); border-color: #c0cad5; }

.login-footer {
  text-align: center;
  margin-top: 20px;
}

.login-link {
  color: var(--brand-primary);
  font-size: 13px;
  text-decoration: none;
}

.login-link:hover { text-decoration: underline; }

/* ── Admin layout ───────────────────────────────────────────── */

.admin-body { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--brand-primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.sidebar-brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .5px;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-section {
  padding: 16px 20px 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,.45);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: 13.5px;
  transition: background .15s, color .15s;
}

.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 500; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-user {
  font-size: 12px;
  color: rgba(255,255,255,.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

.btn-logout {
  font-size: 12px;
  color: rgba(255,255,255,.6);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,.2);
  transition: background .15s;
  white-space: nowrap;
}

.btn-logout:hover { background: rgba(255,255,255,.1); color: #fff; }

.admin-main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }

.admin-content { padding: 32px 32px 48px; max-width: 1200px; }

/* ── Page header ────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-title { font-size: 22px; font-weight: 600; margin: 0 0 4px; color: var(--ink); }
.page-subtitle { font-size: 13px; color: var(--muted); margin: 0; }

/* ── Cards ──────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}

.stat-icon-users    { background: var(--brand-light); color: var(--brand-primary); }
.stat-icon-profiles { background: #ede9fe; color: #7c3aed; }
.stat-icon-perms    { background: #fef3c7; color: #b45309; }

.stat-value { font-size: 28px; font-weight: 700; color: var(--ink); }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-link  { font-size: 12px; color: var(--brand-primary); text-decoration: none; margin-top: 8px; }
.stat-link:hover { text-decoration: underline; }

.section-card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title { font-size: 15px; font-weight: 600; margin: 0; }

/* ── Table ──────────────────────────────────────────────────── */

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
}

.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }
.data-table .actions { text-align: right; white-space: nowrap; }

/* ── Buttons ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, opacity .15s;
  line-height: 1;
}

.btn-primary   { background: var(--brand-primary); color: var(--brand-btn-text); }
.btn-primary:hover { background: var(--brand-hover); color: var(--brand-hover-text); }

.btn-primary:disabled,
.btn-primary[disabled] {
  background: var(--brand-disabled);
  color: var(--brand-disabled-text);
  cursor: not-allowed;
  opacity: 1;
}

.btn-outline   { background: transparent; color: var(--ink); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }

.btn-ghost     { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); }

.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }

.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover { opacity: .9; }

.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .9; }

.btn-full  { width: 100%; justify-content: center; }
.btn-sm    { padding: 5px 10px; font-size: 12px; }
.btn-xs    { padding: 2px 7px; font-size: 11px; }

/* ── Badges ─────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-active   { background: #dcfce7; color: #166534; }
.badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-locked   { background: #fee2e2; color: #991b1b; }
.badge-admin    { background: #fef3c7; color: #92400e; margin-left: 4px; }
.badge-action   { background: #e0f2fe; color: #0369a1; font-weight: 500; }
.badge-2fa      { background: var(--brand-light); color: var(--brand-primary); }

.badge-provider-local     { background: #f1f5f9; color: #475569; }
.badge-provider-google    { background: #fce8e6; color: #c5221f; }
.badge-provider-microsoft { background: #e8f0fe; color: #1a73e8; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--brand-light);
  color: var(--brand-primary);
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 500;
  margin: 1px 2px;
}

.tag-google { background: #fce8e6; color: #c5221f; }
.tag-ms     { background: #e8f0fe; color: #1a73e8; }

/* ── Forms ──────────────────────────────────────────────────── */

.form-card { max-width: 860px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-group label { font-size: 13px; font-weight: 500; color: var(--ink); }

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="tel"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group textarea,
.form-group select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--paper);
  transition: border-color .15s;
  width: 100%;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-light);
}

.form-group input[readonly] { background: var(--bg); color: var(--muted); }

.field-hint { font-size: 11.5px; color: var(--muted); }

.form-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.form-help { font-size: 12.5px; color: var(--muted); margin-bottom: 16px; line-height: 1.6; }

.form-check-group { flex-direction: row; align-items: center; }

.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  cursor: pointer;
}

.check-label input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--brand-primary);
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.info-box {
  padding: 10px 14px;
  background: var(--brand-light);
  border-left: 3px solid var(--brand-primary);
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  color: var(--brand-primary);
  margin-bottom: 16px;
}

/* ── Phone input ────────────────────────────────────────────── */

.phone-input-group {
  display: flex;
  gap: 8px;
}

.phone-input-group .country-code {
  width: 80px;
  flex-shrink: 0;
}

.phone-input-group .phone-number { flex: 1; }

/* ── Mostrar/ocultar senha ─────────────────────────────────────── */

.password-field { position: relative; }

.password-field input[type="password"],
.password-field input[type="text"] {
  padding-right: 42px;
}

.pwd-toggle-btn {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.pwd-toggle-btn:hover { background: var(--bg); color: var(--ink); }

.pwd-toggle-btn .icon-eye-off { display: none; }
.pwd-toggle-btn.is-visible .icon-eye     { display: none; }
.pwd-toggle-btn.is-visible .icon-eye-off { display: block; }

/* ── Password strength ──────────────────────────────────────── */

.pwd-strength-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin-top: 6px;
  overflow: hidden;
}

.pwd-strength-fill {
  height: 100%;
  border-radius: 2px;
  transition: width .3s, background .3s;
  width: 0;
}

.pwd-strength-fill.s1 { background: var(--danger);  width: 25%; }
.pwd-strength-fill.s2 { background: var(--warning); width: 50%; }
.pwd-strength-fill.s3 { background: var(--info);    width: 75%; }
.pwd-strength-fill.s4 { background: var(--success); width: 100%; }

.pwd-rules {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pwd-rules li {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.pwd-rules li::before {
  content: '○';
  font-size: 10px;
  flex-shrink: 0;
}

.pwd-rules li.ok { color: var(--success); }
.pwd-rules li.ok::before { content: '●'; }

/* ── OTP / 2FA input ────────────────────────────────────────── */

.otp-input {
  letter-spacing: 6px;
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: monospace;
}

.otp-input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-light);
}

.twofa-methods {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.twofa-method-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--paper);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  transition: border-color .15s, background .15s;
}

.twofa-method-btn:hover { border-color: var(--brand-primary); background: var(--brand-light); }
.twofa-method-btn.active { border-color: var(--brand-primary); background: var(--brand-light); }

/* ── QR code display ────────────────────────────────────────── */

.qr-container {
  text-align: center;
  margin: 20px 0;
}

.qr-container img {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
}

.secret-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: monospace;
  font-size: 14px;
  letter-spacing: 2px;
  text-align: center;
  color: var(--ink);
  margin: 8px 0;
  word-break: break-all;
}

/* ── Backup codes ───────────────────────────────────────────── */

.backup-codes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.backup-code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-family: monospace;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  letter-spacing: 2px;
}

/* ── Account settings tabs ──────────────────────────────────── */

.account-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.account-tab {
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}

.account-tab:hover { color: var(--ink); }
.account-tab.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }

.twofa-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
}

.twofa-status-info { display: flex; align-items: center; gap: 12px; }
.twofa-status-icon { font-size: 22px; }
.twofa-status-label { font-weight: 500; font-size: 14px; }
.twofa-status-desc { font-size: 12px; color: var(--muted); }

/* ── Profiles grid ──────────────────────────────────────────── */

.profiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.profile-check {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.profile-check:has(input:checked) {
  border-color: var(--brand-primary);
  background: var(--brand-light);
}

.profile-check input { display: none; }
.profile-name { font-weight: 500; font-size: 13px; }
.profile-desc { font-size: 11.5px; color: var(--muted); }
.profile-inactive { opacity: .5; }

/* ── Permissions grid ───────────────────────────────────────── */

.permissions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.perm-group { border: 1px solid var(--border); border-radius: 8px; padding: 12px; }

.perm-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin-bottom: 8px;
}

.perm-check {
  display: flex;
  flex-direction: column;
  padding: 5px 0;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.perm-check:last-child { border-bottom: none; }
.perm-check input[type="checkbox"] { display: none; }
.perm-check:has(input:checked) .perm-action { color: var(--brand-primary); font-weight: 600; }

.perm-action { font-size: 13px; }
.perm-desc   { font-size: 11.5px; color: var(--muted); }

.perm-code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  font-family: monospace;
}

/* ── Search & filter bars ───────────────────────────────────── */

.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }

.search-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13.5px;
}

.search-input:focus { outline: none; border-color: var(--brand-primary); }

.filter-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; }

.filter-group input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
}

.filter-group input:focus { outline: none; border-color: var(--brand-primary); }

/* ── Pagination ─────────────────────────────────────────────── */

.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: center; }

.page-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--ink);
  font-size: 12.5px;
}

.page-btn.active { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.page-btn:not(.active):hover { background: var(--bg); }

/* ── Alerts ─────────────────────────────────────────────────── */

.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

.alert-danger   { background: #fee2e2; color: #b91c1c; border-left: 3px solid var(--danger); }
.alert-success  { background: #dcfce7; color: #166534; border-left: 3px solid var(--success); }
.alert-warning  { background: #fef3c7; color: #92400e; border-left: 3px solid var(--warning); }
.alert-info     { background: #e0f2fe; color: #0369a1; border-left: 3px solid var(--info); }

/* ── Steps indicator ────────────────────────────────────────── */

.steps {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 28px;
}

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.step-num {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  background: var(--border);
  color: var(--muted);
  flex-shrink: 0;
}

.step.active .step-num { background: var(--brand-primary); color: #fff; }
.step.active { color: var(--ink); font-weight: 500; }
.step.done .step-num { background: var(--success); color: #fff; }

.step-sep { width: 32px; height: 1px; background: var(--border); flex-shrink: 0; }

/* ── Misc ───────────────────────────────────────────────────── */

.text-muted   { color: var(--muted); }
.text-sm      { font-size: 12.5px; }
.text-center  { text-align: center; }
.nowrap       { white-space: nowrap; }

.details-pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-size: 11.5px;
  margin-top: 4px;
  overflow: auto;
  max-height: 200px;
}

code { font-family: monospace; }
