:root {
  /* Dark theme (default) */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a2e;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-hover: rgba(255, 255, 255, 0.15);
  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-tertiary: #55556a;
  --accent: #6c5ce7;
  --accent-hover: #7c6cf7;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --accent-subtle: rgba(108, 92, 231, 0.1);
  --success: #00d2a0;
  --error: #ff6b6b;
  --warning: #ffa94d;
  --glass-bg: rgba(18, 18, 26, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --code-bg: #0d0d14;
  --code-border: rgba(255, 255, 255, 0.05);
  --badge-bg: var(--accent-subtle);
  --badge-text: var(--accent);
  --orb-1: rgba(108, 92, 231, 0.15);
  --orb-2: rgba(0, 210, 160, 0.1);
  --orb-3: rgba(255, 107, 107, 0.08);
}

[data-theme="light"] {
  --bg-primary: #f5f5fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #eeeef5;
  --bg-card: rgba(255, 255, 255, 0.8);
  --bg-card-hover: rgba(255, 255, 255, 1);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-color-hover: rgba(0, 0, 0, 0.15);
  --text-primary: #1a1a2e;
  --text-secondary: #666680;
  --text-tertiary: #999;
  --accent: #5b4cdb;
  --accent-hover: #4a3cbf;
  --accent-glow: rgba(91, 76, 219, 0.25);
  --accent-subtle: rgba(91, 76, 219, 0.08);
  --glass-bg: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
  --code-bg: #f0f0f8;
  --code-border: rgba(0, 0, 0, 0.06);
  --orb-1: rgba(91, 76, 219, 0.08);
  --orb-2: rgba(0, 180, 140, 0.06);
  --orb-3: rgba(255, 107, 107, 0.05);
}

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

html {
  scroll-behavior: smooth;
}

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

.hidden { display: none !important; }

/* ===== GLASS EFFECT ===== */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes orbFloat1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -50px) scale(1.1); }
  66% { transform: translate(-20px, 20px) scale(0.9); }
}

@keyframes orbFloat2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(-40px, 30px) scale(1.15); }
  66% { transform: translate(25px, -35px) scale(0.85); }
}

@keyframes orbFloat3 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(20px, 40px) scale(0.9); }
  66% { transform: translate(-35px, -20px) scale(1.1); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%) scale(0.9); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to { opacity: 0; transform: translateX(100%) scale(0.9); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.fade-in { animation: fadeIn 0.5s ease both; }
.fade-in-delay-1 { animation: fadeIn 0.5s ease 0.1s both; }
.fade-in-delay-2 { animation: fadeIn 0.5s ease 0.2s both; }
.fade-in-delay-3 { animation: fadeIn 0.5s ease 0.3s both; }

/* ===== SCREENS ===== */
.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: block;
}

/* ===== LOGIN ===== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 48px 40px;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 2;
  animation: fadeInScale 0.6s ease;
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
}

.logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: var(--accent-subtle);
  color: var(--accent);
  margin-bottom: 20px;
}

.login-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.login-header p {
  color: var(--text-secondary);
  font-size: 14px;
}

.login-bg-orbs {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
}

.orb-1 {
  width: 400px;
  height: 400px;
  background: var(--orb-1);
  top: -100px;
  right: -100px;
  animation: orbFloat1 15s ease-in-out infinite;
}

.orb-2 {
  width: 300px;
  height: 300px;
  background: var(--orb-2);
  bottom: -80px;
  left: -80px;
  animation: orbFloat2 18s ease-in-out infinite;
}

.orb-3 {
  width: 250px;
  height: 250px;
  background: var(--orb-3);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: orbFloat3 20s ease-in-out infinite;
}

/* ===== FORMS ===== */
.input-group {
  position: relative;
  margin-bottom: 24px;
}

.input-group input,
.input-group textarea,
.input-group select {
  width: 100%;
  padding: 14px 0 10px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--border-color);
  outline: none;
  transition: border-color 0.3s ease;
}

.input-group textarea {
  resize: vertical;
  min-height: 120px;
  background: var(--code-bg);
  border: 1.5px solid var(--border-color);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.7;
}

.input-group textarea:focus {
  border-color: var(--accent);
}

