/* ============================================================
   User Management Module -- Shared Styles
   Apex GUI spec compliant: light theme, mobile-first.
   Used by: login/index.html, profile/index.html, admin/users/index.html
   ============================================================ */

:root {
  --bg-page: #f6f8fa;
  --bg-card: #ffffff;
  --text-primary: #222;
  --text-secondary: #555;
  --text-hint: #888;
  --accent-blue: #1a5faf;
  --green-up: #14ae5c;
  --red-down: #f23645;
  --border: #e0e0e0;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

html, body { overflow-x: hidden; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  padding: 56px 16px 32px;
  padding-top: calc(56px + env(safe-area-inset-top));
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  line-height: 1.5;
}

.container { max-width: 960px; margin: 0 auto; }

/* -- Home pill / Version badge (fixed) -- */
.home-pill {
  position: fixed; top: 12px; left: 12px; z-index: 100;
  display: inline-block; background: #ffffff; color: var(--accent-blue);
  border: 1px solid #ccc; border-radius: 20px; padding: 6px 14px;
  font-size: 12px; text-decoration: none; box-shadow: 0 1px 4px rgba(0,0,0,.12);
  min-height: 32px; line-height: 20px;
}
.home-pill:hover { background: #f0f4f8; border-color: #aaa; }

.version-badge {
  position: fixed; top: 12px; right: 12px; z-index: 100;
  font-size: 11px; font-weight: 500; color: var(--text-hint);
  background: rgba(255,255,255,0.85); border: 1px solid var(--border);
  border-radius: 14px; padding: 4px 12px; white-space: nowrap; letter-spacing: .02em;
}

/* -- Title row -- */
.title-row { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.title-row .grow { flex: 1; min-width: 200px; }
.page-title { font-size: 1.9rem; font-weight: 700; color: #111; margin-bottom: 4px; }
.page-subtitle { font-size: .85rem; color: var(--text-secondary); }

/* -- Buttons -- */
.btn {
  padding: 8px 16px; font-size: .85rem; font-weight: 600; border-radius: 6px;
  cursor: pointer; border: 1px solid #ccc; background: #fff; color: #333;
  white-space: nowrap; transition: background .15s, border-color .15s;
  min-height: 44px;
}
.btn:hover { background: #eef2f8; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent-blue); color: #fff; border-color: var(--accent-blue); }
.btn-primary:hover { background: #14538f; }
.btn-danger-solid { background: #c0392b; color: #fff; border-color: #c0392b; }
.btn-danger-solid:hover { background: #a93226; }
.btn-sm { padding: 5px 12px; font-size: .78rem; min-height: 36px; }
.btn-text-danger {
  background: none; border: none; color: var(--red-down); font-weight: 600;
  font-size: .82rem; cursor: pointer; padding: 8px 6px; min-height: 44px;
}
.btn-text-danger:hover { text-decoration: underline; }
.btn-text-danger:disabled { color: #ccc; cursor: not-allowed; text-decoration: none; }
.btn-text-link {
  background: none; border: none; color: var(--accent-blue); font-weight: 600;
  font-size: .82rem; cursor: pointer; padding: 8px 6px; min-height: 44px;
}
.btn-text-link:hover { text-decoration: underline; }
.btn-block { width: 100%; }

/* -- Section / Card -- */
.section { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 18px; }
.section-header { display: flex; align-items: center; gap: 8px; padding: 13px 18px; border-bottom: 1px solid #e8e8e8; background: #fafafa; flex-wrap: wrap; }
.section-header h2 { font-size: .93rem; font-weight: 600; color: #111; flex: 1; }
.section-header .hint { font-size: .72rem; color: var(--text-hint); }
.section-body { padding: 16px 18px; }

/* -- Badges / pills -- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-green { background: #e6f7ee; color: var(--green-up); }
.badge-amber { background: #fff8e6; color: #b8860b; }
.badge-blue  { background: #e6f0fa; color: var(--accent-blue); }
.badge-grey  { background: #f0f0f0; color: var(--text-hint); }
.badge-red   { background: #fde8ea; color: var(--red-down); }

/* -- Avatar (initials circle, hash-based palette) -- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; font-weight: 700; flex-shrink: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.avatar-lg { width: 64px; height: 64px; font-size: 1.35rem; }
.avatar-sm { width: 48px; height: 48px; font-size: 1.05rem; }
.avatar-c0 { background: #dbeafe; color: #1e40af; }
.avatar-c1 { background: #dcfce7; color: #166534; }
.avatar-c2 { background: #fef3c7; color: #92400e; }
.avatar-c3 { background: #fee2e2; color: #991b1b; }
.avatar-c4 { background: #ede9fe; color: #5b21b6; }
.avatar-c5 { background: #fce7f3; color: #9d174d; }
.avatar-c6 { background: #ccfbf1; color: #0f766e; }
.avatar-c7 { background: #f0f2f5; color: #444444; }

/* -- Provider icon chip -- */
.provider-cell { display: flex; align-items: center; gap: 8px; }
.provider-cell svg { flex-shrink: 0; border-radius: 50%; }
.provider-name { font-weight: 600; color: #222; }

/* -- Tables -- */
.tbl-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tbl th {
  text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border);
  font-weight: 600; font-size: .72rem; color: var(--text-hint); text-transform: uppercase;
  letter-spacing: .02em; cursor: pointer; user-select: none; white-space: nowrap;
}
.tbl th.no-sort { cursor: default; }
.tbl th:hover:not(.no-sort) { background: #eef2f8; }
.tbl th .arrow { color: var(--accent-blue); margin-left: 3px; font-size: 9px; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.tbl tr:hover td { background: #fafbfc; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr.row-clickable { cursor: pointer; }
.tbl tr.row-selected td { background: #eef6ff; }
.tbl .muted { color: #bbb; }

/* -- Mobile stacked-card table (Pattern A) -- */
@media (max-width: 640px) {
  .tbl-stack thead { display: none; }
  .tbl-stack, .tbl-stack tbody, .tbl-stack tr, .tbl-stack td { display: block; width: 100%; }
  .tbl-stack tr {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 10px 12px; margin-bottom: 10px; background: #fff;
  }
  .tbl-stack tr:hover td { background: transparent; }
  .tbl-stack td {
    padding: 5px 0; border: none; font-size: .85rem;
    display: flex; gap: 8px; align-items: flex-start; text-align: left !important;
  }
  .tbl-stack td.num { justify-content: flex-start; }
  .tbl-stack td::before {
    content: attr(data-label); font-weight: 600; color: var(--text-secondary);
    font-size: .7rem; text-transform: uppercase; letter-spacing: .03em;
    flex: 0 0 108px;
  }
  .tbl-stack td:empty, .tbl-stack td[data-label=""] { display: none; }
}

/* -- Sessions scroll box (Profile page) -- */
.scroll-box { max-height: 400px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* -- Forms -- */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: .8rem; font-weight: 600; color: #444; margin-bottom: 5px; }
.form-row select, .form-row input[type="text"], .form-row input[type="email"] {
  width: 100%; border: 1px solid #d0d0d0; border-radius: 6px; padding: 10px 12px;
  font-size: 16px; color: #111; font-family: inherit; min-height: 44px; background: #fff;
}
.form-row select:focus, .form-row input:focus { outline: none; border-color: var(--accent-blue); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 20px; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 6px; }
.toggle-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.toggle-row input[type="checkbox"] { width: 20px; height: 20px; }

/* -- Modal (desktop centered, mobile bottom-sheet) -- */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3);
  z-index: 1000; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  position: relative; background: #fff; border-radius: 12px; padding: 24px;
  width: 100%; min-width: 280px; max-width: 420px; max-height: 80vh; overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15); margin: 16px;
}
.modal h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 16px; color: #111; display: flex; align-items: center; }
.modal h3 .close {
  margin-left: auto; background: none; border: none; font-size: 1.3rem; color: #888;
  cursor: pointer; min-width: 44px; min-height: 44px;
}
.modal p.hint { font-size: .8rem; color: var(--text-secondary); margin-bottom: 12px; }
.modal-msg { font-size: .78rem; margin-top: 6px; min-height: 16px; text-align: center; }
.modal-msg.ok { color: var(--green-up); } .modal-msg.err { color: var(--red-down); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

@media (max-width: 640px) {
  .modal-overlay { align-items: flex-end; }
  .modal {
    top: auto; bottom: 0; left: 0; right: 0; transform: none;
    max-width: 100vw; width: 100%; margin: 0; border-radius: 16px 16px 0 0; max-height: 70vh;
  }
  .form-grid { grid-template-columns: 1fr; }
}

/* -- Toast -- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff; padding: 10px 24px; border-radius: 20px;
  font-size: 0.9rem; z-index: 2000; opacity: 0; transition: opacity 0.3s; pointer-events: none;
  max-width: 90vw; text-align: center;
}
.toast.toast-visible { opacity: 1; }
.toast.ok { background: #1b7a43; }
.toast.err { background: #b3202f; }

/* -- Empty / zero-result states -- */
.empty-state { text-align: center; padding: 36px 20px; color: #999; }
.empty-state p { font-size: .88rem; margin-bottom: 10px; }

/* -- Pagination -- */
.pager { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 14px 0 4px; flex-wrap: wrap; }
.pager button {
  min-width: 36px; min-height: 36px; padding: 4px 10px; border: 1px solid #ccc; border-radius: 6px;
  background: #fff; color: #333; font-size: .82rem; cursor: pointer;
}
.pager button.active { background: var(--accent-blue); color: #fff; border-color: var(--accent-blue); font-weight: 600; }
.pager button:disabled { opacity: .4; cursor: not-allowed; }
.pager .pg-simple { display: none; }
@media (max-width: 640px) {
  .pager .pg-numbered { display: none; }
  .pager .pg-simple { display: flex; gap: 8px; align-items: center; }
}

/* -- Login page -- */
.login-wrap {
  min-height: calc(100vh - 88px); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 20px 0;
}
.brand-block { text-align: center; margin-bottom: 28px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px; border-radius: 16px; background: var(--accent-blue);
  color: #fff; font-size: 1.6rem; font-weight: 700; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.brand-title { font-size: 1.5rem; font-weight: 700; color: #111; }
.brand-subtitle { font-size: .85rem; color: var(--text-secondary); margin-top: 2px; }
.login-heading { font-size: .95rem; font-weight: 600; color: #333; margin-bottom: 20px; text-align: center; }

.provider-list { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 12px; padding: 0 16px; }
.provider-card {
  position: relative; display: flex; align-items: center; gap: 14px;
  min-width: 280px; min-height: 56px; width: 100%;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 18px; text-decoration: none; color: #222; font-size: .92rem; font-weight: 600;
  box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s;
}
.provider-card:hover { border-color: var(--accent-blue); box-shadow: 0 4px 14px rgba(26,95,175,.12); }
.provider-card.disabled { opacity: 0.5; pointer-events: none; }
.provider-card svg { flex-shrink: 0; }
.soon-badge {
  position: absolute; top: 10px; right: 12px;
  background: #f0f0f0; color: var(--text-hint); font-size: .68rem; font-weight: 600;
  padding: 2px 8px; border-radius: 10px;
}
.login-footer { text-align: center; font-size: .78rem; color: var(--text-hint); margin-top: 28px; max-width: 320px; padding: 0 16px; }

@media (max-width: 640px) {
  .brand-mark { width: 52px; height: 52px; font-size: 1.3rem; }
  .brand-title { font-size: 1.25rem; }
}

/* -- Profile card -- */
.profile-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.profile-head .who { flex: 1; min-width: 160px; }
.profile-name-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.profile-name { font-size: 1.15rem; font-weight: 700; color: #111; }
.profile-badges { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.profile-edit-btn {
  background: none; border: none; color: var(--accent-blue); font-size: .82rem; font-weight: 600;
  cursor: pointer; padding: 6px 4px; min-height: 44px;
}
.profile-edit-btn:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .avatar-lg { width: 48px; height: 48px; font-size: 1.05rem; }
}

/* -- Identity panel (admin) -- */
#identity-panel.hidden { display: none; }
.identity-panel-title { font-weight: 600; color: #111; }

/* -- Sign out -- */
.signout-row { text-align: center; margin-top: 8px; }
.signout-link {
  display: inline-block; color: var(--red-down); font-weight: 600; font-size: .88rem;
  text-decoration: none; padding: 10px 20px; min-height: 44px; line-height: 24px;
}
.signout-link:hover { text-decoration: underline; }
@media (max-width: 640px) {
  .signout-row { position: sticky; bottom: 0; background: var(--bg-page); padding: 8px 0; margin-top: 16px; }
  .signout-link { display: block; width: 100%; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
}

/* ============================================================
   Global Header -- user menu (top-right corner, all pages)
   Mirrors global-header.css (duplicated here because @import
   must be at top of file, which conflicts with the CSS reset
   pattern used by user-management pages).
   ============================================================ */
#global-header { position: fixed; top: 10px; right: 12px; z-index: 200; }

.gh-trigger {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 24px; padding: 4px 8px 4px 4px;
  box-shadow: var(--shadow); user-select: none;
}
.gh-trigger:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }

.gh-avatar-img {
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: block;
}
.gh-avatar-txt {
  width: 32px; height: 32px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 0.8rem;
  font-weight: 700; line-height: 1;
}
.gh-caret {
  width: 0; height: 0; border-left: 5px solid transparent;
  border-right: 5px solid transparent; border-top: 6px solid var(--text-hint);
}

.gh-dropdown {
  display: none; position: absolute; top: 44px; right: 0;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 180px; padding: 8px 0; z-index: 201;
}
.gh-dropdown.gh-open { display: block; }

.gh-drop-name {
  padding: 8px 16px 4px; font-weight: 600; font-size: 0.9rem;
  border-bottom: 1px solid var(--border); margin-bottom: 4px;
  display: flex; align-items: center; gap: 8px;
}
.gh-badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 0.7rem; font-weight: 600;
}
.gh-badge-admin { background: #fff8e6; color: #b8860b; }

.gh-drop-item {
  display: block; padding: 8px 16px; text-decoration: none;
  color: var(--text-primary); font-size: 0.88rem; min-height: 36px;
  line-height: 20px;
}
.gh-drop-item:hover { background: #f0f4ff; }


.denied-card {
  background: #fff; border: 1px solid #e0e0e0; border-radius: 8px;
  padding: 32px 24px; text-align: center; max-width: 480px; margin: 24px auto;
}
.denied-card h2 { color: #f23645; margin-bottom: 12px; }
.denied-card p { color: #555; margin-bottom: 8px; }
