/* ========== RESET & BASE ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f172a; --bg2: #1e293b; --bg3: #334155;
  --text: #f1f5f9; --text2: #94a3b8; --text3: #64748b;
  --primary: #6366f1; --primary-light: #818cf8;
  --success: #22c55e; --warning: #f59e0b; --danger: #ef4444;
  --border: #334155; --radius: 12px; --radius-sm: 8px;
}
body { font-family: 'Tajawal', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* ========== LOGIN ========== */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
}
.login-card {
  background: var(--bg2); padding: 40px; border-radius: 20px; width: 380px; max-width: 90vw;
  box-shadow: 0 25px 60px rgba(0,0,0,0.5); text-align: center;
  border: 1px solid var(--border);
}
.login-logo { font-size: 3rem; color: var(--primary); margin-bottom: 12px; }
.login-card h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { color: var(--text2); margin-bottom: 24px; font-size: 0.9rem; }
.login-error { background: rgba(239,68,68,0.15); color: var(--danger); padding: 10px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 0.85rem; }

/* ========== FORMS ========== */
.form-group { margin-bottom: 16px; text-align: right; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text2); margin-bottom: 6px; font-weight: 500; }
.form-group input, .form-group select {
  width: 100%; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-family: inherit; font-size: 0.95rem;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 10px 20px;
  border: none; border-radius: var(--radius-sm); font-family: inherit; font-size: 0.9rem;
  font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: #1e293b; }
.btn-outline { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--text2); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== TOP BAR ========== */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px; background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-icon { font-size: 1.3rem; color: var(--primary); }
.topbar-title { font-size: 1.1rem; font-weight: 700; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.admin-name { color: var(--text2); font-size: 0.85rem; }

/* ========== TAB NAV ========== */
.tab-nav {
  display: flex; gap: 4px; padding: 12px 24px 0; background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 10px 20px; background: transparent; border: none; color: var(--text3);
  font-family: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer;
  border-bottom: 3px solid transparent; transition: all 0.2s;
}
.tab:hover { color: var(--text2); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ========== CONTENT ========== */
.content { padding: 24px; max-width: 1400px; margin: 0 auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h2 { font-size: 1.2rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.loading { text-align: center; padding: 40px; color: var(--text3); font-size: 1rem; }

/* ========== TENANT GRID ========== */
.tenants-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 20px; }
.tenant-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; transition: transform 0.2s, box-shadow 0.2s;
}
.tenant-card:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(0,0,0,0.3); }
.tenant-card-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.tenant-name { font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.tenant-badge { font-size: 0.7rem; padding: 3px 8px; border-radius: 20px; font-weight: 600; }
.badge-pilot { background: rgba(99,102,241,0.2); color: var(--primary-light); }
.badge-healthy { background: rgba(34,197,94,0.2); color: var(--success); }
.badge-unhealthy { background: rgba(239,68,68,0.2); color: var(--danger); }
.badge-starting { background: rgba(245,158,11,0.2); color: var(--warning); }

.tenant-card-body { padding: 16px 20px; }
.tenant-info-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 0.85rem; }
.tenant-info-label { color: var(--text3); }
.tenant-info-value { color: var(--text); font-weight: 500; }

.modules-bar { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 10px; }
.module-chip {
  font-size: 0.7rem; padding: 3px 8px; border-radius: 12px; font-weight: 500;
  background: rgba(99,102,241,0.15); color: var(--primary-light);
}
.module-chip.off { background: rgba(100,116,139,0.15); color: var(--text3); text-decoration: line-through; }

.tenant-card-footer {
  display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* ========== DOMAINS LIST ========== */
.domain-list { display: flex; flex-direction: column; gap: 4px; }
.domain-link {
  color: var(--primary-light); text-decoration: none; font-size: 0.8rem;
  display: flex; align-items: center; gap: 4px;
}
.domain-link:hover { text-decoration: underline; }

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  width: 700px; max-width: 95vw; max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text3); font-size: 1.5rem; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }

/* Module toggles in modal */
.module-toggle-list { display: flex; flex-direction: column; gap: 8px; }
.module-toggle {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--bg); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.module-toggle-info { display: flex; align-items: center; gap: 10px; }
.module-toggle-name { font-weight: 600; font-size: 0.9rem; }

/* Toggle switch */
.switch { position: relative; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--bg3); border-radius: 24px;
  cursor: pointer; transition: 0.3s;
}
.switch .slider::before {
  content: ''; position: absolute; width: 18px; height: 18px; bottom: 3px; right: 3px;
  background: white; border-radius: 50%; transition: 0.3s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(-20px); }

/* ========== LOGS ========== */
.logs-container {
  background: #0d1117; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; max-height: 400px; overflow-y: auto; font-family: 'Fira Code', 'Courier New', monospace;
  font-size: 0.75rem; line-height: 1.6; direction: ltr; text-align: left;
}
.log-line { color: #c9d1d9; white-space: pre-wrap; word-break: break-all; }

/* ========== AUDIT TABLE ========== */
.audit-container { overflow-x: auto; }
.audit-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.audit-table th { text-align: right; padding: 10px 14px; background: var(--bg2); color: var(--text2); font-weight: 600; border-bottom: 1px solid var(--border); }
.audit-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
.audit-table tr:hover td { background: rgba(99,102,241,0.05); }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .tenants-grid { grid-template-columns: 1fr; }
  .tab-nav { overflow-x: auto; }
  .content { padding: 16px; }
  .modal { width: 100%; }
}

/* ========== SECTION HEADER in modal ========== */
.section-title {
  font-size: 0.9rem; font-weight: 700; color: var(--text2); margin: 20px 0 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.section-title:first-child { margin-top: 0; }

/* Action buttons row */
.action-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

/* Status dot */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.status-dot.green { background: var(--success); }
.status-dot.red { background: var(--danger); }
.status-dot.yellow { background: var(--warning); }
