:root {
  --bg-base: #080c14;
  --bg-gradient: radial-gradient(ellipse at 20% 0%, #111d33 0%, #080c14 70%);
  --sidebar-bg: #0b111c;
  --card-bg: #0e1726;
  --card-hover: #121e32;
  --panel-bg: #0e1624;
  --input-bg: #070d17;
  
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);
  
  --text-main: #f1f5f9;
  --text-muted: #8496ad;
  --text-dim: #55677d;
  
  --accent: #00d2ff;
  --accent-hover: #38e1ff;
  --accent-glow: rgba(0, 210, 255, 0.25);
  --accent-bg: rgba(0, 210, 255, 0.1);
  
  --emerald: #10b981;
  --emerald-bg: rgba(16, 185, 129, 0.12);
  --rose: #f43f5e;
  --rose-bg: rgba(244, 63, 94, 0.12);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.12);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow: 0 12px 36px -8px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg-base);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ======================================================== AUTH SCREENS */

.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--card-bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.9), 0 0 40px rgba(0, 210, 255, 0.05);
  animation: fadeIn 0.3s ease-out;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(0, 210, 255, 0.2), rgba(0, 210, 255, 0.05));
  border: 1px solid rgba(0, 210, 255, 0.3);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px var(--accent-glow);
}

.badge-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--accent);
  margin-bottom: 2px;
}

.auth-card h1 {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
}

.auth-card p.muted {
  margin-bottom: 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-icon svg {
  position: absolute;
  left: 14px;
  color: var(--text-dim);
  pointer-events: none;
  transition: color 0.2s;
}

.input-with-icon input {
  padding-left: 42px;
}

.input-with-icon input:focus + svg,
.input-with-icon input:focus ~ svg {
  color: var(--accent);
}

.auth-footer {
  margin-top: 24px;
  text-align: center;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: color 0.2s;
}

.link-btn:hover {
  color: var(--accent);
}

/* ======================================================== NOT ADMIN SCREEN */

.notadmin-card {
  max-width: 560px;
}

.warning-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--rose);
  background: var(--rose-bg);
  border: 1px solid rgba(244, 63, 94, 0.3);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.code-pill {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--accent);
}

pre {
  background: #05080e;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  color: #7dd3fc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  margin: 16px 0 20px;
  overflow-x: auto;
}

/* ======================================================== DASHBOARD SHELL */

.dashboard-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* ----------------- SIDEBAR ----------------- */

.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-brand {
  padding: 24px 20px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.brand-details {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
}

.sidebar-menu {
  flex: 1;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.menu-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--text-dim);
  padding: 0 12px 8px;
  margin-top: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: all 0.2s ease;
  position: relative;
}

.nav-item svg {
  color: var(--text-dim);
  transition: color 0.2s, transform 0.2s;
}

.nav-item:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.nav-item:hover svg {
  color: var(--accent);
  transform: scale(1.05);
}

.nav-item.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(0, 210, 255, 0.15) 0%, rgba(0, 210, 255, 0.03) 100%);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-weight: 600;
}

.nav-item.active svg {
  color: var(--accent);
}

.nav-pill {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 12px;
}

.nav-item.active .nav-pill {
  background: rgba(0, 210, 255, 0.2);
  color: var(--accent);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.2);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-email {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: var(--text-dim);
}

.footer-actions {
  display: flex;
  gap: 4px;
}

/* ----------------- MAIN WRAPPER ----------------- */

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 24px 32px 48px;
}

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

.header-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.crumb-root { color: var(--text-dim); font-weight: 500; }
.crumb-sep { color: var(--text-dim); font-size: 13px; }
.crumb-active { color: #fff; font-weight: 700; }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.connection-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: #34d399;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 8px #34d399;
}

/* ======================================================== KPI METRIC CARDS */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.2s;
}

.kpi-card:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-cyan { background: rgba(0, 210, 255, 0.12); color: var(--accent); border: 1px solid rgba(0, 210, 255, 0.25); }
.icon-emerald { background: var(--emerald-bg); color: var(--emerald); border: 1px solid rgba(16, 185, 129, 0.25); }
.icon-blue { background: var(--blue-bg); color: var(--blue); border: 1px solid rgba(59, 130, 246, 0.25); }
.icon-rose { background: var(--rose-bg); color: var(--rose); border: 1px solid rgba(244, 63, 94, 0.25); }