.input-group select {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.input-group label {
  position: absolute;
  top: 14px;
  left: 0;
  font-size: 15px;
  color: var(--text-tertiary);
  pointer-events: none;
  transition: all 0.3s ease;
}

.input-group input:focus + label,
.input-group input:not(:placeholder-shown) + label,
.input-group textarea:focus + label,
.input-group textarea:not(:placeholder-shown) + label {
  top: -4px;
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.input-line {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent);
  transition: width 0.3s ease;
}

.input-group input:focus ~ .input-line,
.input-group textarea:focus ~ .input-line {
  width: 100%;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-ghost:hover {
  background: var(--bg-card);
  border-color: var(--border-color-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: rgba(255, 107, 107, 0.1);
  color: var(--error);
  border: 1px solid rgba(255, 107, 107, 0.2);
}

.btn-danger:hover {
  background: rgba(255, 107, 107, 0.2);
}

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

.btn-full {
  width: 100%;
  justify-content: center;
  padding: 14px 24px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.25s ease;
}

.icon-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.error-text {
  color: var(--error);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  min-height: 20px;
}

/* ===== NAVBAR ===== */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  border-radius: 0;
  border-top: none;
  border-left: none;
  border-right: none;
  border-bottom: 1px solid var(--glass-border);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  color: var(--accent);
}

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

/* Theme toggle icons */
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ===== DASHBOARD ===== */
.dashboard {
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 32px 80px;
}

.dashboard-header {
  margin-bottom: 36px;
}

.dashboard-header h2 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.dashboard-header p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 32px;
  padding: 4px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  width: fit-content;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.25s ease;
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 10px var(--accent-glow);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.35s ease;
}

/* ===== SECTION HEADER ===== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.section-header h3 {
  font-size: 18px;
  font-weight: 600;
}

/* ===== SEARCH BAR ===== */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin-bottom: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  transition: border-color 0.25s ease;
}

.search-bar:focus-within {
  border-color: var(--accent);
}

.search-bar svg {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.search-bar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
}

.search-bar input::placeholder {
  color: var(--text-tertiary);
}

/* ===== CARD GRID ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.card {
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  transition: all 0.3s ease;
  animation: fadeIn 0.4s ease both;
}

.card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-color-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.card-title a {
  color: inherit;
  text-decoration: none;
}

.card-title a:hover {
  color: var(--accent);
}

.card-description {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 6px;
  background: var(--badge-bg);
  color: var(--badge-text);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.badge-tag {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0;
}

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

.card-actions .icon-btn {
  width: 32px;
  height: 32px;
}

.card-actions .icon-btn svg {
  width: 14px;
  height: 14px;
}

/* Script specific */
.card-script {
  cursor: pointer;
}

.card-script .card-title {
  color: var(--accent);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 15px;
}

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 20px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  animation: fadeInScale 0.3s ease;
}

.modal-lg {
  max-width: 700px;
}

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

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

.modal-form .input-group:last-of-type {
  margin-bottom: 28px;
}

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

/* ===== SCRIPT VIEWER ===== */
.script-view {
  margin-bottom: 12px;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border-radius: 10px 10px 0 0;
  border: 1px solid var(--code-border);
  border-bottom: none;
}

.script-view pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 0 0 10px 10px;
  padding: 20px;
  overflow-x: auto;
  max-height: 60vh;
  overflow-y: auto;
}

.script-view code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre;
}

/* ===== TOASTS ===== */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  backdrop-filter: blur(12px);
  animation: toastIn 0.35s ease;
  min-width: 260px;
  box-shadow: var(--shadow-md);
}

.toast.success {
  background: rgba(0, 210, 160, 0.15);
  border: 1px solid rgba(0, 210, 160, 0.3);
  color: var(--success);
}

.toast.error {
  background: rgba(255, 107, 107, 0.15);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--error);
}

.toast.info {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}

.toast.removing {
  animation: toastOut 0.3s ease forwards;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
  width: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-color-hover);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .navbar {
    padding: 12px 16px;
  }

  .dashboard {
    padding: 24px 16px 60px;
  }

  .dashboard-header h2 {
    font-size: 24px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 36px 28px;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1;
    justify-content: center;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .modal {
    padding: 24px;
    border-radius: 14px;
  }
}

@media (max-width: 400px) {
  .card-grid {
    gap: 12px;
  }

  .card {
    padding: 16px;
  }

  .card-top {
    flex-direction: column;
  }
}

/* ===== LOADING STATE ===== */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 8px;
}

/* ===== SELECT STYLING ===== */
.input-group select {
  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='%238888a0' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0 center;
  padding-right: 20px;
}

.input-group select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}
