:root {
  --bg: #06101a;
  --bg-2: #081524;
  --panel: rgba(15, 28, 44, 0.92);
  --panel-2: rgba(17, 35, 56, 0.96);
  --panel-3: rgba(9, 20, 33, 0.85);
  --line: rgba(255,255,255,0.08);
  --line-strong: rgba(110,231,255,0.18);
  --text: #eef6ff;
  --muted: #9db1c8;
  --accent: #6ee7ff;
  --accent-2: #4f8cff;
  --accent-3: #7c5cff;
  --success: #49d17d;
  --warn: #ffb347;
  --danger: #ff6b6b;
  --shadow-xl: 0 30px 80px rgba(0,0,0,0.35);
  --shadow-lg: 0 18px 45px rgba(0,0,0,0.28);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(79,140,255,0.16), transparent 30%),
    radial-gradient(circle at top right, rgba(110,231,255,0.12), transparent 25%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  font-family: var(--font);
}

button, input, select { font: inherit; }

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.app-shell {
  display: grid;
  grid-template-columns: 290px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: linear-gradient(180deg, rgba(7,16,27,0.98), rgba(7,17,29,0.94));
  border-right: 1px solid var(--line);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.015));
  box-shadow: var(--shadow-lg);
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--accent-3), var(--accent-2), var(--accent));
  color: #05101a;
  box-shadow: 0 10px 25px rgba(79,140,255,0.22);
}

.brand h1 { margin: 0; font-size: 18px; line-height: 1.1; }
.brand p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

.nav { display: grid; gap: 8px; }

.nav-item {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.18s ease, border-color 0.18s ease;
}

.nav-item:hover {
  transform: translateX(2px);
  background: rgba(255,255,255,0.04);
  border-color: var(--line);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(79,140,255,0.24), rgba(110,231,255,0.14));
  border-color: rgba(110,231,255,0.24);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.sidebar-footer { margin-top: auto; }

.footer-card {
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0.02));
}

.footer-card .label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.main {
  padding: 28px;
  display: grid;
  gap: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 4px 0 2px;
}

.topbar h2 { margin: 0; font-size: 30px; letter-spacing: -0.02em; }
.topbar p { margin: 8px 0 0; color: var(--muted); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions input {
  min-width: 250px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}

.topbar-actions input:focus,
.form-grid input:focus,
.form-grid select:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 4px rgba(110,231,255,0.08);
}

.topbar-actions button,
.quick-actions button,
.form-grid button {
  padding: 12px 16px;
  border: 1px solid rgba(110,231,255,0.22);
  border-radius: 12px;
  color: var(--text);
  background: linear-gradient(135deg, rgba(79,140,255,0.26), rgba(110,231,255,0.18));
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0,0,0,0.18);
  transition: transform 0.15s ease, opacity 0.18s ease;
}

.topbar-actions button:hover,
.quick-actions button:hover,
.form-grid button:hover {
  transform: translateY(-1px);
  opacity: 0.96;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.section { display: none; gap: 20px; }
.section.active { display: grid; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 16px;
}

.metric-card {
  position: relative;
  overflow: hidden;
  padding: 18px 18px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(19,42,67,0.95), rgba(9,22,36,0.95));
  box-shadow: var(--shadow-lg);
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-3), var(--accent-2), var(--accent));
  opacity: 0.9;
}

.metric-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.metric-card strong {
  display: block;
  font-size: 30px;
  letter-spacing: -0.03em;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
}

.panel {
  border-radius: var(--radius-xl);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(16,35,56,0.95), rgba(10,24,39,0.96));
  box-shadow: var(--shadow-xl);
  padding: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.panel-header h3 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.quick-actions,
.form-grid {
  display: grid;
  gap: 10px;
}

.form-grid input,
.form-grid select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-3);
  color: var(--text);
  outline: none;
}

.json-box {
  min-height: 240px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(0,0,0,0.18), rgba(255,255,255,0.015));
  color: #dff5ff;
  overflow: auto;
}

.small-box { min-height: 140px; }

.table-wrap {
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.12);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  vertical-align: top;
  padding: 12px 12px;
  border-bottom: 1px solid var(--line);
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(7,17,29,0.96);
  backdrop-filter: blur(8px);
}

