/* ═══════════════════════════════════════════════════════════
   MaxTool Dynamic Injection System — Premium Dashboard CSS
   ═══════════════════════════════════════════════════════════ */

/* ── Tokens ────────────────────────────────────────────── */
:root {
  --bg-deep:       #07080a;
  --bg-base:       #0d0f14;
  --bg-surface:    #131620;
  --bg-elevated:   #1a1d2b;
  --bg-hover:      #21253a;
  --border:        #1e2235;
  --border-bright: #2a2f4a;
  --text-primary:  #e8eaf0;
  --text-secondary:#8b8fa7;
  --text-muted:    #555873;

  --accent-green:  #10b981;
  --accent-red:    #ef4444;
  --accent-purple: #a855f7;
  --accent-blue:   #3b82f6;
  --accent-amber:  #f59e0b;

  --glow-green:    rgba(16,185,129,.12);
  --glow-red:      rgba(239,68,68,.12);
  --glow-purple:   rgba(168,85,247,.12);
  --glow-blue:     rgba(59,130,246,.12);

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  18px;

  --font-ui:   'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --ease: cubic-bezier(.4,0,.2,1);
  --transition-fast: .18s var(--ease);
  --transition-mid:  .28s var(--ease);
  --transition-slow: .4s  var(--ease);

  --sidebar-w: 56px;
  --drawer-w:  480px;
}

/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--bg-deep);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Custom Scrollbar ──────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Typography ────────────────────────────────────────── */
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -.01em; color: var(--text-primary); }
.mono { font-family: var(--font-mono); font-size: 12px; }

/* ══════════════════════════════════════════════════════════
   LOGIN OVERLAY
   ══════════════════════════════════════════════════════════ */
.login-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-deep);
  animation: loginFadeIn .5s var(--ease);
}
@keyframes loginFadeIn { from { opacity: 0 } to { opacity: 1 } }

.login-box {
  display: flex; flex-direction: column; align-items: center; gap: 28px;
  width: 340px; padding: 44px 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 0 80px rgba(59,130,246,.06);
}

.login-logo {
  font-size: 15px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent-blue);
}
.login-logo span { color: var(--text-muted); font-weight: 400; }

.login-input {
  width: 100%; padding: 12px 16px;
  font-family: var(--font-mono); font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-base);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  outline: none;
  transition: border var(--transition-fast), box-shadow var(--transition-fast);
}
.login-input::placeholder { color: var(--text-muted); }
.login-input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.login-btn {
  width: 100%; padding: 12px;
  font-family: var(--font-ui); font-size: 13px; font-weight: 600;
  color: #fff; background: var(--accent-blue);
  border: none; border-radius: var(--radius-md); cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.login-btn:hover { background: #2563eb; transform: translateY(-1px); }
.login-btn:active { transform: translateY(0); }

.login-error {
  font-size: 12px; color: var(--accent-red);
  min-height: 16px; text-align: center;
}

/* ══════════════════════════════════════════════════════════
   APP SHELL
   ══════════════════════════════════════════════════════════ */
.app { display: flex; height: 100vh; width: 100vw; }

/* ── Navigation Rail ───────────────────────────────────── */
.nav-rail {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 0 18px;
  background: var(--bg-base);
  border-right: 1px solid var(--border);
  z-index: 100;
}

.nav-brand {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  margin-bottom: 24px;
  font-size: 16px; font-weight: 800; color: var(--accent-blue);
  background: rgba(59,130,246,.1);
  border-radius: var(--radius-sm);
}

.nav-items { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 20px; color: var(--text-muted);
  background: transparent; border: none; border-radius: var(--radius-sm);
  cursor: pointer; position: relative;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.nav-btn:hover { color: var(--text-secondary); background: var(--bg-hover); }
.nav-btn.active {
  color: var(--accent-blue);
  background: rgba(59,130,246,.1);
}
.nav-btn.active::before {
  content: '';
  position: absolute; left: -9px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--accent-blue);
  border-radius: 0 4px 4px 0;
}

.nav-spacer { flex: 1; }

.nav-btn.danger:hover { color: var(--accent-red); background: rgba(239,68,68,.08); }

/* ── Main Content Area ─────────────────────────────────── */
.main {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; background: var(--bg-deep);
}

.view {
  display: none; flex-direction: column;
  flex: 1; overflow-y: auto;
  padding: 28px 32px;
  animation: viewFadeIn .3s var(--ease);
}
.view.active { display: flex; }

@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.view-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}

.view-title {
  font-size: 18px; font-weight: 700; letter-spacing: -.02em;
  display: flex; align-items: center; gap: 10px;
}
.view-title .material-symbols-rounded { font-size: 22px; color: var(--accent-blue); }

/* ══════════════════════════════════════════════════════════
   STAT CARDS
   ══════════════════════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  padding: 22px 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
  transition: transform var(--transition-fast), box-shadow var(--transition-mid);
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.stat-card:hover { transform: translateY(-2px); }

.stat-card.green::before  { background: var(--accent-green); }
.stat-card.green:hover    { box-shadow: 0 8px 32px var(--glow-green); }
.stat-card.blue::before   { background: var(--accent-blue); }
.stat-card.blue:hover     { box-shadow: 0 8px 32px var(--glow-blue); }
.stat-card.red::before    { background: var(--accent-red); }
.stat-card.red:hover      { box-shadow: 0 8px 32px var(--glow-red); }
.stat-card.purple::before { background: var(--accent-purple); }
.stat-card.purple:hover   { box-shadow: 0 8px 32px var(--glow-purple); }

.stat-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.stat-card.green  .stat-value { color: var(--accent-green); }
.stat-card.blue   .stat-value { color: var(--accent-blue); }
.stat-card.red    .stat-value { color: var(--accent-red); }
.stat-card.purple .stat-value { color: var(--accent-purple); }

/* ══════════════════════════════════════════════════════════
   TABLES
   ══════════════════════════════════════════════════════════ */
.table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  backdrop-filter: blur(12px);
}