.kpi-body {
  display: flex;
  flex-direction: column;
}

.kpi-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
  margin: 2px 0;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--text-dim);
}

/* ======================================================== DASHBOARD PANES */

.dashboard-pane {
  animation: fadeIn 0.2s ease-in-out;
}

.pane-card {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.pane-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 380px;
}

.search-box svg {
  position: absolute;
  left: 12px;
  color: var(--text-dim);
  pointer-events: none;
}

.search-box input {
  padding-left: 36px;
  margin-top: 0;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* ======================================================== TABLES */

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.grid th, .grid td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.grid th {
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  background: #09101b;
}

.grid tbody tr {
  transition: background 0.15s;
}

.grid tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.grid tr:last-child td {
  border-bottom: none;
}

.grid td.actions-cell,
.actions-header {
  text-align: right;
}

.empty-state {
  text-align: center !important;
  padding: 40px 16px !important;
  color: var(--text-dim);
}

.keycell {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s;
}

.keycell:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.plan-tag {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: #cbd5e1;
}

/* ======================================================== BADGES */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.badge.ok {
  background: var(--emerald-bg);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge.bad {
  background: var(--rose-bg);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.badge.warn {
  background: var(--amber-bg);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* ======================================================== FORMS */

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 16px;
}

label span {
  display: block;
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--input-bg);
  color: var(--text-main);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13.5px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-pane-card {
  max-width: 800px;
}

.pane-header {
  margin-bottom: 24px;
}

.pane-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.gen-form-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}

.form-row label {
  margin-bottom: 0;
}

.form-actions {
  margin-top: 10px;
}

.gen-result-box {
  margin-top: 28px;
  border-top: 1px solid var(--line);
  padding-top: 24px;
}

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

.result-header h3 {
  font-size: 16px;
  color: #34d399;
}

/* ======================================================== BUTTONS */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s ease;
  user-select: none;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.btn.primary {
  background: linear-gradient(135deg, #0284c7 0%, #00bcd4 100%);
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(0, 188, 212, 0.35);
}

.btn.primary:hover {
  background: linear-gradient(135deg, #039be5 0%, #00d2ff 100%);
  box-shadow: 0 6px 20px rgba(0, 210, 255, 0.5);
  transform: translateY(-1px);
}

.btn.primary:active {
  transform: translateY(0);
}

.btn.small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn.danger {
  background: transparent;
  border-color: rgba(244, 63, 94, 0.3);
  color: #fda4af;
}

.btn.danger:hover {
  background: var(--rose-bg);
  border-color: var(--rose);
  color: #fff;
}

.btn.full-width {
  width: 100%;
}

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

.btn-group {
  display: inline-flex;
  gap: 10px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.icon-btn.danger-hover:hover {
  background: var(--rose-bg);
  color: var(--rose);
}

/* ======================================================== MODAL DIALOG */

dialog {
  background: transparent;
  border: none;
  padding: 0;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  margin: 0;
}

dialog::backdrop {
  background: rgba(3, 7, 18, 0.8);
  backdrop-filter: blur(8px);
}

.modal-card {
  width: 480px;
  max-width: 90vw;
  background: var(--card-bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.8), 0 0 30px rgba(0, 210, 255, 0.05);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* ======================================================== TOAST */

#toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: #101c2e;
  border: 1px solid rgba(0, 210, 255, 0.35);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.7), 0 0 25px rgba(0, 210, 255, 0.2);
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 9999;
}

#toast.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* ======================================================== ANIMATIONS */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ======================================================== RESPONSIVE */

@media (max-width: 960px) {
  .dashboard-layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-menu {
    flex-direction: row;
    overflow-x: auto;
    padding: 10px 14px;
  }
  .menu-label {
    display: none;
  }
  .main-wrapper {
    padding: 20px 16px;
  }
}
