:root {
  --bg-primary: #0a0a0c;
  --bg-secondary: #121218;
  --bg-tertiary: #1a1a24;
  --bg-card: #15151d;
  --bg-hover: #222230;
  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-primary-hover: #7c7ff2;
  --accent-success: #10b981;
  --accent-success-glow: rgba(16, 185, 129, 0.25);
  --accent-danger: #ef4444;
  --accent-warning: #f59e0b;
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border-color: #27272a;
  --border-subtle: rgba(255, 255, 255, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
  --glow-primary: 0 0 20px rgba(99, 102, 241, 0.3);
  --glow-success: 0 0 15px rgba(16, 185, 129, 0.3);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

.app-container { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, #0f0f14 100%);
}

.sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 1px;
  height: 100%;
  background: linear-gradient(180deg, var(--accent-primary) 0%, transparent 50%, var(--accent-secondary) 100%);
  opacity: 0.5;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  margin-bottom: 32px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s;
  margin-bottom: 4px;
  cursor: pointer;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.15));
  color: var(--accent-primary);
}

.nav-icon { font-size: 18px; width: 24px; text-align: center; }

.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 32px;
  max-width: calc(100% - 260px);
}

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

.page-title { font-size: 28px; font-weight: 700; }
.page-subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  background: linear-gradient(180deg, rgba(255,255,255,0.02) 0%, transparent 100%);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-body { 
  padding: 20px 24px; 
}

.card-body-no-padding { padding: 0; }

.card:hover {
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(99, 102, 241, 0.1);
  transform: translateY(-2px);
  transition: all 0.3s ease;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.1) 0%, transparent 100%);
  opacity: 0;
  transition: opacity 0.2s;
}

.btn:hover::before { opacity: 1; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  box-shadow: var(--glow-primary);
}

.btn-primary:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-danger);
}

.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-success);
}

.btn-success:hover { background: rgba(16, 185, 129, 0.25); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }

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

th {
  padding: 14px 24px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(255, 255, 255, 0.02);
}

td { 
  padding: 18px 24px; 
  border-top: 1px solid var(--border-color);
  transition: background 0.2s;
}

tr { 
  transition: all 0.2s;
}

tr:hover td { 
  background: var(--bg-hover);
}

tr:hover {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.05) 0%, transparent 100%);
}

.rule-name { font-weight: 600; color: var(--text-primary); }
.rule-name.disabled { color: var(--text-muted); text-decoration: line-through; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  margin-right: 6px;
  margin-bottom: 4px;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.badge:hover {
  transform: scale(1.05);
}

.badge-from { 
  background: rgba(99, 102, 241, 0.15); 
  color: #a5b4fc; 
  border-color: rgba(99, 102, 241, 0.2);
}
.badge-to { 
  background: rgba(16, 185, 129, 0.15); 
  color: #6ee7b7; 
  border-color: rgba(16, 185, 129, 0.2);
}
.badge-subject { 
  background: rgba(245, 158, 11, 0.15); 
  color: #fcd34d; 
  border-color: rgba(245, 158, 11, 0.2);
}
.badge-body { 
  background: rgba(139, 92, 246, 0.15); 
  color: #c4b5fd; 
  border-color: rgba(139, 92, 246, 0.2);
}
.badge-account { 
  background: rgba(16, 185, 129, 0.15); 
  color: var(--accent-success); 
  border-color: rgba(16, 185, 129, 0.2);
}
.badge-all { 
  background: rgba(99, 102, 241, 0.15); 
  color: var(--accent-primary); 
  border-color: rgba(99, 102, 241, 0.2);
}
.badge-read {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border-color: rgba(59, 130, 246, 0.2);
}

.toggle {
  width: 48px;
  height: 26px;
  background: var(--bg-tertiary);
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid var(--border-color);
}

.toggle.active { 
  background: linear-gradient(135deg, var(--accent-success), #059669);
  border-color: transparent;
  box-shadow: var(--glow-success);
}

.toggle::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle.active::after { 
  transform: translateX(22px); 
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 16px 24px;
}

.account-card {
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--border-color);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.account-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  opacity: 0;
  transition: opacity 0.3s;
}

.account-card:hover {
  border-color: rgba(99, 102, 241, 0.3);
  transform: translateY(-4px);
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.4);
}

.account-card:hover::before {
  opacity: 1;
}

.account-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.account-avatar {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
}

.account-name { font-weight: 600; font-size: 16px; }

.account-vars { font-size: 12px; color: var(--text-muted); }

.account-vars code {
  display: block;
  padding: 4px 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  margin-top: 4px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
}

.code-preview {
  background: #0d0d10;
  border-radius: 8px;
  padding: 20px;
  overflow: auto;
  max-height: 400px;
}

#monaco-editor {
  border-radius: 0 0 12px 12px;
}

pre {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: #e4e4e7;
  margin: 0;
}

.keyword { color: #c678dd; }
.string { color: #98c379; }
.comment { color: #5c6370; font-style: italic; }
.function { color: #61afef; }
.number { color: #d19a66; }

.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s;
}

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

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 90%;
  max-width: 560px;
  max-height: 90vh;
  overflow: auto;
  animation: slideUp 0.3s;
}

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

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
}

.modal-title { font-size: 20px; font-weight: 600; }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover { background: var(--accent-danger); color: white; }

.modal-body { padding: 24px; }

.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 14px;
}

.form-input, .form-select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus { outline: none; border-color: var(--accent-primary); }
.form-input::placeholder { color: var(--text-muted); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.modal-footer {
  padding: 20px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.empty-state { 
  text-align: center; 
  padding: 60px 24px; 
  color: var(--text-muted);
  position: relative;
}

.empty-state::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.1) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.empty-icon { 
  font-size: 56px; 
  margin-bottom: 16px; 
  opacity: 0.6; 
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.actions { display: flex; gap: 8px; }

.folder-input-group { display: flex; gap: 8px; }
.folder-input-group .form-input { flex: 1; }

.folder-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.folder-preset {
  padding: 4px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.folder-preset:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

.sidebar-footer {
  margin-top: auto;
  padding: 16px;
}

.sidebar-footer-box {
  background: var(--bg-tertiary);
  border-radius: 10px;
  padding: 16px;
}

.sidebar-footer-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.dashboard-status {
  margin-bottom: 24px;
  color: var(--text-secondary);
  font-size: 14px;
}

.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  z-index: 200;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
}

.sidebar.open + .sidebar-overlay { display: block; }
.sidebar.open { transform: translateX(0); }

@media (max-width: 768px) {
  .mobile-header { display: flex; }
  .mobile-menu-btn { display: block; }
  
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 100;
    width: 280px;
  }
  
  .sidebar.open { transform: translateX(0); }
  
  .main-content {
    margin-left: 0;
    padding: 80px 16px 24px;
    max-width: 100%;
  }
  
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .page-header .btn { width: 100%; }
  
  .card-header { padding: 16px; }
  .card-body { padding: 8px 0; }
  
  th, td { padding: 12px 16px; }
  
  .account-grid {
    grid-template-columns: 1fr;
    padding: 8px 16px;
  }
  
  .form-row { grid-template-columns: 1fr; }
  
  .modal {
    width: 95%;
    max-height: 85vh;
    margin: 16px;
  }
  
  .modal-header, .modal-body, .modal-footer { padding: 16px; }
  
  .code-preview { font-size: 11px; padding: 12px; }
  
  .folder-input-group { flex-direction: column; }
  .folder-presets { overflow-x: auto; padding-bottom: 8px; }
}
