:root {
  --bg: #07090f;
  --glass: rgba(255, 255, 255, 0.04);
  --glass-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.35);
  --emerald: #10b981;
  --emerald-glow: rgba(16, 185, 129, 0.25);
  --danger: #ef4444;
  --radius: 18px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Vazirmatn", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Ambient Aurora Background */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.4;
}
.glow-1 {
  width: 520px; height: 520px;
  background: radial-gradient(circle, #4f46e5, transparent 70%);
  top: -160px; right: -100px;
}
.glow-2 {
  width: 460px; height: 460px;
  background: radial-gradient(circle, #059669, transparent 70%);
  bottom: -140px; left: -100px;
}

/* Topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 24px;
  background: rgba(7, 9, 15, 0.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo-mark {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #6366f1, #10b981);
  box-shadow: 0 8px 24px var(--primary-glow);
}
.brand h1 { margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.3px; }
.brand small { color: var(--muted); font-size: 0.76rem; display: block; margin-top: -2px; }

.tabs {
  display: flex; gap: 6px; padding: 5px;
  background: var(--glass); border: 1px solid var(--border); border-radius: 14px;
}
.tab {
  background: transparent; color: var(--muted); border: none;
  padding: 8px 16px; border-radius: 10px; cursor: pointer;
  font-family: inherit; font-weight: 600; font-size: 0.88rem;
  transition: all 0.2s ease;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  box-shadow: 0 4px 16px var(--primary-glow);
}

.health-badge {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.76rem; padding: 6px 12px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--border); color: var(--muted);
}
.pulse-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--emerald);
  box-shadow: 0 0 10px var(--emerald);
}

.container { max-width: 1240px; margin: 26px auto; padding: 0 18px; }
.panel { display: none; animation: fadeIn 0.25s ease; }
.panel.active { display: block; }
.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Glass Cards */
.glass-card {
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

.hero-upload {
  text-align: center;
  padding: 44px 22px;
  border: 1.5px dashed var(--border-strong);
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.06), rgba(16, 185, 129, 0.03));
  transition: border-color 0.2s, transform 0.2s;
}
.hero-upload:hover { border-color: var(--primary); }
.hero-icon {
  width: 68px; height: 68px; margin: 0 auto 14px; border-radius: 20px;
  display: grid; place-items: center;
  background: rgba(99, 102, 241, 0.14); color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
}
.hero-upload h2 { margin: 0 0 6px; font-size: 1.35rem; font-weight: 800; }

.card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-header h3 { margin: 0; font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }

/* Buttons */
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }
.btn {
  border: none; border-radius: 12px; padding: 10px 18px; cursor: pointer;
  font-family: inherit; font-weight: 600; font-size: 0.9rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; transition: all 0.2s ease;
}
.btn-lg { padding: 12px 22px; font-size: 0.95rem; }
.btn-sm { padding: 6px 11px; font-size: 0.8rem; border-radius: 9px; }
.btn-block { width: 100%; margin-top: 10px; }
.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff;
  box-shadow: 0 6px 20px var(--primary-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 26px var(--primary-glow); }
.btn-emerald {
  background: linear-gradient(135deg, #10b981, #059669); color: #022c22; font-weight: 700;
  box-shadow: 0 6px 20px var(--emerald-glow);
}
.btn-emerald:hover { transform: translateY(-1px); }
.btn-glass {
  background: var(--glass); color: var(--text); border: 1px solid var(--border-strong);
}
.btn-glass:hover { background: var(--glass-hover); }
.btn-danger { background: rgba(239, 68, 68, 0.16); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.35); }
.btn-danger:hover { background: var(--danger); color: #fff; }

/* Crop Canvas + Google Lens Scan Laser */
.canvas-wrap {
  position: relative; display: flex; justify-content: center;
  background: #030508; border-radius: 14px; overflow: hidden; border: 1px solid var(--border);
}
#cropCanvas { max-width: 100%; max-height: 400px; cursor: crosshair; touch-action: none; }
.scan-laser {
  position: absolute; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent, #10b981, #6366f1, transparent);
  box-shadow: 0 0 18px #10b981;
  animation: scanSweep 1.3s ease-in-out infinite;
}
@keyframes scanSweep { 0% { top: 5%; } 50% { top: 92%; } 100% { top: 5%; } }

.results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 12px; }
.ai-box {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(99, 102, 241, 0.08));
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: var(--radius); padding: 16px; margin-bottom: 18px; white-space: pre-line;
}

