/* ===== CSS Variables (Light Theme) ===== */
:root {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f8f9fa;
  --bg-accent: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --text-primary: #1a1a2e;
  --text-secondary: #555;
  --text-muted: #999;
  --border: #e0e0e0;
  --border-light: #f0f0f0;
  --accent: #667eea;
  --accent-hover: #5a6fd6;
  --accent-light: rgba(102, 126, 234, 0.1);
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
  --info: #17a2b8;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-width: 260px;
  --header-height: 60px;
  --transition: 0.3s ease;
}

/* ===== Dark Theme ===== */
[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #16213e;
  --text-primary: #e0e0e0;
  --text-secondary: #aaa;
  --text-muted: #666;
  --border: #2a2a4a;
  --border-light: #1f1f3a;
  --accent: #7c8cf8;
  --accent-hover: #6b7ce8;
  --accent-light: rgba(124, 140, 248, 0.15);
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
}

/* ===== Reset ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}
body.rtl { direction: rtl; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
.app-layout { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}
body.rtl .sidebar { left: auto; right: 0; border-right: none; border-left: 1px solid var(--border); }
.sidebar-header {
  padding: 20px;
  background: var(--bg-accent);
  color: white;
  text-align: center;
}
.sidebar-header h2 { font-size: 1.2rem; margin-bottom: 4px; }
.sidebar-header small { opacity: 0.8; font-size: 0.75rem; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; cursor: pointer;
  color: var(--text-secondary); transition: all var(--transition);
  border-left: 3px solid transparent; font-size: 0.93rem;
}
body.rtl .nav-item { border-left: none; border-right: 3px solid transparent; }
.nav-item:hover { background: var(--accent-light); color: var(--accent); }
.nav-item.active { background: var(--accent-light); color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
body.rtl .nav-item.active { border-left-color: transparent; border-right-color: var(--accent); }
.nav-item .icon { font-size: 1.2em; width: 24px; text-align: center; }
.nav-divider { height: 1px; background: var(--border); margin: 8px 20px; }
.sidebar-footer {
  padding: 15px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}
body.rtl .main-content { margin-left: 0; margin-right: var(--sidebar-width); }

/* ===== Top Bar ===== */
.top-bar {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
}
.top-bar-left { display: flex; align-items: center; gap: 16px; }
.top-bar-right { display: flex; align-items: center; gap: 12px; }
.hamburger { display: none; background: none; border: none; font-size: 1.5em; cursor: pointer; color: var(--text-primary); }
.page-title { font-size: 1.1rem; font-weight: 600; }

/* ===== Page Sections ===== */
.page-section { display: none; padding: 24px; max-width: 1400px; margin: 0 auto; }
.page-section.active { display: block; }

/* ===== Cards ===== */
.card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-header h3 { font-size: 1.1rem; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border: none; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: all var(--transition); text-decoration: none;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); text-decoration: none; }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-success { background: var(--success); color: white; }
.btn-sm { padding: 6px 14px; font-size: 0.82rem; }
.btn-lg { padding: 14px 32px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 0.88rem; color: var(--text-secondary); }
.form-control {
  width: 100%; padding: 10px 14px;
  background: var(--bg-tertiary); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.93rem; transition: border-color var(--transition);
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
select.form-control { cursor: pointer; }
input[type="color"].form-control { padding: 4px; height: 42px; cursor: pointer; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 120px; }

/* ===== Grid ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ===== Size Buttons ===== */
.size-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.size-btn {
  padding: 8px 14px; background: var(--bg-tertiary); border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; font-size: 0.82rem;
  font-weight: 500; transition: all var(--transition); color: var(--text-primary);
}
.size-btn:hover { border-color: var(--accent); }
.size-btn.active { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }

/* ===== Format Checkboxes ===== */
.format-group { display: flex; gap: 16px; flex-wrap: wrap; }
.format-label {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  background: var(--bg-tertiary); border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition);
}
.format-label:has(input:checked) { border-color: var(--accent); background: var(--accent-light); }
.format-label input { accent-color: var(--accent); }

/* ===== Results ===== */
.results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.result-card {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden; text-align: center;
}
.result-card img, .result-card video { max-width: 100%; height: auto; display: block; }
.result-card .result-info { padding: 12px; display: flex; justify-content: space-between; align-items: center; }
.result-card .result-info .format-badge {
  padding: 3px 10px; background: var(--accent); color: white;
  border-radius: 20px; font-size: 0.75rem; text-transform: uppercase; font-weight: 600;
}

