@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;500;600;700;800&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&display=swap');

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

:root {
  --bg: #0a0a12;
  --bg2: #111120;
  --bg3: #1a1a2e;
  --surface: #1e1e32;
  --surface2: #252540;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --text: #e8e8f8;
  --text2: #9898b8;
  --text3: #6060808;
  --accent: #6366f1;
  --accent2: #818cf8;
  --ozon: #005bff;
  --wb: #cb11ab;
  --ali: #ff6900;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 48px rgba(0,0,0,0.6);
  --font: 'DM Sans', system-ui, sans-serif;
  --font-display: 'Syne', system-ui, sans-serif;
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="light"] {
  --bg: #f0f0f8;
  --bg2: #e8e8f5;
  --bg3: #ddddf0;
  --surface: #ffffff;
  --surface2: #f5f5fc;
  --border: rgba(0,0,0,0.08);
  --border2: rgba(0,0,0,0.14);
  --text: #1a1a2e;
  --text2: #55557a;
  --accent: #4f46e5;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 99px; }

/* HEADER */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,18,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
}
[data-theme="light"] .header { background: rgba(240,240,248,0.85); }

.header-left { display: flex; align-items: center; gap: 12px; }
.logo { font-family: var(--font-display); font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.logo span { background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.product-count {
  font-size: 12px; font-weight: 600; 
  background: var(--surface2); color: var(--text2);
  padding: 3px 10px; border-radius: 99px;
  border: 1px solid var(--border);
}
.header-right { display: flex; align-items: center; gap: 8px; }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 14px; font-weight: 600;
  cursor: pointer; border: none; transition: var(--transition);
  text-decoration: none; white-space: nowrap;
}
.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 12px rgba(99,102,241,0.4);
}
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); box-shadow: 0 4px 20px rgba(99,102,241,0.5); }
.btn-ghost {
  background: transparent; color: var(--text2);
  border: 1px solid var(--border2);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-icon { padding: 10px; border-radius: var(--radius-sm); aspect-ratio: 1; }
.btn-danger { background: rgba(239,68,68,0.12); color: var(--red); border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover { background: rgba(239,68,68,0.2); }

/* MAIN LAYOUT */
.main { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }

/* TOOLBAR */
.toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.sort-tabs { display: flex; gap: 4px; background: var(--surface); border-radius: var(--radius-sm); padding: 4px; border: 1px solid var(--border); }
.sort-tab {
  padding: 6px 14px; border-radius: 7px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: var(--transition); color: var(--text2); background: none; border: none;
  font-family: var(--font);
}
.sort-tab.active { background: var(--surface2); color: var(--text); }
.toolbar-right { margin-left: auto; display: flex; gap: 8px; }

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

/* PRODUCT CARD */
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: var(--transition);
  position: relative;
  animation: fadeInUp 0.3s ease forwards;
}
.product-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border2); }

