/* ==========================================================
   QuickScanHub - Application Styles
   Dark/light dual theme with gold accent.
   ========================================================== */

:root {
  /* Dark (default) */
  --bg:           #0a0a0f;
  --surface:      #15151f;
  --surface-2:    #1d1d29;
  --surface-3:    #252535;
  --ink:          #f3f0ea;
  --ink-dim:      #9a96a3;
  --ink-mute:     #6b6776;
  --accent:       #d4af37;
  --accent-soft:  rgba(212, 175, 55, 0.12);
  --accent-hover: #e8c668;
  --line:         rgba(255, 255, 255, 0.08);
  --line-strong:  rgba(255, 255, 255, 0.15);
  --danger:       #ef4444;
  --success:      #10b981;
  --warning:      #f59e0b;
  --info:         #3b82f6;
  --shadow:       0 30px 80px rgba(0,0,0,.6);
  --radius:       16px;
  --radius-sm:    10px;
  --radius-lg:    24px;
}

[data-theme="light"] {
  --bg:           #faf9f6;
  --surface:      #ffffff;
  --surface-2:    #f5f3ee;
  --surface-3:    #ebe8e1;
  --ink:          #1a1a24;
  --ink-dim:      #5a5663;
  --ink-mute:     #8a8694;
  --line:         rgba(0, 0, 0, 0.08);
  --line-strong:  rgba(0, 0, 0, 0.15);
  --accent-soft:  rgba(212, 175, 55, 0.18);
  --shadow:       0 30px 80px rgba(0,0,0,.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

[dir="rtl"] body {
  font-family: 'Heebo', 'Inter', system-ui, sans-serif;
}

[dir="rtl"][lang="ar"] body {
  font-family: 'Cairo', 'Heebo', 'Inter', system-ui, sans-serif;
}

a { color: var(--accent); text-decoration: none; transition: opacity .15s; }
a:hover { opacity: .8; }

img, svg { display: block; max-width: 100%; }

button {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  width: 100%;
  transition: all .15s;
}

input:focus, textarea:focus, select:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

label {
  display: block;
  font-size: 13px;
  color: var(--ink-dim);
  margin-bottom: 6px;
  font-weight: 500;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  background: var(--accent);
  color: #0a0a0f;
  font-weight: 600;
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: all .15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.btn.secondary:hover { background: var(--surface-2); }

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn.small { padding: 8px 14px; font-size: 13px; }
.btn.large { padding: 16px 28px; font-size: 17px; }
.btn.full  { width: 100%; }

/* ---------------- Layout ---------------- */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  width: 100%;
}

.container.narrow { max-width: 640px; }
.container.wide   { max-width: 1400px; }

/* ---------------- Header ---------------- */

.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  max-width: 1200px;
  margin: 0 auto;
  gap: 16px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
}

.logo-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0a0a0f;
  font-weight: 800;
  font-size: 18px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav a {
  color: var(--ink-dim);
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
}

.nav a:hover { color: var(--ink); background: var(--surface-2); opacity: 1; }

.nav .btn { padding: 10px 18px; }

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-dim);
  transition: all .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.lang-select {
  width: auto;
  padding: 8px 12px;
  font-size: 13px;
}

/* ---------------- Footer ---------------- */
.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding: 32px 24px;
  text-align: center;
  color: var(--ink-mute);
  font-size: 13px;
}

/* ---------------- Cards ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}

.card h2 { font-size: 18px; margin-bottom: 16px; }
.card h3 { font-size: 15px; margin-bottom: 12px; color: var(--ink-dim); font-weight: 600; }

/* ---------------- Hero ---------------- */
.hero {
  padding: 80px 24px 40px;
  text-align: center;
}

.hero .tagline {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 24px;
}

.hero h1 {
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 20px;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--ink) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero .subtitle {
  font-size: clamp(16px, 2vw, 20px);
  color: var(--ink-dim);
  max-width: 600px;
  margin: 0 auto 32px;
}

.hero-cta {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------------- Features ---------------- */
.features {
  padding: 60px 24px;
}

.features h2 {
  text-align: center;
  font-size: 32px;
  margin-bottom: 48px;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
}

.feature {
  text-align: center;
  padding: 32px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: all .2s;
}

.feature:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
}

