/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d2e;
  --bg-card: #21243a;
  --bg-input: #2a2d42;
  --text-primary: #e4e4e7;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --accent-dim: rgba(139, 92, 246, 0.15);
  --danger: #ef4444;
  --success: #22c55e;
  --border: #2e3148;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* === Login === */
#app-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f1117 0%, #1a1035 100%);
}

.login-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-box h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
  color: var(--accent-hover);
}

.login-box p { color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 0.9rem; }

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.3rem; }

input[type="text"], input[type="password"], input[type="number"], input[type="tel"], select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

input:focus, select:focus { border-color: var(--accent); }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  color: #fff;
  background: var(--accent);
}

.btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-primary); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* === App Layout === */
#app-main {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 0 1.25rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.sidebar-brand h2 { font-size: 1.1rem; color: var(--accent-hover); }
.sidebar-brand small { font-size: 0.75rem; color: var(--text-muted); }

.sidebar nav { flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1.25rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 0.9rem;
}

.nav-item:hover { background: var(--accent-dim); color: var(--text-primary); }
.nav-item.active { background: var(--accent-dim); color: var(--accent-hover); border-right: 3px solid var(--accent); }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sidebar-footer .user-info { margin-bottom: 0.5rem; color: var(--text-secondary); }

.main-content {
  flex: 1;
  padding: 1.5rem 2rem;
  overflow-y: auto;
  max-height: 100vh;
}

/* === View Header === */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.view-header h2 { font-size: 1.4rem; }
.view-header-filters { display: flex; gap: 0.5rem; align-items: center; }

/* === Stats Bar === */
.stats-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; color: var(--accent-hover); }
.stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); }

/* === Product Cards Grid === */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  display: flex;
  flex-direction: column;
}

.product-card:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(0,0,0,0.4); }

.product-card img {
  width: 100%;
  height: 180px;
  object-fit: contain;
  background: #fff;
  padding: 0.5rem;
}

.badge-discount {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: var(--danger);
  color: #fff;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  z-index: 1;
}

