@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --background: 220 30% 6%;
  --foreground: 220 15% 95%;
  --card: 220 25% 10%;
  --card-foreground: 220 15% 95%;
  --primary: 220 85% 60%;
  --primary-foreground: 220 30% 6%;
  --secondary: 220 20% 15%;
  --secondary-foreground: 220 50% 75%;
  --muted: 220 20% 15%;
  --muted-foreground: 220 15% 55%;
  --accent: 160 65% 50%;
  --accent-foreground: 220 30% 6%;
  --border: 220 20% 18%;
  --input: 220 20% 18%;
  --ring: 220 85% 60%;
  --radius: 1rem;
  --gradient-primary: linear-gradient(135deg, hsl(220 85% 60%) 0%, hsl(260 75% 55%) 50%, hsl(300 70% 50%) 100%);
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* Header */
.header {
  border-bottom: 1px solid hsl(var(--border));
  padding: 1rem 1.5rem;
  background: hsl(var(--card));
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--gradient-primary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 20px hsla(220 85% 60% / 0.3);
}

.logo-text {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.badge {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--secondary));
  padding: 0.375rem 0.875rem;
  border-radius: 9999px;
  font-weight: 500;
}

/* Main */
.main {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
}

/* Section */
.section {
  margin-bottom: 2rem;
}

.section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Profile Grid */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1rem 1.125rem;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.profile-card:hover {
  border-color: hsl(var(--primary) / 0.5);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px hsla(0 0% 0% / 0.2);
}

.profile-card.active {
  border-color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.1);
  box-shadow: 0 0 0 3px hsl(var(--primary) / 0.15), 0 8px 24px hsla(0 0% 0% / 0.2);
}

.profile-card .icon {
  font-size: 1.75rem;
  line-height: 1;
}

.profile-card .name {
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(var(--card-foreground));
}

/* Editor Layout */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 1024px) {
  .editor-layout { grid-template-columns: 1fr; }
}

/* Panel */
.panel {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 1rem;
  overflow: hidden;
}

.panel-header {
  padding: 1rem 1.25rem;
  background: hsl(var(--secondary) / 0.5);
  border-bottom: 1px solid hsl(var(--border));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.panel-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: hsl(var(--foreground));
}

.panel-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Form */
.field { display: flex; flex-direction: column; gap: 0.5rem; }

.field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: 0.625rem;
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  font-family: inherit;
  transition: all 0.2s;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 3px hsl(var(--primary) / 0.1);
}

.field input::placeholder,
.field textarea::placeholder {
  color: hsl(var(--muted-foreground) / 0.7);
}

.field textarea { resize: vertical; min-height: 80px; }

.field select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr; }
}

/* Rules */
.rules { display: flex; flex-direction: column; gap: 0.5rem; }

.rule-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: 0.625rem;
  transition: border-color 0.2s;
}

.rule-item:focus-within {
  border-color: hsl(var(--primary) / 0.5);
}

.rule-num {
  width: 26px;
  height: 26px;
  background: var(--gradient-primary);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.rule-item input {
  flex: 1;
  background: none;
  border: none;
  font-size: 0.875rem;
  padding: 0;
  color: hsl(var(--foreground));
}

.rule-item input:focus { outline: none; }

.rule-item button {
  background: none;
  border: none;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  padding: 0.25rem;
  opacity: 0;
  transition: opacity 0.2s;
  font-size: 1rem;
}

.rule-item:hover button { opacity: 1; }
.rule-item button:hover { color: hsl(0 72% 51%); }

.add-btn {
  width: 100%;
  padding: 0.625rem;
  background: transparent;
  border: 1px dashed hsl(var(--border));
  border-radius: 0.625rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.add-btn:hover {
  border-color: hsl(var(--primary));
  color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.05);
}

/* Actions */
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border));
  border-radius: 0.625rem;
  color: hsl(var(--secondary-foreground));
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover {
  background: hsl(var(--muted));
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--gradient-primary);
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 12px hsla(220 85% 60% / 0.3);
}

.btn.primary:hover {
  box-shadow: 0 6px 20px hsla(220 85% 60% / 0.4);
  transform: translateY(-2px);
}

/* Stats */
.stats {
  display: flex;
  gap: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: hsl(var(--secondary) / 0.5);
  border-bottom: 1px solid hsl(var(--border));
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.stats strong {
  color: hsl(var(--primary));
  font-weight: 600;
}

/* Preview */
.preview-box {
  padding: 1.25rem;
  max-height: 400px;
  overflow-y: auto;
}

.preview-box pre {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8125rem;
  line-height: 1.7;
  white-space: pre-wrap;
  color: hsl(var(--foreground) / 0.85);
}

/* Footer */
.footer {
  text-align: center;
  padding: 1.5rem;
  border-top: 1px solid hsl(var(--border));
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  background: hsl(var(--card));
}

.footer strong {
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 600;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: hsla(0 0% 0% / 0.7);
  backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.active { display: flex; }

.modal-box {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 1rem;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow: hidden;
  margin: 1rem;
  box-shadow: 0 24px 48px hsla(0 0% 0% / 0.4);
}

.modal-header {
  padding: 1rem 1.25rem;
  background: hsl(var(--secondary) / 0.5);
  border-bottom: 1px solid hsl(var(--border));
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 0.875rem; font-weight: 600; }

.close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
}

.close:hover { color: hsl(var(--foreground)); }

.modal-body {
  padding: 1rem;
  max-height: calc(80vh - 60px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.saved-item {
  padding: 0.875rem 1rem;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: 0.625rem;
  cursor: pointer;
  transition: all 0.2s;
}

.saved-item:hover {
  border-color: hsl(var(--primary) / 0.5);
  background: hsl(var(--primary) / 0.05);
}

.saved-item h4 {
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.saved-item p {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.75rem 1.25rem;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--accent));
  border-radius: 0.75rem;
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 32px hsla(0 0% 0% / 0.3);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 2000;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: hsl(var(--border)); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground)); }

/* Responsive */
@media (max-width: 640px) {
  .main { padding: 1rem; }
  .panel-body { padding: 1rem; }
  .header { padding: 0.75rem 1rem; }
  .actions { flex-direction: column; }
  .btn { width: 100%; justify-content: center; }
  .profile-grid { grid-template-columns: repeat(2, 1fr); }
}