/* ===== Templates Gallery ===== */
.template-card {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: all var(--transition);
}
.template-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--accent); }
.template-preview { height: 120px; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.template-info { padding: 12px; }
.template-info h4 { font-size: 0.9rem; margin-bottom: 4px; }
.template-info .category-badge {
  display: inline-block; padding: 2px 8px; background: var(--accent-light);
  color: var(--accent); border-radius: 10px; font-size: 0.72rem; font-weight: 600;
}

/* ===== History Table ===== */
.history-list { display: flex; flex-direction: column; gap: 12px; }
.history-item {
  display: flex; align-items: center; gap: 16px; padding: 12px;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); transition: background var(--transition);
}
.history-item:hover { background: var(--accent-light); }
.history-thumb { width: 80px; height: 50px; border-radius: 6px; object-fit: cover; background: #333; }
.history-details { flex: 1; }
.history-details h4 { font-size: 0.88rem; margin-bottom: 2px; }
.history-details small { color: var(--text-muted); }
.history-actions { display: flex; gap: 8px; }

/* ===== Auth Forms ===== */
.auth-container { max-width: 400px; margin: 40px auto; }
.auth-tabs { display: flex; gap: 0; margin-bottom: 24px; }
.auth-tab {
  flex: 1; padding: 12px; text-align: center; cursor: pointer;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  font-weight: 600; transition: all var(--transition);
}
.auth-tab:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.auth-tab:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.auth-tab.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ===== Analytics Charts ===== */
.stat-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; text-align: center;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-card .stat-label { font-size: 0.82rem; color: var(--text-muted); margin-top: 4px; }
.chart-container { position: relative; height: 300px; width: 100%; }

/* ===== API Keys ===== */
.key-card {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 16px; background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 10px;
}
.key-prefix { font-family: monospace; font-size: 0.9rem; color: var(--accent); }
.key-new {
  background: var(--success); color: white; padding: 12px 16px;
  border-radius: var(--radius-sm); font-family: monospace; word-break: break-all;
  margin-bottom: 16px;
}

/* ===== Batch Mode ===== */
.batch-table { width: 100%; border-collapse: collapse; }
.batch-table th, .batch-table td {
  padding: 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.88rem;
}
.batch-table th { font-weight: 600; color: var(--text-muted); }
.batch-progress { display: flex; align-items: center; gap: 12px; }
.progress-bar {
  flex: 1; height: 8px; background: var(--bg-tertiary); border-radius: 4px; overflow: hidden;
}
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.5s ease; }

/* ===== Logo Manager ===== */
.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.logo-item {
  position: relative; border: 2px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  background: var(--bg-tertiary); cursor: pointer;
}
.logo-item:hover { border-color: var(--accent); }
.logo-item.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.logo-item img { max-width: 80%; max-height: 80%; object-fit: contain; }
.logo-delete {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px;
  background: var(--danger); color: white; border: none; border-radius: 50%;
  cursor: pointer; font-size: 0.75rem; display: none; align-items: center; justify-content: center;
}
.logo-item:hover .logo-delete { display: flex; }

/* ===== Theme Toggle ===== */
.theme-toggle {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 12px; cursor: pointer;
  font-size: 1.1em; display: flex; align-items: center;
  transition: all var(--transition);
}
.theme-toggle:hover { background: var(--accent-light); }

/* ===== Language Select ===== */
.lang-select {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 12px; font-size: 0.82rem;
  color: var(--text-primary); cursor: pointer;
}

/* ===== Promo Banner (traffic2gift) ===== */
.promo-banner {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: linear-gradient(135deg, #1a0a2e, #3d1a78);
  border-top: 2px solid #ffd700;
  padding: 10px 20px;
  display: flex; align-items: center; justify-content: center; gap: 16px;
  z-index: 1000;
  animation: slideUp 0.5s ease;
}
.promo-banner a { display: flex; align-items: center; gap: 12px; color: white; text-decoration: none; }
.promo-banner .promo-text {
  font-size: 0.9rem; font-weight: 600; color: #ffd700;
}
.promo-banner .promo-cta {
  padding: 8px 20px; background: linear-gradient(135deg, #ffd700, #ff8c00);
  color: #1a0a2e; border-radius: 20px; font-weight: 700; font-size: 0.85rem;
  text-transform: uppercase; white-space: nowrap;
}
.promo-close {
  background: none; border: none; color: rgba(255,255,255,0.6);
  font-size: 1.3rem; cursor: pointer; padding: 5px; position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
}
.promo-close:hover { color: white; }

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ===== Loading ===== */
.loading-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center; z-index: 9999;
}
.loading-overlay.active { display: flex; }
.spinner {
  width: 50px; height: 50px; border: 4px solid rgba(255,255,255,0.3);
  border-top: 4px solid white; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Preview Canvas ===== */
.preview-wrap {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; text-align: center;
  position: sticky; top: calc(var(--header-height) + 24px);
}
.preview-wrap canvas { max-width: 100%; height: auto; border-radius: 8px; }

/* ===== Toast / Notifications ===== */
.toast-container { position: fixed; top: 80px; right: 24px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 20px; border-radius: var(--radius-sm); color: white;
  font-size: 0.88rem; font-weight: 500;
  animation: fadeInRight 0.3s ease;
  box-shadow: var(--shadow-lg);
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }
@keyframes fadeInRight { from { opacity: 0; transform: translateX(50px); } to { opacity: 1; transform: translateX(0); } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  body.rtl .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0 !important; margin-right: 0 !important; }
  .hamburger { display: block; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-section { padding: 16px; }
  .form-row { flex-direction: column; }
  .promo-banner { flex-direction: column; padding: 12px 40px 12px 12px; }
}
@media (max-width: 480px) {
  html { font-size: 14px; }
  .sidebar { width: 100%; }
}
