/* ===== ADMIN HUB PAGE ===== */

.ah-page {
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────── */
.ah-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ah-header-center { flex: 1; display: flex; justify-content: center; }
.ah-header-title  { display: flex; align-items: center; gap: 10px; }
.ah-page-title    { font-size: 1rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.ah-page-sub      { font-size: 0.72rem; color: var(--text-muted); }
.ah-header-right  { display: flex; align-items: center; gap: 8px; }

/* ── Tab bar ─────────────────────────────────────────────── */
.ah-tabs {
  display: flex;
  gap: 2px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ah-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 12px 18px;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.ah-tab:hover { color: var(--text-primary); }
.ah-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.ah-tab-count {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--border-soft);
  color: var(--text-muted);
}
.ah-tab.active .ah-tab-count {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ── Main content area ───────────────────────────────────── */
.ah-main {
  flex: 1;
  padding: 28px 24px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

.ah-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.ah-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 2px;
}
.ah-section-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
}

/* ── State: loading / empty / error ─────────────────────── */
.ah-state {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.ah-state-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 14px;
  opacity: 0.35;
}
.ah-state-title { font-weight: 700; color: var(--text-secondary); margin-bottom: 6px; }
.ah-error-banner {
  background: rgba(239,68,68,0.08);
  border: 1.5px solid rgba(239,68,68,0.2);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.82rem;
  color: #dc2626;
  margin-bottom: 16px;
}
[data-theme="dark"] .ah-error-banner { background: rgba(239,68,68,0.12); color: #f87171; border-color: rgba(239,68,68,0.3); }

/* ── Analytics cards ─────────────────────────────────────── */
.ah-analytics-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ah-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.ah-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }

.ah-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.ah-card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.ah-card-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}
.ah-card-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 5px 0 6px;
}
.ah-card-route {
  display: inline-block;
  font-size: 0.75rem;
  font-family: 'Courier New', monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 7px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.ah-card-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
}
.ah-tag-divider {
  color: var(--border);
  font-size: 0.75rem;
  margin: 0 2px;
}
.ah-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Version + type badges */
.ah-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}
.ah-badge--version {
  background: var(--border-soft);
  color: var(--text-muted);
}
.ah-badge--type {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* Category + data source chips */
.ah-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}
.ah-chip--cat {
  background: rgba(99,102,241,0.1);
  color: #6366f1;
}
.ah-chip--src {
  background: rgba(245,158,11,0.1);
  color: #d97706;
}
[data-theme="dark"] .ah-chip--cat { background: rgba(99,102,241,0.18); color: #a5b4fc; }
[data-theme="dark"] .ah-chip--src { background: rgba(245,158,11,0.18); color: #fbbf24; }

/* Delete button variant */
.ah-del { color: var(--text-muted); }
.ah-del:hover:not(:disabled) {
  color: #dc2626; border-color: #fca5a5; background: #fee2e2;
}
[data-theme="dark"] .ah-del:hover:not(:disabled) {
  color: #f87171; border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.12);
}

/* ── Categories / Data Sources list ─────────────────────── */
.ah-tag-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.ah-tag-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
  transition: background 0.1s;
}
.ah-tag-row:last-child { border-bottom: none; }
.ah-tag-row:hover { background: var(--bg); }
.ah-tag-info { flex: 1; min-width: 0; }
.ah-tag-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}
.ah-tag-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1px;
}
.ah-tag-actions { display: flex; gap: 5px; flex-shrink: 0; }

/* Inline edit row */
.ah-tag-row--editing { background: var(--bg); align-items: flex-start; padding: 10px 16px; }
.ah-tag-edit-form { flex: 1; display: flex; flex-direction: column; gap: 6px; }

/* Add new form */
.ah-add-form {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}
.ah-add-form.hidden { display: none; }
.ah-add-form-fields { display: flex; flex-direction: column; gap: 8px; }
.ah-add-form-actions { display: flex; gap: 7px; margin-top: 10px; }

/* ── Drawer ──────────────────────────────────────────────── */
.ah-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
}
.ah-drawer-overlay.hidden { display: none; }

.ah-drawer-panel {
  width: min(560px, 95vw);
  height: 100%;
  background: var(--surface);
  border-left: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ah-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ah-drawer-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.ah-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ah-drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Form components ─────────────────────────────────────── */
.ah-form-group { display: flex; flex-direction: column; gap: 5px; }
.ah-form-row { display: flex; gap: 12px; }
.ah-form-row > .ah-form-group { flex: 1; }

.ah-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}
.ah-label-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.68rem;
}
.ah-req { color: var(--primary); }

.ah-input {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-size: 0.85rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ah-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14,165,233,0.1);
}
.ah-input--sm { padding: 6px 10px; font-size: 0.82rem; border-radius: 7px; }
.ah-textarea { resize: vertical; min-height: 60px; }
.ah-code { font-family: 'Courier New', monospace; font-size: 0.78rem; line-height: 1.5; }

