/* Authentication & Staff User Management — Taj Al Mada */

body.auth-locked .rail,
body.auth-locked .workspace,
body.auth-locked .skip {
  display: none !important;
}

#auth-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top right, #28538a 0%, #142b50 48%, #0c1b32 100%);
  overflow-y: auto;
}

#auth-screen[hidden] {
  display: none !important;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 24px 60px rgba(7, 17, 34, 0.45);
  padding: 28px 28px 24px;
  color: #152742;
}

.auth-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-brand img {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid #e0e6ee;
  background: #0c1b32;
}

.auth-brand h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
  color: #102441;
  font-family: Georgia, "Times New Roman", serif;
}

.auth-brand small {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: #58677b;
  font-weight: 600;
}

.auth-lang {
  display: inline-flex;
  border: 1px solid #d7e0ec;
  border-radius: 8px;
  overflow: hidden;
  background: #f4f6fa;
}

.auth-lang button {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #46576e;
  cursor: pointer;
}

.auth-lang button[aria-pressed="true"] {
  background: #102441;
  color: #ffffff;
}

.auth-subtitle {
  margin: 0 0 18px;
  font-size: 13.5px;
  color: #58677b;
  line-height: 1.5;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-field label {
  font-size: 13px;
  font-weight: 600;
  color: #152742;
}

.auth-field input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid #cfd8e5;
  border-radius: 8px;
  font-size: 14px;
  color: #152742;
  background: #ffffff;
  box-sizing: border-box;
}

.auth-field input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: #2563eb;
}

.auth-password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.auth-password-wrap input {
  padding-right: 64px;
}

.auth-toggle-pw {
  position: absolute;
  right: 8px;
  border: 0;
  background: #f1f5f9;
  color: #334155;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.auth-toggle-pw:hover {
  background: #e2e8f0;
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffe7ea;
  color: #af263d;
  font-size: 13px;
  font-weight: 500;
}

.auth-submit {
  width: 100%;
  min-height: 44px;
  margin-top: 4px;
  border: 0;
  border-radius: 8px;
  background: #102441;
  color: #ffffff;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.auth-submit:hover {
  background: #1b3863;
}

.auth-submit:disabled {
  opacity: 0.65;
  cursor: wait;
}

.auth-footer {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #edf1f7;
  font-size: 12px;
  color: #6b7a90;
  text-align: center;
}

/* Header user controls */
.user-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 6px;
}

.user-controls[hidden] {
  display: none !important;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 8px;
  background: #f4f6fa;
  border: 1px solid #e0e6ee;
  font-size: 13px;
  color: #152742;
}

.user-chip strong {
  font-weight: 600;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.role-badge.admin {
  background: #fff2cf;
  color: #805307;
}

.role-badge.staff {
  background: #e6efff;
  color: #2459b2;
}

.status-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status-badge.active {
  background: #e3f6eb;
  color: #17623c;
}

.status-badge.disabled {
  background: #ffe7ea;
  color: #af263d;
}

/* Staff Management Workspace */
.staff-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.staff-stat {
  background: #ffffff;
  border: 1px solid #e0e6ee;
  border-radius: 12px;
  padding: 16px 18px;
}

.staff-stat span {
  display: block;
  font-size: 12.5px;
  color: #58677b;
  margin-bottom: 6px;
}

.staff-stat strong {
  font-size: 26px;
  color: #102441;
}

.staff-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.staff-toolbar p {
  margin: 0;
  color: #58677b;
  font-size: 13.5px;
}

.staff-dialog {
  width: min(540px, 94vw);
  max-height: 92dvh;
  padding: 0;
  border: 1px solid #d8e1ec;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(12, 27, 50, 0.28);
}

.staff-dialog::backdrop {
  background: rgba(12, 27, 50, 0.55);
}

.staff-dialog form {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.staff-dialog h2 {
  margin: 0;
  font-size: 18px;
  color: #102441;
}

.staff-dialog .staff-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.staff-dialog .staff-grid .wide {
  grid-column: 1 / -1;
}

.staff-dialog label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: #152742;
}

.staff-dialog input,
.staff-dialog select {
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #cfd8e5;
  border-radius: 7px;
  font-size: 14px;
  color: #152742;
  background: #ffffff;
}

.staff-dialog .staff-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.staff-dialog .staff-checkbox input {
  min-height: auto;
  width: 17px;
  height: 17px;
}

.staff-dialog .staff-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.btn-danger {
  background: #ffe7ea;
  color: #af263d;
  border: 1px solid #f7c2ca;
  border-radius: 7px;
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger:hover {
  background: #ffd4da;
}

@media (max-width: 780px) {
  .staff-summary {
    grid-template-columns: 1fr;
  }
  .staff-dialog .staff-grid {
    grid-template-columns: 1fr;
  }
  .user-chip strong {
    max-width: 90px;
  }
  #change-own-password {
    display: none;
  }
  body:not(.auth-locked) .workspace main {
    padding-bottom: 84px;
  }
}

/* PWA Install Button, Offline Banner & Mobile Bottom App Navigation */
.install-app-btn {
  background: #102441;
  color: #ffffff;
  border: 1px solid #102441;
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.install-app-btn:hover {
  background: #1b3863;
}

.install-app-btn[hidden] {
  display: none !important;
}

.offline-banner {
  position: sticky;
  top: 0;
  z-index: 500;
  background: #805307;
  color: #ffffff;
  text-align: center;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
}

.offline-banner[hidden] {
  display: none !important;
}

.pwa-steps {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  line-height: 1.5;
  color: #152742;
}

.mobile-bottom-nav {
  display: none;
}

@media (max-width: 780px) {
  body:not(.auth-locked) .mobile-bottom-nav:not([hidden]) {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 400;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    background: #0c1b32;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -6px 20px rgba(12, 27, 50, 0.25);
  }

  .mbn-btn {
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.72);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 5px 2px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
  }

  .mbn-btn .mbn-icon {
    font-size: 16px;
    line-height: 1;
  }

  .mbn-btn.active {
    color: #d9b66d;
    background: rgba(255, 255, 255, 0.08);
  }
}

@media print {
  #auth-screen,
  #user-controls,
  #staff-workspace,
  #install-app-btn,
  #offline-banner,
  #mobile-bottom-nav {
    display: none !important;
  }
}