.table-wrap table {
  width: 100%; border-collapse: collapse;
}

.table-wrap th {
  text-align: left;
  padding: 12px 16px;
  font-size: 10px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  user-select: none;
  white-space: nowrap;
}

.table-wrap td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-wrap tbody tr {
  transition: background var(--transition-fast);
}
.table-wrap tbody tr:nth-child(even) { background: rgba(255,255,255,.01); }
.table-wrap tbody tr:hover { background: var(--bg-hover); }

.table-wrap tbody tr:last-child td { border-bottom: none; }

.table-empty {
  padding: 52px 16px;
  text-align: center;
  color: var(--text-muted);
}
.table-empty .material-symbols-rounded { font-size: 40px; display: block; margin-bottom: 10px; opacity: .35; }
.table-empty p { font-size: 13px; }

/* Row actions */
.row-actions {
  display: flex; gap: 4px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.table-wrap tbody tr:hover .row-actions { opacity: 1; }

.row-action-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  font-size: 17px; color: var(--text-muted);
  background: transparent; border: none; border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.row-action-btn:hover { color: var(--text-primary); background: var(--bg-surface); }
.row-action-btn.danger:hover { color: var(--accent-red); background: rgba(239,68,68,.08); }

/* ══════════════════════════════════════════════════════════
   BADGES
   ══════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  border-radius: 99px;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge.injection {
  color: var(--accent-green);
  background: rgba(16,185,129,.1);
  border: 1px solid rgba(16,185,129,.18);
}
.badge.block {
  color: var(--accent-red);
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.18);
}
.badge.redirect {
  color: var(--accent-purple);
  background: rgba(168,85,247,.1);
  border: 1px solid rgba(168,85,247,.18);
}
.badge.log-event {
  color: var(--accent-blue);
  background: rgba(59,130,246,.1);
  border: 1px solid rgba(59,130,246,.18);
}

/* ══════════════════════════════════════════════════════════
   TOGGLE SWITCH
   ══════════════════════════════════════════════════════════ */
.toggle {
  position: relative;
  width: 36px; height: 20px;
  display: inline-block;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--bg-hover);
  border-radius: 99px; cursor: pointer;
  transition: background var(--transition-fast);
}
.toggle-track::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 14px; height: 14px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform var(--transition-fast), background var(--transition-fast);
}
.toggle input:checked + .toggle-track {
  background: rgba(16,185,129,.2);
}
.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: var(--accent-green);
}

/* ══════════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  font-family: var(--font-ui); font-size: 12px; font-weight: 600;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast),
              transform var(--transition-fast), box-shadow var(--transition-fast);
}
.btn:active { transform: scale(.97); }
.btn .material-symbols-rounded { font-size: 16px; }

.btn-primary {
  color: #fff; background: var(--accent-blue);
}
.btn-primary:hover { background: #2563eb; box-shadow: 0 4px 20px rgba(59,130,246,.25); }

.btn-secondary {
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-bright);
}
.btn-secondary:hover { color: var(--text-primary); background: var(--bg-hover); border-color: var(--text-muted); }

.btn-danger {
  color: var(--accent-red); background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.18);
}
.btn-danger:hover { background: rgba(239,68,68,.15); }

.btn-icon {
  width: 34px; height: 34px; padding: 0;
  display: grid; place-items: center;
  font-size: 18px; color: var(--text-muted);
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.btn-icon:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ══════════════════════════════════════════════════════════
   SEARCH INPUT
   ══════════════════════════════════════════════════════════ */
