/* Tenant Management dashboard — scoped to #tenants-root */
body.adm-authed:has(#page-tenants.active) .fl-topbar { display: none; }
body.adm-authed:has(#page-tenants.active) #fl-pages.fl-pad { padding: 0; gap: 0; }

#page-tenants { padding: 0 !important; gap: 0 !important; }
#page-tenants.active { display: block !important; }

.tm-dashboard {
  --bg-base: #0b0f19;
  --bg-card: #111827;
  --bg-card-hover: #1a2235;
  --bg-input: #1f2937;
  --border: #1f2937;
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #4b5563;
  --accent-red: #e53935;
  --accent-green: #22c55e;
  --accent-blue: #3b82f6;
  --accent-purple: #a855f7;
  --accent-orange: #f97316;
  --accent-amber: #f59e0b;
  --danger: #ef4444;

  font-family: 'DM Sans', var(--font-sans), system-ui, sans-serif;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-base);
  min-height: calc(100vh - 48px);
  padding: 20px 24px;
  box-sizing: border-box;
  overflow-x: hidden;
}

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

.tm-mono { font-family: 'JetBrains Mono', var(--font-mono), monospace; }

@keyframes tmFadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes tmLivePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* Header */
.tm-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20px;
  animation: tmFadeUp 0.35s ease;
}
.tm-header-left h1 {
  margin: 0;
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  font-size: 22px;
  color: var(--text-primary);
}
.tm-header-left p {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}
.tm-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.tm-btn-new {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  background: #e53935;
  color: #fff;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.tm-btn-new:hover { background: #c62828; }

.tm-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 220px;
  padding: 8px 14px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
}
.tm-search input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: #fff;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
}
.tm-search input::placeholder { color: #4b5563; }
.tm-search-kbd {
  padding: 2px 6px;
  background: #374151;
  border-radius: 4px;
  font-size: 12px;
  color: #4b5563;
  flex-shrink: 0;
}

.tm-icon-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  color: #9ca3af;
}
.tm-icon-btn:hover { background: #374151; }

.tm-notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e53935;
  border-radius: 50%;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 10px;
  color: #fff;
}

.tm-admin-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  cursor: pointer;
}
.tm-admin-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #e53935;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  flex-shrink: 0;
}
.tm-admin-text { line-height: 1.2; }
.tm-admin-name { font-weight: 600; font-size: 13px; color: #fff; }
.tm-admin-role { font-size: 11px; color: #9ca3af; }

/* Metric cards */
.tm-metrics {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}
.tm-metric-card {
  flex: 1;
  min-width: 0;
  padding: 18px 20px;
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 12px;
  transition: box-shadow 0.2s, transform 0.2s;
  animation: tmFadeUp 0.35s ease backwards;
}
.tm-metric-card:hover {
  box-shadow: 0 0 0 1px rgba(229, 57, 53, 0.2);
  transform: translateY(-1px);
}
.tm-metric-top {
  display: flex;
  align-items: flex-start;
}
.tm-metric-icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 14px;
}
.tm-metric-body { flex: 1; min-width: 0; }
.tm-metric-label {
  font-size: 12px;
  color: #9ca3af;
  margin-bottom: 4px;
}
.tm-metric-value {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 24px;
  color: var(--text-primary);
  line-height: 1.1;
}
.tm-metric-trend {
  margin-top: 6px;
  font-size: 12px;
}
.tm-trend-up { color: #22c55e; }
.tm-trend-muted { color: #9ca3af; }

/* Storage capacity */
.tm-storage-card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  animation: tmFadeUp 0.35s ease 0.1s backwards;
}
.tm-storage-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}
.tm-storage-head h2 {
  margin: 0;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}
.tm-storage-head p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #9ca3af;
}
.tm-period-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 6px;
  font-weight: 500;
  font-size: 12px;
  color: #9ca3af;
  cursor: pointer;
}
.tm-storage-body {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 40px;
  align-items: center;
}
.tm-storage-bar-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.tm-storage-bar-label { font-weight: 600; font-size: 16px; }
.tm-storage-bar-pct { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 20px; }
.tm-progress {
  display: flex;
  height: 10px;
  border-radius: 6px;
  background: #1f2937;
  overflow: hidden;
  margin: 12px 0;
}
.tm-progress-seg { height: 100%; flex-shrink: 0; }
.tm-storage-bar-bottom {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #9ca3af;
}
.tm-refresh-icon {
  display: inline-block;
  transition: transform 0.5s;
}
.tm-refresh-wrap:hover .tm-refresh-icon { transform: rotate(180deg); }