/* --- SECURITY, 2FA, PERMISSIONS & AUDIT LOG --- */
.totp-code-input {
  text-align: center;
  font-size: 22px !important;
  font-weight: 700;
  letter-spacing: 0.28em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.auth-back-link {
  border: 0;
  background: transparent;
  color: #3b5998;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px;
  text-align: center;
}
.auth-back-link:hover {
  text-decoration: underline;
}

.sec-2fa-dot {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  background: #dcfce7;
  color: #166534;
  vertical-align: middle;
}

#password-dialog {
  max-width: 580px;
  width: min(94vw, 580px);
}

.sec-dialog-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sec-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sec-dialog-head h2 {
  margin: 0;
  font-size: 19px;
}

.sec-close-x {
  width: 34px;
  height: 34px;
  padding: 0 !important;
  font-size: 20px;
  line-height: 1;
  border-radius: 10px;
}

.sec-card {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px 16px;
  background: #f8fafc;
}

.sec-card h3 {
  margin: 0 0 4px;
  font-size: 14.5px;
  color: #0f172a;
}

.sec-card .sub {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: #58677b;
}

.sec-card-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sec-idle-select {
  min-width: 150px;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  font-size: 13px;
  font-weight: 600;
}

.sec-inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.sec-inline-form input {
  flex: 1 1 180px;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  font-size: 13.5px;
}

.sec-qr-setup {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-top: 10px;
}

.sec-qr-box {
  background: #ffffff;
  border: 1px solid #d7e0ec;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sec-qr-box svg {
  width: 164px;
  height: 164px;
  display: block;
}

.sec-qr-steps p {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.45;
  color: #1e293b;
}

.sec-secret-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.sec-secret-row code {
  flex: 1;
  padding: 7px 10px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 12px;
  letter-spacing: 0.08em;
  word-break: break-all;
}

.staff-summary-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.staff-perms-box {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #dbe4f0;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.staff-perms-box[hidden] {
  display: none !important;
}

.staff-perms-box h4 {
  margin: 0 0 2px;
  font-size: 13px;
  color: #0f172a;
}

.perm-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.perm-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.perm-pill.full {
  margin-top: 5px;
  background: #eff6ff;
  color: #1d4ed8;
}

.perm-pill.allow {
  background: #ecfdf5;
  color: #047857;
}

.perm-pill.deny {
  background: #fef2f2;
  color: #b91c1c;
  text-decoration: line-through;
  opacity: 0.85;
}

.audit-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.audit-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.audit-filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.audit-filter-btn {
  border: 1px solid #d7e0ec;
  background: #ffffff;
  color: #334155;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.audit-filter-btn.active {
  background: #102441;
  border-color: #102441;
  color: #ffffff;
}