.feature-icon {
  width: 56px; height: 56px;
  margin: 0 auto 16px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
}

.feature h3 { font-size: 18px; margin-bottom: 8px; }
.feature p { color: var(--ink-dim); font-size: 14px; }

/* ---------------- Generator ---------------- */
.generator {
  padding: 60px 24px;
}

.generator .panel-title {
  text-align: center;
  margin-bottom: 8px;
  font-size: 28px;
}
.generator .panel-sub {
  text-align: center;
  color: var(--ink-dim);
  margin-bottom: 32px;
}

.gen-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
}

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

.type-tabs {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  overflow-x: auto;
}

.type-tab {
  flex: 1;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--ink-dim);
  font-weight: 500;
  font-size: 14px;
  text-align: center;
  white-space: nowrap;
  min-width: max-content;
}

.type-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

.field-row {
  margin-bottom: 16px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-input {
  width: 48px;
  height: 42px;
  padding: 2px;
  cursor: pointer;
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}

.style-btn {
  aspect-ratio: 1;
  border: 2px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  padding: 8px;
}
.style-btn:hover { border-color: var(--accent); }
.style-btn.active { border-color: var(--accent); background: var(--accent-soft); }
.style-btn svg { width: 100%; height: 100%; }

.preview-panel {
  position: sticky;
  top: 90px;
  align-self: start;
}

.preview-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  box-shadow: var(--shadow);
}

.preview-box canvas, .preview-box svg, .preview-box img {
  max-width: 100%;
  height: auto;
}

.preview-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* ---------------- Tables ---------------- */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  padding: 12px;
  text-align: start;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.table th {
  font-weight: 600;
  color: var(--ink-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table tr:hover td { background: var(--surface-2); }

.badge {
  display: inline-flex;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge.active   { background: rgba(16,185,129,.15); color: var(--success); }
.badge.paused   { background: rgba(245,158,11,.15); color: var(--warning); }
.badge.disabled { background: rgba(239,68,68,.15);  color: var(--danger); }
.badge.expired  { background: rgba(107,114,128,.2); color: var(--ink-mute); }

/* ---------------- Dashboard layout ---------------- */
.dash-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 880px) {
  .dash-layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }
}

.dash-sidebar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  height: max-content;
  position: sticky;
  top: 90px;
}

.dash-sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--ink-dim);
  font-weight: 500;
  margin-bottom: 4px;
}

.dash-sidebar a:hover { background: var(--surface-2); color: var(--ink); opacity: 1; }
.dash-sidebar a.active { background: var(--accent-soft); color: var(--accent); }

@media (max-width: 880px) {
  .dash-sidebar {
    position: static;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    gap: 4px;
    padding: 8px;
  }
  .dash-sidebar a { white-space: nowrap; margin-bottom: 0; }
}

.dash-main {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ---------------- Stats grid ---------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.stat .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-dim);
  margin-bottom: 8px;
}

.stat .value {
  font-size: 32px;
  font-weight: 700;
  color: var(--ink);
}

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal h2 { margin-bottom: 8px; font-size: 22px; }
.modal p.lead { color: var(--ink-dim); margin-bottom: 20px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface-3);
  color: var(--ink);
  padding: 12px 20px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-weight: 500;
  font-size: 14px;
  z-index: 300;
  transition: transform .3s;
  box-shadow: var(--shadow);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---------------- Misc ---------------- */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.text-dim { color: var(--ink-dim); }
.text-sm { font-size: 13px; }
.text-center { text-align: center; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 13px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-dim);
}

.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chart-container { position: relative; height: 300px; }

.recent-list { list-style: none; }
.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  gap: 12px;
}
.recent-item:last-child { border-bottom: 0; }
.recent-item .meta { color: var(--ink-dim); font-size: 12px; }

.bar-list { display: flex; flex-direction: column; gap: 8px; }
.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 50px;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}
[dir="rtl"] .bar-row { grid-template-columns: 120px 1fr 50px; }
.bar-row .label { color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.bar-row .fill {
  position: absolute;
  inset-inline-start: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 4px;
}
.bar-row .num { text-align: end; font-weight: 600; }
