:root {
  --bg: #090d16;
  --surface: #111827;
  --surface-2: #161f32;
  --border: #1f2a40;
  --border-hover: #334566;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; min-height: 100vh; }
a { color: inherit; }
.hidden { display: none !important; }

/* Auth Gate */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, rgba(99, 102, 241, 0.16), transparent 55%), var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 30px;
  text-align: center;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.55);
}
.auth-logo {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.04em;
  color: #fff;
  margin-bottom: 16px;
}
.auth-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}
.auth-card h1 { margin: 0 0 10px; font-size: 24px; }
.auth-card p { margin: 0 0 24px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.auth-foot { margin-top: 18px; font-size: 12px; color: #64748b; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--border-hover); background: #1c2840; }
.btn-danger { background: rgba(239, 68, 68, 0.14); color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn-block { width: 100%; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(9, 13, 22, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}
.brand-title { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.domain-pill { font-size: 11px; font-weight: 600; color: #a5b4fc; background: rgba(99, 102, 241, 0.15); padding: 2px 8px; border-radius: 999px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
}
.user-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.logout-link { color: #fca5a5; text-decoration: none; font-weight: 600; margin-left: 4px; }
.logout-link:hover { text-decoration: underline; }

/* Container */
.container { max-width: 1320px; margin: 0 auto; padding: 22px 24px 60px; }

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 800; }
.kpi-good .kpi-value { color: #34d399; }
.kpi-warn .kpi-value { color: #fbbf24; }
.kpi-bad .kpi-value { color: #f87171; }
.kpi-accent .kpi-value { color: #a5b4fc; }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.search-wrap { flex: 1; min-width: 240px; max-width: 420px; }
.search-wrap input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  outline: none;
}
.search-wrap input:focus { border-color: var(--primary); }
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.pill.active, .pill:hover { color: #fff; border-color: var(--primary); background: rgba(99, 102, 241, 0.2); }

/* Sub-Apps Grid */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.app-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s ease, transform 0.15s ease;
  overflow: hidden;
}
.app-card:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.app-accent { position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.app-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.app-title-wrap { display: flex; align-items: center; gap: 12px; min-width: 0; }
.app-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.app-name { font-size: 16px; font-weight: 700; margin: 0 0 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.app-meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11px;
  color: #cbd5e1;
}

/* Status Pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  flex-shrink: 0;
}
.status-online { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.status-degraded { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.status-offline { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.status-maintenance, .status-draft, .status-unknown { background: rgba(148, 163, 184, 0.14); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.25); }

.app-desc { margin: 0; font-size: 13px; color: #cbd5e1; line-height: 1.5; }
.app-url-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px;
}
.app-url-link {
  font-size: 12px;
  color: #93c5fd;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-url-link:hover { text-decoration: underline; }

/* Metrics */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.metric-chip {
  background: #0d1322;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
}
.metric-label { font-size: 11px; color: var(--muted); }
.metric-val { font-size: 14px; font-weight: 700; margin-top: 2px; }
.metric-good .metric-val { color: #34d399; }
.metric-warn .metric-val { color: #fbbf24; }
.metric-bad .metric-val { color: #f87171; }

.app-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.app-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.probe-info { font-size: 11px; color: #64748b; }

/* Activity Panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
}
.panel-head h2 { margin: 0 0 12px; font-size: 15px; }
.activity-list { display: flex; flex-direction: column; gap: 8px; }
.activity-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 9px;
  flex-wrap: wrap;
}
.activity-msg { color: #e2e8f0; }
.activity-time { color: #64748b; font-size: 11px; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(3, 6, 14, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  width: 100%;
  max-width: 620px;
  max-height: 92vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.65);
}
.modal-xl { max-width: 1240px; height: 88vh; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}
.icon-btn:hover { color: #fff; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--border);
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { border-color: var(--primary); }
.check-row { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--text) !important; cursor: pointer; }

.api-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.api-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.api-key-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.code-block {
  background: #070b13;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 12px;
  overflow-x: auto;
  color: #cbd5e1;
  margin: 0 0 10px;
}

.iframe-head-left { display: flex; align-items: center; gap: 12px; }
.iframe-wrap { flex: 1; background: #fff; }
.iframe-wrap iframe { width: 100%; height: 100%; border: 0; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 90;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid var(--primary);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
}
.muted { color: var(--muted); font-size: 13px; line-height: 1.5; margin-top: 0; }

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .topbar { padding: 12px 14px; }
  .container { padding: 16px 14px 48px; }
  .apps-grid { grid-template-columns: 1fr; }
}