.tm-donut-wrap {
  display: flex;
  align-items: center;
  gap: 24px;
}
.tm-donut-canvas { width: 140px; height: 140px; flex-shrink: 0; }
.tm-legend { display: flex; flex-direction: column; gap: 10px; }
.tm-legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 200px;
}
.tm-legend-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #9ca3af;
}
.tm-legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.tm-legend-right {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.tm-legend-val {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
}
.tm-legend-pct { font-size: 12px; color: #9ca3af; }

/* Table card */
.tm-table-card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 12px;
  overflow: hidden;
  animation: tmFadeUp 0.35s ease 0.15s backwards;
}
.tm-table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid #1f2937;
}
.tm-table-head h2 {
  margin: 0;
  font-weight: 700;
  font-size: 16px;
}
.tm-table-head p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #9ca3af;
}
.tm-table-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tm-filter-wrap { position: relative; }
.tm-filter-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 140px;
  padding: 8px 14px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  font-weight: 500;
  font-size: 13px;
  color: #9ca3af;
  cursor: pointer;
}
.tm-filter-drop {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 100;
  min-width: 160px;
  padding: 6px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.tm-filter-drop.open { display: block; }
.tm-filter-opt {
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13px;
  color: #9ca3af;
  cursor: pointer;
}
.tm-filter-opt:hover, .tm-filter-opt.active { background: #374151; color: #fff; }

.tm-export-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: transparent;
  border: 1px solid #374151;
  border-radius: 8px;
  font-weight: 500;
  font-size: 13px;
  color: #9ca3af;
  cursor: pointer;
  transition: background 0.15s;
}
.tm-export-btn:hover { background: #1f2937; }

.tm-table-wrap { overflow-x: auto; }
.tm-table {
  width: 100%;
  border-collapse: collapse;
}
.tm-table thead th {
  padding: 12px 16px;
  background: #0d1117;
  border-bottom: 1px solid #1f2937;
  font-weight: 500;
  font-size: 11px;
  color: #4b5563;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  white-space: nowrap;
}
.tm-table thead th:first-child { padding-left: 24px; }
.tm-table thead th:last-child { padding-right: 24px; }
.tm-table thead th.tm-sortable { cursor: pointer; user-select: none; }
.tm-table thead th.tm-sortable:hover { color: #9ca3af; }
.tm-sort-icon { margin-left: 4px; vertical-align: middle; opacity: 0.7; }

.tm-table tbody td {
  padding: 16px;
  border-bottom: 1px solid #1f2937;
  vertical-align: middle;
}
.tm-table tbody td:first-child { padding-left: 24px; }
.tm-table tbody td:last-child { padding-right: 24px; }
.tm-table tbody tr { transition: background 0.15s; }
.tm-table tbody tr:hover { background: #1a2235; }

.tm-row-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: #4b5563;
}
.tm-tenant-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}
.tm-tenant-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}
.tm-tenant-name { font-weight: 600; font-size: 14px; }
.tm-tenant-domain { margin-top: 2px; font-size: 12px; color: #4b5563; }

.tm-plan-badge {
  display: inline-flex;
  padding: 3px 12px;
  border-radius: 999px;
  font-weight: 500;
  font-size: 12px;
  border: 1px solid;
}
.tm-plan-enterprise { border-color: #3b82f6; color: #3b82f6; background: #3b82f610; }
.tm-plan-business { border-color: #22c55e; color: #22c55e; background: #22c55e10; }
.tm-plan-starter { border-color: #f59e0b; color: #f59e0b; background: #f59e0b10; }
.tm-plan-unlimited { border-color: #a855f7; color: #a855f7; background: #a855f710; }

.tm-row-superadmin { background: rgba(99, 102, 241, 0.04); }
.tm-row-superadmin:hover { background: rgba(99, 102, 241, 0.08) !important; }
.tm-sa-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #a855f7;
  background: #a855f715;
  border: 1px solid #a855f730;
  vertical-align: middle;
}

.tm-storage-cell-top {
  font-size: 13px;
  color: var(--text-primary);
}
.tm-storage-cell-pct {
  margin-left: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-secondary);
}
.tm-storage-bar {
  height: 4px;
  width: 140px;
  margin-top: 6px;
  border-radius: 2px;
  background: #1f2937;
  overflow: hidden;
}
.tm-storage-bar-fill { height: 100%; border-radius: 2px; }

.tm-cell-num {
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 14px;
}

.tm-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 500;
  font-size: 12px;
  border: 1px solid;
  white-space: nowrap;
}
.tm-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tm-status-active { background: #22c55e15; color: #22c55e; border-color: #22c55e30; }
.tm-status-active .tm-status-dot { background: #22c55e; animation: tmLivePulse 2s ease infinite; }
.tm-status-over_quota { background: #ef444415; color: #ef4444; border-color: #ef444430; }
.tm-status-over_quota .tm-status-dot { background: #ef4444; }
.tm-status-inactive { background: #6b728015; color: #6b7280; border-color: #6b728030; }
.tm-status-inactive .tm-status-dot { background: #6b7280; }

.tm-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tm-action-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: transparent;
  border: 1px solid #374151;
  color: #9ca3af;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.tm-action-btn:hover { background: #1f2937; border-color: #4b5563; }
.tm-action-btn.tm-action-delete {
  border-color: #ef444430;
  color: #ef4444;
}
.tm-action-btn.tm-action-delete:hover {
  background: #ef444415;
  border-color: #ef4444;
}

.tm-more-wrap { position: relative; }
.tm-more-menu-src { display: none !important; }

.tm-more-float {
  position: fixed;
  z-index: 10000;
  min-width: 200px;
  padding: 6px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
  animation: tmMenuIn 0.15s ease;
}
@keyframes tmMenuIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.tm-more-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 100;
  width: 180px;
  padding: 6px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.tm-more-menu.open { display: block; }
.tm-more-float .tm-more-item,
.tm-more-menu .tm-more-item {
  padding: 10px 14px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13px;
  color: #d1d5db;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background 0.12s, color 0.12s;
}
.tm-more-float .tm-more-item:hover,
.tm-more-menu .tm-more-item:hover { background: #374151; color: #fff; }
.tm-more-float .tm-more-item.danger,
.tm-more-menu .tm-more-item.danger { color: #ef4444; }
.tm-more-float .tm-more-item.danger:hover,
.tm-more-menu .tm-more-item.danger:hover { background: #ef444415; color: #ef4444; }
.tm-more-float .tm-more-sep,
.tm-more-menu .tm-more-sep { height: 1px; background: #374151; margin: 4px 0; }

.tm-empty-state {
  text-align: center;
  padding: 48px 24px;
}
.tm-empty-state svg { margin-bottom: 12px; }
.tm-empty-title { font-weight: 500; font-size: 14px; color: #4b5563; margin: 0 0 4px; }
.tm-empty-sub { font-size: 12px; color: #4b5563; margin: 0; }

/* Pagination */
.tm-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-top: 1px solid #1f2937;
}
.tm-pagination-info { font-size: 13px; color: #9ca3af; }
.tm-pagination-btns { display: flex; gap: 6px; }
.tm-page-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid #374151;
  background: transparent;
  font-weight: 600;
  font-size: 13px;
  color: #9ca3af;
  cursor: pointer;
  transition: background 0.15s;
}
.tm-page-btn:hover:not(:disabled):not(.active) { background: #1f2937; }
.tm-page-btn.active {
  background: #e53935;
  border-color: #e53935;
  color: #fff;
}
.tm-page-btn:disabled { opacity: 0.4; cursor: default; }

/* Modals */
.tm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
}
.tm-overlay.open { display: flex; }
.tm-modal {
  position: relative;
  width: 480px;
  max-width: 90vw;
  padding: 32px;
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  animation: tmFadeUp 0.3s ease;
}
.tm-modal.tm-modal-sm { width: 400px; }
.tm-modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px;
}
.tm-modal-close:hover { color: #fff; }
.tm-modal h2 {
  margin: 0;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
}
.tm-modal-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: #9ca3af;
}
.tm-form { display: flex; flex-direction: column; gap: 16px; margin-top: 20px; }
.tm-field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 12px;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tm-field input, .tm-field select {
  width: 100%;
  padding: 10px 14px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  outline: none;
}
.tm-field input:focus, .tm-field select:focus {
  border-color: #e53935;
  box-shadow: 0 0 0 3px rgba(229,57,53,0.15);
}
.tm-field-hint { margin-top: 4px; font-size: 11px; color: #4b5563; }
.tm-field-error { font-size: 12px; color: #ef4444; margin-top: 4px; }
.tm-modal-footer {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}
.tm-btn-secondary {
  flex: 1;
  padding: 11px;
  background: transparent;
  border: 1px solid #374151;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  color: #9ca3af;
  cursor: pointer;
  transition: background 0.15s;
}
.tm-btn-secondary:hover { background: #1f2937; }
.tm-btn-primary {
  flex: 1;
  padding: 11px;
  background: #e53935;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}
.tm-btn-primary:hover { background: #c62828; }
.tm-btn-danger {
  flex: 1;
  padding: 11px;
  background: #ef4444;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  cursor: pointer;
}
.tm-btn-danger:hover { background: #dc2626; }

.tm-delete-icon { text-align: center; margin-bottom: 12px; }
.tm-delete-body { text-align: center; font-size: 13px; color: #9ca3af; line-height: 1.6; margin: 12px 0 0; }
.tm-warning-box {
  margin-top: 12px;
  padding: 12px 16px;
  background: #ef444410;
  border: 1px solid #ef444430;
  border-radius: 8px;
  font-weight: 500;
  font-size: 12px;
  color: #ef4444;
}

/* Toast */
.tm-toast-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.tm-toast {
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: tmFadeUp 0.25s ease;
  pointer-events: auto;
}
.tm-toast-success { background: #111827; border: 1px solid #22c55e40; color: #22c55e; }
.tm-toast-error { background: #111827; border: 1px solid #ef444440; color: #ef4444; }

@media (max-width: 1400px) {
  .tm-metrics { flex-wrap: wrap; }
  .tm-metric-card { flex: 1 1 calc(33.333% - 8px); min-width: 180px; }
}
@media (max-width: 1100px) {
  .tm-storage-body { grid-template-columns: 1fr; }
  .tm-header { flex-direction: column; align-items: flex-start; gap: 16px; }
  .tm-header-right { flex-wrap: wrap; width: 100%; }
}