.ah-form-error {
  font-size: 0.78rem;
  color: #dc2626;
  background: rgba(239,68,68,0.08);
  border: 1.5px solid rgba(239,68,68,0.2);
  border-radius: 7px;
  padding: 8px 12px;
}
[data-theme="dark"] .ah-form-error { background: rgba(239,68,68,0.12); color: #f87171; border-color: rgba(239,68,68,0.3); }

/* Checkbox group */
.ah-check-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
  padding: 6px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
}
.ah-check-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-secondary);
  transition: background 0.1s;
}
.ah-check-item:hover { background: var(--surface); }
.ah-check-item input[type=checkbox] { accent-color: var(--primary); flex-shrink: 0; }
.ah-check-empty {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 4px 6px;
}

/* ── Tab hidden state ───────────────────────────────────────── */
.ah-tab.hidden { display: none; }

/* ── Table (Users / Orgs tabs) ───────────────────────────────── */
.ah-main { max-width: 1100px; }   /* wider to accommodate org table */

.ah-list-wrap {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.ah-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.ah-table thead tr {
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
}

.ah-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.ah-th-actions { width: 80px; }

.ah-td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.ah-table tbody tr:last-child td { border-bottom: none; }
.ah-td--secondary { color: var(--text-muted); font-size: 0.83rem; }
.ah-td--actions   { text-align: right; white-space: nowrap; }

.ah-row-self td { background: rgba(14,165,233,0.04); }

.ah-row-name { font-weight: 600; }
.ah-you {
  font-size: 0.68rem;
  color: var(--accent, #0ea5e9);
  font-weight: 600;
  margin-left: 5px;
  background: rgba(14,165,233,0.1);
  border-radius: 4px;
  padding: 1px 5px;
}

.ah-id-chip {
  font-size: 0.78rem;
  font-family: ui-monospace, 'Cascadia Code', Menlo, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  color: var(--text-muted);
}

/* Icon action buttons */
.ah-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: none;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  margin-left: 4px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.ah-action-btn:hover { background: var(--border-soft); color: var(--text-primary); }
.ah-action-btn--danger:hover {
  background: rgba(239,68,68,0.08);
  color: #ef4444;
  border-color: rgba(239,68,68,0.3);
}

/* Role + SU badges */
.ah-badge--admin   { background: rgba(139,92,246,0.12); color: #8b5cf6; }
.ah-badge--manager { background: rgba(14,165,233,0.12);  color: #0ea5e9; }
.ah-badge--user    { background: rgba(100,116,139,0.12); color: #64748b; }
.ah-badge--su      { background: rgba(239,68,68,0.1);    color: #ef4444; font-size: 0.65rem; margin-left: 4px; }

/* ── Password field in user drawer ──────────────────────────── */
.ah-pw-wrap { position: relative; }
.ah-pw-wrap .ah-input { padding-right: 38px; }
.ah-pw-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
}
.ah-pw-toggle:hover { color: var(--text-primary); }

/* ── Section divider in drawer ───────────────────────────────── */
.ah-form-section {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding-top: 6px;
  border-top: 1px solid var(--border-soft);
  margin-top: 2px;
}

/* ── Field hint text ─────────────────────────────────────────── */
.ah-field-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Org access checklist in user drawer ─────────────────────── */
.ah-org-checklist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
.ah-org-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}
.ah-org-check-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}
.ah-org-check-row input[type="checkbox"]:disabled {
  opacity: 0.5;
  cursor: default;
}
.ah-org-check-row:has(input:disabled) { opacity: 0.7; }

/* ── Default Dashboards tab ──────────────────────────────────── */
.ah-dd-cards { display: flex; flex-direction: column; gap: 16px; }
.ah-dd-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
}
.ah-dd-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.ah-dd-name-input { flex: 1; font-weight: 600; }
.ah-dd-card-btns  { display: flex; gap: 6px; flex-shrink: 0; }
.ah-dd-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.ah-dd-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
}
.ah-dd-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 8px 12px;
}
.ah-dd-reorder { display: flex; flex-direction: column; gap: 2px; }
.ah-dd-move    { padding: 2px 5px; font-size: 0.72rem; line-height: 1; min-width: 22px; }
.ah-dd-move:disabled { opacity: 0.25; cursor: default; }
.ah-dd-info    { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.ah-dd-name    { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ah-dd-remove  { font-size: 0.75rem; padding: 4px 7px; color: var(--text-muted); }
.ah-dd-remove:hover { color: #dc2626; }
.ah-dd-del-btn:hover { color: #dc2626; }
.ah-dd-add     { display: flex; gap: 8px; align-items: center; }
.ah-dd-add-select { flex: 1; }

/* Responsive */
@media (max-width: 640px) {
  .ah-header { padding: 0 16px; }
  .ah-header-center { display: none; }
  .ah-main { padding: 16px; }
  .ah-tabs { padding: 0 16px; gap: 0; }
  .ah-tab { padding: 10px 12px; font-size: 0.78rem; }
  .ah-form-row { flex-direction: column; }
  .ah-card-top { flex-direction: column; }
  .ah-card-actions { align-self: flex-end; }
}