.search-wrap {
  position: relative; display: flex; align-items: center;
}
.search-wrap .material-symbols-rounded {
  position: absolute; left: 12px;
  font-size: 17px; color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  padding: 8px 14px 8px 36px;
  width: 260px;
  font-family: var(--font-ui); font-size: 12px;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border var(--transition-fast), box-shadow var(--transition-fast), width var(--transition-mid);
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
  width: 300px;
}

/* ══════════════════════════════════════════════════════════
   DRAWER (Rule Editor)
   ══════════════════════════════════════════════════════════ */
.backdrop {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition-mid);
}
.backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: var(--drawer-w); z-index: 510;
  display: flex; flex-direction: column;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 48px rgba(0,0,0,.35);
  transform: translateX(100%);
  transition: transform var(--transition-mid);
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.drawer-title {
  font-size: 13px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-secondary);
}
.drawer-close {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  font-size: 20px; color: var(--text-muted);
  background: transparent; border: none; border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.drawer-close:hover { color: var(--text-primary); background: var(--bg-hover); }

.drawer-body {
  flex: 1; overflow-y: auto;
  padding: 24px;
  display: flex; flex-direction: column; gap: 20px;
}

.drawer-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-base);
}

/* ── Form Controls ────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-size: 10px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-muted);
}

.field-hint {
  font-size: 11px; color: var(--text-muted); margin-top: -2px;
}

.field-input,
.field-select {
  padding: 10px 14px;
  font-family: var(--font-ui); font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border var(--transition-fast), box-shadow var(--transition-fast);
}
.field-input:focus,
.field-select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}

.field-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23555873' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.code-editor {
  padding: 14px 16px;
  font-family: var(--font-mono); font-size: 12px;
  line-height: 1.65; color: var(--accent-green);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none; resize: vertical;
  min-height: 100px;
  tab-size: 2;
  transition: border var(--transition-fast), box-shadow var(--transition-fast);
}
.code-editor:focus {
  border-color: var(--accent-green);
  box-shadow: 0 0 0 3px rgba(16,185,129,.08);
}
.code-editor.css-editor { color: var(--accent-blue); }
.code-editor.css-editor:focus { border-color: var(--accent-blue); box-shadow: 0 0 0 3px rgba(59,130,246,.08); }
.code-editor.js-editor  { color: var(--accent-amber); }
.code-editor.js-editor:focus { border-color: var(--accent-amber); box-shadow: 0 0 0 3px rgba(245,158,11,.08); }

.block-warning {
  padding: 14px 18px;
  font-size: 12px; color: var(--accent-red);
  background: rgba(239,68,68,.06);
  border: 1px solid rgba(239,68,68,.15);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 10px;
}
.block-warning .material-symbols-rounded { font-size: 20px; }

/* ══════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ══════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 9000;
  display: flex; flex-direction: column-reverse; gap: 8px;
  pointer-events: none;
}

.toast {
  min-width: 280px; max-width: 380px;
  padding: 12px 18px;
  font-size: 12px; font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  backdrop-filter: blur(16px);
  display: flex; align-items: center; gap: 10px;
  pointer-events: auto;
  animation: toastIn .3s var(--ease) forwards;
}
.toast.removing {
  animation: toastOut .25s var(--ease) forwards;
}
.toast .material-symbols-rounded { font-size: 18px; }

.toast.success { border-left: 3px solid var(--accent-green); }
.toast.success .material-symbols-rounded { color: var(--accent-green); }
.toast.error   { border-left: 3px solid var(--accent-red); }
.toast.error .material-symbols-rounded   { color: var(--accent-red); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px) scale(.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to   { opacity: 0; transform: translateX(40px) scale(.92); }
}

/* ══════════════════════════════════════════════════════════
   RECENT LOG PANEL (Dashboard view)
   ══════════════════════════════════════════════════════════ */
.log-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  backdrop-filter: blur(12px);
}

.log-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.log-entry {
  padding: 10px 20px;
  font-family: var(--font-mono); font-size: 11.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  display: flex; gap: 14px; align-items: center;
}
.log-entry:last-child { border-bottom: none; }
.log-entry .log-time { color: var(--text-muted); min-width: 140px; white-space: nowrap; }

/* ══════════════════════════════════════════════════════════
   UTILITIES & RESPONSIVE
   ══════════════════════════════════════════════════════════ */
.flex-gap  { display: flex; gap: 8px; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.payload-preview {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-muted); max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.section-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* Responsive */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .drawer { width: 100%; max-width: 420px; }
}
@media (max-width: 700px) {
  .stats-grid { grid-template-columns: 1fr; }
  .view { padding: 20px 16px; }
  .search-input { width: 180px; }
  .search-input:focus { width: 200px; }
  .view-header { flex-direction: column; align-items: flex-start; }
}