.card-body {
  padding: 0.75rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.card-body h4 {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.price-row { display: flex; align-items: center; gap: 0.5rem; margin-top: auto; }
.price-current { font-size: 1.15rem; font-weight: 700; color: var(--success); }
.price-original { font-size: 0.8rem; color: var(--text-muted); text-decoration: line-through; }

.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: var(--accent-dim);
  color: var(--accent-hover);
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 500;
  width: fit-content;
}

.tag-green { background: rgba(34,197,94,0.15); color: var(--success); }

.card-actions {
  display: flex;
  border-top: 1px solid var(--border);
}

.btn-history, .btn-share {
  flex: 1;
  display: block;
  padding: 0.5rem;
  border: none;
  background: transparent;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-history { color: var(--accent); }
.btn-share { color: var(--success); border-left: 1px solid var(--border); }
.btn-history:hover { background: var(--accent-dim); }
.btn-share:hover { background: rgba(34,197,94,0.15); }

.btn-whatsapp { background: #25D366; }
.btn-whatsapp:hover { background: #1da851; }
.btn-copy { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border); }
.btn-copy:hover { background: var(--accent-dim); border-color: var(--accent); }
.btn-affiliate { background: #f59e0b; color: #000; }
.btn-affiliate:hover { background: #d97706; }

/* === Platform Badge === */
.badge-platform {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  z-index: 1;
  letter-spacing: 0.02em;
}

.platform-tag {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
}

/* === Search Input === */
.search-bar {
  margin-bottom: 1.5rem;
}

.search-bar-row {
  display: flex;
  gap: 0.75rem;
}

.search-bar-row select {
  width: 180px;
  flex-shrink: 0;
  padding: 0.85rem 0.75rem;
  font-size: 0.95rem;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
}

.search-bar-row select:focus { border-color: var(--accent); outline: none; }

.search-bar-row input {
  flex: 1;
  padding: 0.85rem 1.2rem;
  font-size: 1.05rem;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
}

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

.search-bar input {
  width: 100%;
  padding: 0.85rem 1.2rem;
  font-size: 1.05rem;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
}

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

/* === My Searches List === */
.search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  gap: 1rem;
}

.search-info h4 { margin-bottom: 0.25rem; }
.search-meta { display: flex; gap: 0.75rem; flex-wrap: wrap; font-size: 0.8rem; color: var(--text-secondary); align-items: center; }
.search-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* === Notifications === */
.notif-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.25rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--text-muted);
}

.notif-item.notif-sent { border-left-color: var(--success); }
.notif-item.notif-failed { border-left-color: var(--danger); }
.notif-item.notif-pending { border-left-color: var(--accent); }
.notif-info p { font-size: 0.9rem; margin-bottom: 0.25rem; }
.notif-meta { font-size: 0.75rem; color: var(--text-muted); }

/* === Modals === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.modal-content h3 { margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem; }

/* === History Table === */
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.history-table th { color: var(--text-muted); font-weight: 500; font-size: 0.8rem; }

/* === States === */
.loading { text-align: center; padding: 3rem; color: var(--text-muted); }
.empty-state { text-align: center; padding: 3rem; color: var(--text-secondary); }
.empty-state h3 { margin-bottom: 0.5rem; }
.error-state { text-align: center; padding: 2rem; color: var(--danger); }

/* === Checkbox Row === */
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-row input[type="checkbox"] { width: auto; accent-color: var(--accent); }

/* === Settings === */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 600px;
}

.settings-card h3 { margin-bottom: 0.5rem; }
.settings-card code { background: var(--bg-input); padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.85rem; color: var(--accent-hover); }

.status-badge {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-ok { background: rgba(34,197,94,0.15); color: var(--success); }
.status-warning { background: rgba(234,179,8,0.15); color: #eab308; }
.status-error { background: rgba(239,68,68,0.15); color: var(--danger); }

/* === Search Filters === */
.search-filters {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.filter-checkbox input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

.filter-select {
  padding: 0.4rem 0.7rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
}

.filter-select:focus { border-color: var(--accent); outline: none; }

.search-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* === Stat Highlight === */
.stat-highlight .stat-value { color: var(--success); }

/* === Responsive === */
@media (max-width: 768px) {
  #app-main { flex-direction: column; }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 0;
  }

  .sidebar-brand { padding: 0 1rem 0.5rem; }
  .sidebar-brand h2 { font-size: 1rem; }
  .sidebar nav { display: flex; overflow-x: auto; gap: 0; -webkit-overflow-scrolling: touch; }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .nav-item { padding: 0.5rem 0.85rem; white-space: nowrap; border-right: none !important; font-size: 0.8rem; }
  .nav-item.active { border-bottom: 2px solid var(--accent); border-right: none !important; }
  .sidebar-footer { display: none; }

  .main-content { padding: 1rem; max-height: none; }

  /* Stats bar - 2 columns grid on tablet */
  .stats-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
  }
  .stat-card { padding: 0.75rem 1rem; }
  .stat-card .stat-value { font-size: 1.3rem; }
  .stat-card .stat-label { font-size: 0.7rem; }

  /* Products grid */
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem; }

  .search-item { flex-direction: column; align-items: flex-start; }
  .search-actions { width: 100%; justify-content: flex-end; flex-wrap: wrap; }

  .view-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .view-header h2 { font-size: 1.2rem; }
  .view-header-filters { width: 100%; }
  .view-header-filters select { flex: 1; }

  .search-bar-row { flex-direction: column; }
  .search-bar-row select { width: 100%; }

  /* Modal responsive */
  .modal-content { padding: 1.25rem; margin: 0.5rem; }
}

@media (max-width: 480px) {
  .main-content { padding: 0.75rem; }

  /* Stats - horizontal scroll on small phones */
  .stats-bar {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.5rem;
    padding-bottom: 0.25rem;
  }
  .stats-bar::-webkit-scrollbar { display: none; }
  .stat-card {
    min-width: 110px;
    flex-shrink: 0;
    padding: 0.6rem 0.75rem;
  }
  .stat-card .stat-value { font-size: 1.15rem; }

  /* Products - 2 columns */
  .products-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .product-card img { height: 120px; }
  .card-body { padding: 0.5rem 0.65rem; }
  .card-body h4 { font-size: 0.75rem; }
  .price-current { font-size: 0.95rem; }
  .price-original { font-size: 0.7rem; }
  .badge-discount { font-size: 0.7rem; padding: 0.15rem 0.45rem; }
  .badge-platform { font-size: 0.6rem; padding: 0.1rem 0.35rem; }
  .btn-history, .btn-share { font-size: 0.7rem; padding: 0.4rem; }

  /* View header */
  .view-header h2 { font-size: 1.1rem; }
  .view-header-filters { flex-direction: column; }
  .view-header-filters select { width: 100%; }

  /* Login */
  .login-box { padding: 1.5rem; margin: 1rem; }
  .login-box h1 { font-size: 1.25rem; }

  /* Search actions wrap on small */
  .search-actions { gap: 0.35rem; }
  .search-actions .btn { font-size: 0.7rem; padding: 0.3rem 0.55rem; }
}

@media (max-width: 360px) {
  .products-grid { grid-template-columns: 1fr; }
  .product-card { display: flex; flex-direction: row; }
  .product-card img { width: 100px; height: 100px; flex-shrink: 0; }
  .card-body { padding: 0.5rem; }
  .card-actions { flex-direction: column; border-top: none; border-left: 1px solid var(--border); }
  .btn-share { border-left: none; border-top: 1px solid var(--border); }
  .badge-discount { top: 0.25rem; left: 0.25rem; }
  .badge-platform { top: 0.25rem; right: auto; left: 0.25rem; top: 1.8rem; }
}