/* Bento Results Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 16px;
}
.design-card {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.design-card:hover { transform: translateY(-3px); border-color: var(--border-strong); }
.design-thumb-wrap { position: relative; overflow: hidden; background: #030508; }
.design-card img {
  width: 100%; height: 205px; object-fit: cover; display: block;
  transition: transform 0.35s ease;
}
.design-card:hover img { transform: scale(1.04); }
.score-float {
  position: absolute; top: 10px; left: 10px;
  background: rgba(6, 78, 59, 0.88); backdrop-filter: blur(8px);
  color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.45);
  font-size: 0.78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px;
}
.design-body { padding: 14px; display: flex; flex-direction: column; gap: 9px; flex: 1; }
.code-pill {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(99, 102, 241, 0.12); border: 1px solid rgba(99, 102, 241, 0.28);
  padding: 6px 10px; border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.94rem; font-weight: 700; color: #c7d2fe;
}
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 0.74rem; padding: 3px 9px; border-radius: 999px; background: var(--glass); border: 1px solid var(--border); color: var(--muted); }
.badge-psd { background: rgba(37, 99, 235, 0.25); border-color: rgba(59, 130, 246, 0.45); color: #93c5fd; }

/* Inputs & Search */
.search-bar { display: flex; gap: 10px; }
.large-search { max-width: 560px; margin: 16px auto 0; }
.code-hero { text-align: center; padding: 34px 20px; }
.search-bar input, .input {
  flex: 1; width: 100%; padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: rgba(0, 0, 0, 0.35); color: var(--text);
  font-family: inherit; outline: none; transition: border-color 0.2s;
}
.search-bar input:focus, .input:focus { border-color: var(--primary); }
.input { margin-bottom: 10px; }
.file-label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 10px; }

/* Admin Layout */
.admin-grid { display: grid; grid-template-columns: 310px 1fr; gap: 18px; }
@media (max-width: 880px) { .admin-grid { grid-template-columns: 1fr; } }

.folder-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.folder-list li {
  padding: 9px 12px; border-radius: 10px; cursor: pointer;
  display: flex; justify-content: space-between; font-size: 0.9rem;
  transition: background 0.15s;
}
.folder-list li:hover, .folder-list li.active { background: rgba(99, 102, 241, 0.18); color: #fff; }

.progress-box { margin-top: 12px; }
.progress-bar { height: 8px; background: rgba(0, 0, 0, 0.4); border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
#zipProgressFill { height: 100%; width: 0%; background: linear-gradient(90deg, #6366f1, #10b981); transition: width 0.3s; }

/* Modal & Toast */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.78); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-content { max-width: 520px; width: 92%; }
.modal-content video { width: 100%; border-radius: 12px; }

.toast {
  position: fixed; bottom: 24px; left: 24px;
  background: linear-gradient(135deg, #10b981, #059669); color: #022c22;
  padding: 11px 18px; border-radius: 12px; font-weight: 700; z-index: 60;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.login-card {
  max-width: 440px;
  margin: 60px auto;
  text-align: center;
  padding: 36px 24px;
}

.footer {
  max-width: 1240px;
  margin: 40px auto 24px;
  padding: 0 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 0.8rem;
}
.footer a { text-decoration: none; }
.footer a:hover { color: var(--text); }

/* Mobile Glassmorphic Header & Responsive Polish */
@media (max-width: 768px) {
  .topbar {
    padding: 12px 14px;
    gap: 10px;
  }
  .brand {
    flex: 1;
    min-width: 0;
  }
  .brand h1 { font-size: 1rem; }
  .brand small { font-size: 0.7rem; }
  .health-badge {
    max-width: 155px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.7rem;
    padding: 5px 10px;
  }
  .tabs {
    order: 3;
    width: 100%;
    display: flex;
    justify-content: stretch;
  }
  .tab {
    flex: 1;
    text-align: center;
    padding: 9px 10px;
    font-size: 0.84rem;
  }
  .container {
    margin: 16px auto;
    padding: 0 12px;
  }
  .hero-upload {
    padding: 28px 16px;
  }
  .hero-upload h2 { font-size: 1.12rem; }
  .search-bar {
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .hero-upload .actions-row {
    flex-direction: column;
    width: 100%;
  }
  .hero-upload .actions-row .btn {
    width: 100%;
  }
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .design-card img {
    height: 150px;
  }
  .design-body {
    padding: 10px;
  }
}