.card-image-wrap {
  position: relative; height: 180px;
  background: var(--bg3); overflow: hidden;
}
.card-image { width: 100%; height: 100%; object-fit: contain; padding: 12px; }
.card-image-placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 48px; opacity: 0.3;
}
.marketplace-badge {
  position: absolute; top: 10px; left: 10px;
  padding: 4px 10px; border-radius: 99px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.5px; text-transform: uppercase;
}
.badge-ozon { background: rgba(0,91,255,0.15); color: #4d8fff; border: 1px solid rgba(0,91,255,0.3); }
.badge-wildberries { background: rgba(203,17,171,0.15); color: #e040d0; border: 1px solid rgba(203,17,171,0.3); }
.badge-aliexpress { background: rgba(255,105,0,0.15); color: #ff8833; border: 1px solid rgba(255,105,0,0.3); }

.status-dot {
  position: absolute; top: 10px; right: 10px;
  width: 10px; height: 10px; border-radius: 50%;
}
.status-reached { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,0.3); animation: pulse 2s infinite; }
.status-above { background: var(--red); }
.status-near { background: var(--yellow); }

.card-body { padding: 16px; }
.card-title {
  font-size: 14px; font-weight: 500; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin-bottom: 14px; line-height: 1.4; min-height: 40px;
}
.card-prices {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 14px;
}
.price-current { 
  font-family: var(--font-display); font-size: 24px; font-weight: 700; 
  line-height: 1;
}
.price-current.reached { color: var(--green); }
.price-current.near { color: var(--yellow); }
.price-current.above { color: var(--text); }
.price-target-block { text-align: right; }
.price-target-label { font-size: 11px; color: var(--text2); margin-bottom: 2px; }
.price-target { font-size: 16px; font-weight: 600; color: var(--text2); }

.price-progress { margin-bottom: 14px; }
.progress-bar-bg { height: 4px; background: var(--bg3); border-radius: 99px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 99px; transition: width 0.5s ease; }
.progress-label { font-size: 11px; color: var(--text2); margin-top: 4px; text-align: right; }

.card-meta { font-size: 12px; color: var(--text2); margin-bottom: 14px; }
.card-actions { display: flex; gap: 8px; }
.btn-visit { flex: 1; padding: 8px 12px; font-size: 13px; }
.btn-refresh { padding: 8px 10px; font-size: 13px; }
.btn-delete { padding: 8px 10px; font-size: 13px; }
.btn-history { padding: 8px 10px; font-size: 13px; }

/* EMPTY STATE */
.empty-state {
  grid-column: 1 / -1; text-align: center; padding: 80px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.empty-icon { font-size: 72px; opacity: 0.4; }
.empty-title { font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.empty-subtitle { color: var(--text2); font-size: 15px; max-width: 360px; }

/* SKELETON */
.skeleton-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.skeleton { background: linear-gradient(90deg, var(--surface2) 25%, var(--bg3) 50%, var(--surface2) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; }
.skeleton-image { height: 180px; }
.skeleton-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.skeleton-line { border-radius: 6px; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 20px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
.modal-header {
  padding: 24px 24px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-family: var(--font-display); font-size: 20px; font-weight: 700; }
.modal-close { background: var(--surface2); border: none; color: var(--text2); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; transition: var(--transition); }
.modal-close:hover { background: var(--surface); color: var(--text); }
.modal-body { padding: 24px; }

/* FORM */
.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text2); margin-bottom: 8px; letter-spacing: 0.3px; text-transform: uppercase; }
.form-input {
  width: 100%; padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--bg3); border: 1.5px solid var(--border2);
  color: var(--text); font-family: var(--font); font-size: 15px;
  transition: var(--transition); outline: none;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.form-input::placeholder { color: var(--text2); }

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn .form-input { flex: 1; }

/* PRODUCT PREVIEW */
.product-preview {
  background: var(--bg3); border-radius: var(--radius-sm); border: 1px solid var(--border);
  padding: 16px; margin-bottom: 20px;
  display: flex; gap: 14px; align-items: flex-start;
  animation: fadeIn 0.2s ease;
}
.preview-image { width: 72px; height: 72px; border-radius: 8px; object-fit: contain; flex-shrink: 0; background: var(--surface2); }
.preview-info { flex: 1; min-width: 0; }
.preview-title { font-size: 14px; font-weight: 500; margin-bottom: 4px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-price { font-family: var(--font-display); font-size: 20px; font-weight: 700; color: var(--accent2); }
.preview-mp { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* DISCOUNT SLIDER */
.discount-presets { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.preset-btn {
  padding: 6px 14px; border-radius: 99px; font-size: 13px; font-weight: 600;
  background: var(--surface2); border: 1.5px solid var(--border2); color: var(--text2);
  cursor: pointer; transition: var(--transition);
}
.preset-btn:hover, .preset-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* SETTINGS PANEL */
.settings-panel {
  position: fixed; right: 0; top: 0; bottom: 0; z-index: 200;
  width: 380px; background: var(--bg2); border-left: 1px solid var(--border2);
  box-shadow: -8px 0 40px rgba(0,0,0,0.5);
  transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  overflow-y: auto;
}
.settings-panel.open { transform: translateX(0); }
.settings-header { padding: 20px 20px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.settings-body { padding: 20px; }
.settings-section { margin-bottom: 28px; }
.settings-section-title { font-family: var(--font-display); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text2); margin-bottom: 14px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle-label { font-size: 14px; font-weight: 500; }
.toggle-desc { font-size: 12px; color: var(--text2); margin-top: 2px; }
.toggle { position: relative; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--surface2); border-radius: 99px; cursor: pointer; transition: var(--transition); }
.toggle-slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: var(--text2); border-radius: 50%; transition: var(--transition); }
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); background: #fff; }

/* HISTORY MODAL */
.history-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--bg3); border-radius: var(--radius-sm); padding: 14px; border: 1px solid var(--border); }
.stat-label { font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.stat-value { font-family: var(--font-display); font-size: 22px; font-weight: 700; }
.stat-min { color: var(--green); }
.stat-max { color: var(--red); }
.chart-wrap { background: var(--bg3); border-radius: var(--radius-sm); padding: 16px; border: 1px solid var(--border); margin-bottom: 20px; }
.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history-table th { text-align: left; padding: 8px 12px; color: var(--text2); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
.history-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.history-table tr:last-child td { border-bottom: none; }
.change-positive { color: var(--red); font-weight: 600; }
.change-negative { color: var(--green); font-weight: 600; }

/* TOAST */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: 14px 18px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-lg); min-width: 280px; max-width: 380px;
  animation: slideInRight 0.3s ease;
  font-size: 14px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }
.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast-dismiss { margin-left: auto; background: none; border: none; color: var(--text2); cursor: pointer; font-size: 16px; padding: 0 4px; }

/* LOADING OVERLAY */
.loading-overlay { position: absolute; inset: 0; background: rgba(10,10,18,0.6); border-radius: inherit; display: flex; align-items: center; justify-content: center; z-index: 10; }
.spinner { width: 24px; height: 24px; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }

/* HINT BOX */
.hint-box { background: rgba(99,102,241,0.08); border: 1px solid rgba(99,102,241,0.2); border-radius: var(--radius-sm); padding: 12px 16px; font-size: 13px; color: var(--text2); line-height: 1.6; }
.hint-box a { color: var(--accent2); text-decoration: none; }
.hint-box a:hover { text-decoration: underline; }

/* PULL TO REFRESH */
.ptr-indicator {
  text-align: center; padding: 12px; font-size: 13px; color: var(--text2);
  overflow: hidden; max-height: 0; transition: max-height 0.3s ease;
}
.ptr-indicator.visible { max-height: 60px; }

/* ANIMATIONS */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(34,197,94,0.3); }
  50% { box-shadow: 0 0 0 6px rgba(34,197,94,0.1); }
}

/* RESPONSIVE */
@media (max-width: 640px) {
  .header { padding: 0 16px; }
  .main { padding: 16px; }
  .products-grid { grid-template-columns: 1fr; }
  .settings-panel { width: 100%; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-right { margin-left: 0; }
  .sort-tabs { justify-content: center; }
}
