/* Phân quyền sử dụng – tài khoản, vai trò, ma trận quyền */
body.auth-locked { overflow: hidden; }
body.auth-locked .app-shell { display: none; }

/* Đăng nhập */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  background:
    radial-gradient(900px 520px at 12% 8%, rgba(37, 99, 235, .22), transparent 62%),
    radial-gradient(760px 460px at 88% 92%, rgba(245, 158, 11, .18), transparent 62%),
    #0b1220;
}
.auth-screen[hidden] { display: none; }
.auth-shell {
  width: 100%;
  max-width: 412px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.auth-brand img {
  width: 58px;
  height: auto;
  padding: 5px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(2, 6, 23, .35);
}
.auth-brand-name { font-size: 17px; font-weight: 800; letter-spacing: .12em; }
.auth-brand-sub { font-size: 11.5px; color: #9fb0c8; margin-top: 2px; }
.auth-project {
  max-width: 380px;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.5;
  color: #cbd5e1;
}
.auth-motto {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #fbbf24;
}
.auth-card {
  width: 100%;
  margin-top: 4px;
  padding: 26px 24px 22px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(2, 6, 23, .5);
}
.auth-card h2 { font-size: 20px; color: var(--ink); letter-spacing: -.01em; }
.auth-sub { font-size: 12px; color: var(--muted); margin: 5px 0 18px; line-height: 1.5; }
.auth-card .field { margin-bottom: 13px; }
.auth-card .field input {
  width: 100%;
  box-sizing: border-box;
  height: 40px;
  font-size: 13px;
}
.auth-error {
  margin: 2px 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--red-soft);
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 11.5px;
  line-height: 1.45;
}
.auth-submit { width: 100%; justify-content: center; height: 42px; font-size: 13px; }
.auth-links { display: flex; justify-content: center; margin-top: 12px; }
.auth-hint {
  max-width: 360px;
  margin: 2px 0 0;
  text-align: center;
  font-size: 11px;
  line-height: 1.55;
  color: #94a3b8;
}
.auth-hint b { color: #e2e8f0; }

/* Tài khoản đang đăng nhập */
.account-me {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px dashed var(--line);
}
.account-me .uc-avatar { width: 44px; height: 44px; font-size: 14px; }
.account-me b { display: block; font-size: 14px; color: var(--ink); }
.account-me span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.account-actions { display: flex; flex-direction: column; gap: 8px; }
.account-actions .btn { width: 100%; justify-content: center; }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  max-width: 230px;
}
.user-chip:hover { border-color: #c7d2e3; box-shadow: var(--shadow-sm); }
.uc-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; letter-spacing: .02em;
  background: #e2e8f0; color: #334155;
  flex: 0 0 auto;
}
.uc-avatar.lg { width: 46px; height: 46px; font-size: 15px; }
.uc-avatar.tone-blue { background: var(--blue-soft); color: #1d4ed8; }
.uc-avatar.tone-cyan { background: var(--cyan-soft); color: #0e7490; }
.uc-avatar.tone-amber { background: var(--brand-soft); color: var(--brand-dark); }
.uc-avatar.tone-violet { background: var(--violet-soft); color: #6d28d9; }
.uc-avatar.tone-gray { background: #f1f5f9; color: #475569; }
.uc-avatar.tone-green { background: var(--green-soft); color: #047857; }
.uc-avatar.tone-rose, .uc-avatar.tone-red { background: var(--red-soft); color: #b91c1c; }
.uc-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: left; min-width: 0; }
.uc-meta b { font-size: 11.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uc-meta small { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uc-caret { font-size: 9px; color: var(--muted-2); }

/* Chip vai trò */
.role-chip {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px; font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}
.role-chip.tone-blue { background: var(--blue-soft); color: #1d4ed8; border-color: #dbeafe; }
.role-chip.tone-cyan { background: var(--cyan-soft); color: #0e7490; border-color: #cffafe; }
.role-chip.tone-amber { background: var(--brand-soft); color: var(--brand-dark); border-color: #fde68a; }
.role-chip.tone-violet { background: var(--violet-soft); color: #6d28d9; border-color: #ede9fe; }
.role-chip.tone-gray { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.role-chip.tone-green { background: var(--green-soft); color: #047857; border-color: #d1fae5; }
.role-chip.tone-rose, .role-chip.tone-red { background: var(--red-soft); color: #b91c1c; border-color: #fecaca; }

/* Banner chỉ xem */
.role-banner {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  margin-bottom: 14px;
}
.role-banner svg { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; color: var(--muted); }
.role-banner b { display: block; font-size: 12.5px; color: var(--ink); margin-bottom: 2px; }
.role-banner span { font-size: 12px; color: var(--muted); line-height: 1.45; }
.role-banner.tone-amber { background: var(--brand-soft); border-color: #fde68a; }
.role-banner.tone-amber svg { color: var(--brand-dark); }
.role-banner.tone-violet { background: var(--violet-soft); border-color: #ede9fe; }
.role-banner.tone-violet svg { color: var(--violet); }
.role-banner.tone-blue { background: var(--blue-soft); border-color: #dbeafe; }
.role-banner.tone-blue svg { color: var(--blue); }
.role-banner.tone-cyan { background: var(--cyan-soft); border-color: #cffafe; }
.role-banner.tone-cyan svg { color: var(--cyan); }
.role-banner.tone-green { background: var(--green-soft); border-color: #d1fae5; }
.role-banner.tone-green svg { color: var(--green); }
.role-banner.tone-rose, .role-banner.tone-red { background: var(--red-soft); border-color: #fecaca; }
.role-banner.tone-rose svg, .role-banner.tone-red svg { color: var(--red); }

/* Thẻ tài khoản hiện tại */
.perm-me {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 18px;
  flex-wrap: wrap;
  border-left: 4px solid var(--blue);
}
.perm-me.tone-cyan { border-left-color: var(--cyan); }
.perm-me.tone-amber { border-left-color: var(--brand); }
.perm-me.tone-violet { border-left-color: var(--violet); }
.perm-me.tone-gray { border-left-color: var(--muted-2); }
.perm-me.tone-green { border-left-color: var(--green); }
.perm-me.tone-rose, .perm-me.tone-red { border-left-color: var(--red); }
.perm-me-main { display: flex; align-items: center; gap: 14px; min-width: 0; }
.perm-me-name { font-size: 16px; font-weight: 750; color: var(--ink); }
.perm-me-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.perm-me-caps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.perm-me-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Danh sách thành viên */
.perm-person { display: flex; align-items: center; gap: 10px; }
.perm-person .cell-title { font-weight: 650; }
.self-tag {
  display: inline-block; margin-left: 4px; padding: 1px 6px;
  font-size: 9px; font-weight: 800; text-transform: uppercase;
  color: var(--blue); background: var(--blue-soft); border-radius: 999px;
}
.role-select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 5px 8px;
  font-size: 11.5px;
  color: var(--ink-2);
  font-family: inherit;
  cursor: pointer;
  max-width: 150px;
}
.role-select:focus { outline: 2px solid #bfdbfe; border-color: #93c5fd; }
.role-select.is-disabled, .btn.is-disabled { opacity: .55; cursor: not-allowed; }
.count-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-dark);
  font-size: 11px; font-weight: 800;
  margin-left: 6px;
}
.perm-empty {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 18px;
  color: var(--muted); font-size: 12.5px;
}
.perm-empty svg { width: 18px; height: 18px; color: var(--green); }

/* Thẻ vai trò */
.perm-role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
  gap: 12px;
  padding: 4px 16px 16px;
}
.perm-role-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border-top: 3px solid var(--muted-2);
}
.perm-role-card.tone-blue { border-top-color: var(--blue); }
.perm-role-card.tone-cyan { border-top-color: var(--cyan); }
.perm-role-card.tone-amber { border-top-color: var(--brand); }
.perm-role-card.tone-violet { border-top-color: var(--violet); }
.perm-role-card.tone-cyan { border-top-color: var(--cyan); }
.perm-role-card.tone-green { border-top-color: var(--green); }
.perm-role-card.tone-rose, .perm-role-card.tone-red { border-top-color: var(--red); }
.perm-role-card.tone-gray { border-top-color: var(--muted-2); }
.prc-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.prc-top b { font-size: 13px; color: var(--ink); }
.perm-role-card p { font-size: 12px; color: var(--ink-2); line-height: 1.45; min-height: 34px; }
.prc-duty { font-size: 11px; color: var(--muted); line-height: 1.5; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }

/* Ma trận */
.perm-matrix-wrap { max-height: 620px; overflow: auto; }
.perm-matrix th, .perm-matrix td { font-size: 11.5px; }
.perm-matrix td:first-child { font-weight: 600; color: var(--ink-2); }
.perm-group-row td {
  background: #f1f5f9;
  font-size: 10.5px !important;
  font-weight: 800 !important;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted) !important;
}
.perm-yes { color: var(--green); font-weight: 800; }
.perm-no { color: #cbd5e1; }

/* Modal đổi tài khoản */
.account-list { display: flex; flex-direction: column; gap: 6px; }
.account-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color .15s, background .15s;
}
.account-row:hover { border-color: #bfdbfe; background: var(--blue-soft); }
.account-row.active { border-color: #bfdbfe; background: var(--blue-soft); }
.ar-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; flex: 1; }
.ar-meta b { font-size: 12.5px; color: var(--ink); }
.ar-meta small { font-size: 11px; color: var(--muted); margin-top: 1px; }
.ar-use { font-size: 11px; font-weight: 700; color: var(--blue); }
.ar-check svg { width: 17px; height: 17px; color: var(--green); }
.account-foot {
  display: flex; align-items: center; gap: 6px;
  justify-content: center;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-size: 12px; color: var(--muted);
}

/* Chế độ chỉ xem: giảm cảm giác thao tác */
body.perm-readonly .crew-cell-input,
body.perm-readonly .crew-cell-input.note { background: #f8fafc; color: var(--muted); }

@media (max-width: 900px) {
  .user-chip { max-width: 150px; }
  .uc-meta { display: none; }
  .perm-me { align-items: flex-start; }
  .perm-role-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .perm-role-grid { grid-template-columns: 1fr; }
  .perm-me-actions { width: 100%; }
}