.audit-search-input {
  min-width: 220px;
  flex: 0 1 280px;
  padding: 7px 12px;
  border: 1px solid #cfd8e5;
  border-radius: 999px;
  font-size: 13px;
  background: #ffffff;
}

.audit-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.audit-pill.ok { background: #dcfce7; color: #166534; }
.audit-pill.info { background: #dbeafe; color: #1e40af; }
.audit-pill.warn { background: #fef3c7; color: #92400e; }
.audit-pill.danger { background: #fee2e2; color: #991b1b; }
.audit-pill.muted { background: #f1f5f9; color: #475569; }

html[data-theme="dark"] .sec-card,
html[data-theme="dark"] .staff-perms-box {
  background: #162238;
  border-color: #293954;
}

html[data-theme="dark"] .sec-card h3,
html[data-theme="dark"] .staff-perms-box h4,
html[data-theme="dark"] .sec-qr-steps p {
  color: #f1f5f9;
}

html[data-theme="dark"] .sec-idle-select,
html[data-theme="dark"] .sec-inline-form input,
html[data-theme="dark"] .sec-secret-row code,
html[data-theme="dark"] .audit-search-input,
html[data-theme="dark"] .audit-filter-btn {
  background: #0f172a;
  border-color: #334155;
  color: #e2e8f0;
}

html[data-theme="dark"] .audit-filter-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #ffffff;
}

@media (max-width: 680px) {
  .sec-qr-setup {
    grid-template-columns: 1fr;
  }
  .staff-summary-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}


/* --- AUDIT LOG IP & COUNTRY BADGES + CLEAN COLUMN WIDTHS --- */
.audit-table .audit-col-time {
  white-space: nowrap;
  width: 145px;
}

.audit-table .audit-col-event {
  white-space: nowrap;
  width: 155px;
}

.audit-table .audit-col-user {
  min-width: 155px;
}

.audit-table .audit-col-ip {
  min-width: 185px;
}

.audit-table .audit-col-detail {
  min-width: 220px;
  line-height: 1.45;
}

.audit-ip-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.audit-loc-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #475569;
  line-height: 1.3;
}

.audit-cc-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.audit-cc-badge.country {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

.audit-cc-badge.local {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.audit-cc-badge.lan {
  background: #ede9fe;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
}

html[data-theme="dark"] .audit-loc-row {
  color: #cbd5e1;
}

html[data-theme="dark"] .audit-cc-badge.country {
  background: #0c4a6e;
  color: #bae6fd;
  border-color: #0369a1;
}

html[data-theme="dark"] .audit-cc-badge.local {
  background: #1e293b;
  color: #cbd5e1;
  border-color: #334155;
}

html[data-theme="dark"] .audit-cc-badge.lan {
  background: #3b0764;
  color: #ddd6fe;
  border-color: #6d28d9;
}


/* Granular Staff Access Permissions Matrix */
dialog.staff-dialog {
  max-width: min(720px, 95vw) !important;
  width: min(720px, 95vw);
  max-height: 92dvh !important;
  overflow-y: auto !important;
}
.perm-matrix-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.perm-matrix-head h4 { margin: 0; }
.perm-quick-btns { display: flex; gap: 6px; }
.perm-qbtn { padding: 4px 10px !important; min-height: 28px !important; font-size: 12px !important; }
.perm-matrix-wrap { overflow: auto; max-height: 36dvh; border: 1px solid var(--border, #e2e8f0); border-radius: 10px; background: var(--surface, #fff); }
.perm-matrix { width: 100%; border-collapse: collapse; font-size: 13px; }
.perm-matrix th, .perm-matrix td { padding: 7px 10px; border-bottom: 1px solid var(--border, #e2e8f0); text-align: left; }
.perm-matrix thead th { position: sticky; top: 0; z-index: 2; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; background: #f1f5f9; font-weight: 700; }
.perm-matrix th:not(:first-child), .perm-matrix td.perm-cell { text-align: center; white-space: nowrap; }
.perm-matrix tbody tr:last-child td { border-bottom: none; }
.perm-matrix input[type="checkbox"] { width: 16px; height: 16px; accent-color: #1d4ed8; cursor: pointer; }
.perm-na { color: #94a3b8; font-weight: 600; }
dialog.staff-dialog .staff-actions {
  position: sticky;
  bottom: 0;
  background: var(--surface, #ffffff);
  padding: 12px 0 4px;
  margin-top: 12px;
  border-top: 1px solid var(--border, #e2e8f0);
  z-index: 3;
}