td { font-size: 14px; }
td pre { margin: 0; font-size: 12px; color: #d9ebff; }
tbody tr:hover { background: rgba(255,255,255,0.03); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
  border: 1px solid transparent;
  font-weight: 600;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.85;
}

.badge.open,
.badge.active,
.badge.executed,
.badge.starter,
.badge.pro,
.badge.enterprise {
  background: rgba(73,209,125,0.12);
  color: #9cf0bb;
  border-color: rgba(73,209,125,0.22);
}

.badge.paid,
.badge.ok,
.badge.running {
  background: rgba(110,231,255,0.12);
  color: #9fefff;
  border-color: rgba(110,231,255,0.22);
}

.badge.blocked,
.badge.error,
.badge.degraded,
.badge.void,
.badge.admin_forbidden {
  background: rgba(255,107,107,0.12);
  color: #ffb3b3;
  border-color: rgba(255,107,107,0.22);
}

.badge.invalid_tenant,
.badge.inactive_tenant {
  background: rgba(255,179,71,0.12);
  color: #ffd194;
  border-color: rgba(255,179,71,0.22);
}

#loadingOverlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 18, 0.55);
  backdrop-filter: blur(4px);
  z-index: 9998;
  display: none;
  align-items: center;
  justify-content: center;
}

#loadingOverlay.active {
  display: flex;
}

.loading-card {
  min-width: 260px;
  padding: 22px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(16,35,56,0.98), rgba(10,24,39,0.98));
  box-shadow: var(--shadow-xl);
  display: grid;
  gap: 12px;
  justify-items: center;
}

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 4px solid rgba(255,255,255,0.12);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

#loadingText {
  color: var(--text);
  font-weight: 600;
}

#toastRoot {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 9999;
  display: grid;
  gap: 10px;
}

.toast {
  min-width: 260px;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  background: linear-gradient(180deg, rgba(16,35,56,0.98), rgba(10,24,39,0.98));
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.success {
  border-color: rgba(73,209,125,0.35);
}

.toast.error {
  border-color: rgba(255,107,107,0.35);
}

.toast.info {
  border-color: rgba(110,231,255,0.35);
}

.toast.hide {
  opacity: 0;
  transform: translateY(-6px);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.14);
  border-radius: 999px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 1320px) {
  .metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    height: auto;
    position: relative;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .main { padding: 18px; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { flex-direction: column; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  .topbar-actions input { min-width: 100%; }
}

@media (max-width: 640px) {
  .metrics-grid { grid-template-columns: 1fr; }
  #toastRoot {
    left: 14px;
    right: 14px;
    top: 14px;
  }
  .toast {
    min-width: 0;
    max-width: none;
  }
}

.confirm-modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 18, 0.62);
  backdrop-filter: blur(5px);
  z-index: 9997;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.confirm-modal.active {
  display: flex;
}

.confirm-card {
  width: min(520px, 100%);
  padding: 22px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(16,35,56,0.98), rgba(10,24,39,0.98));
  box-shadow: var(--shadow-xl);
  display: grid;
  gap: 12px;
}

.confirm-card h3 {
  margin: 0;
  font-size: 20px;
}

.confirm-card p {
  margin: 0;
  color: var(--muted);
}

.confirm-details {
  min-height: 80px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.18);
  color: #dff5ff;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-actions button {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(110,231,255,0.22);
  color: var(--text);
  background: linear-gradient(135deg, rgba(79,140,255,0.26), rgba(110,231,255,0.18));
  cursor: pointer;
}

.confirm-actions button:hover {
  transform: translateY(-1px);
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.meta-pill {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size: 12px;
}

.meta-select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-3);
  color: var(--text);
  outline: none;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 18, 0.62);
  backdrop-filter: blur(5px);
  z-index: 9997;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.confirm-modal.active {
  display: flex;
}

.confirm-card {
  width: min(520px, 100%);
  padding: 22px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(16,35,56,0.98), rgba(10,24,39,0.98));
  box-shadow: var(--shadow-xl);
  display: grid;
  gap: 12px;
}

.confirm-card h3 {
  margin: 0;
  font-size: 20px;
}

.confirm-card p {
  margin: 0;
  color: var(--muted);
}

.confirm-details {
  min-height: 80px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.18);
  color: #dff5ff;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-actions button {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(110,231,255,0.22);
  color: var(--text);
  background: linear-gradient(135deg, rgba(79,140,255,0.26), rgba(110,231,255,0.18));
  cursor: pointer;
}

.confirm-actions button:hover {
  transform: translateY(-1px);
}
