/* === Afiliado ML - estilo Mercado Livre === */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #ebebeb;
  --bg-card: #ffffff;
  --bg-soft: #f7f7f7;
  --border: #e6e6e6;
  --border-strong: #d4d4d4;
  --text: #1a1a1a;
  --text-muted: #666;
  --text-faint: #999;
  --blue: #3483fa;
  --blue-dark: #2968c8;
  --blue-soft: #e3edfd;
  --yellow: #fff159;
  --yellow-dark: #f2d600;
  --green: #00a650;
  --red: #f23d4f;
  --red-soft: #fce4e7;
  --orange: #ff7733;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Topbar === */
.topbar {
  background: var(--yellow);
  border-bottom: 1px solid var(--yellow-dark);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: #333;
  cursor: pointer;
}
.brand-icon {
  width: 26px;
  height: 26px;
  background: var(--blue);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
}
.brand-sub {
  color: #555;
  font-size: 12px;
  font-weight: 400;
  margin-left: 4px;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 5px 12px;
  background: rgba(255,255,255,0.7); border-radius: 999px;
  color: #444;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: #999; }
.pill .dot.ok { background: var(--green); }
.pill .dot.err { background: var(--red); }
.pill .dot.warn { background: var(--orange); }

/* === Container === */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.container-narrow { max-width: 880px; margin: 0 auto; padding: 24px; }

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  background: white; border: 1px solid var(--border-strong);
  color: var(--text); font-size: 13px;
  padding: 8px 14px; border-radius: 6px;
  cursor: pointer; font-family: inherit; font-weight: 500;
  transition: all 0.15s;
  text-decoration: none;
}
.btn:hover { background: var(--bg-soft); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--blue); color: white; border-color: var(--blue);
}
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }

.btn-success {
  background: var(--green); color: white; border-color: var(--green);
}
.btn-success:hover { filter: brightness(1.08); }

.btn-danger {
  background: white; color: var(--red); border-color: #ffd0d6;
}
.btn-danger:hover { background: var(--red-soft); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 20px; font-size: 15px; }

/* === Top alert/banner === */
.banner {
  background: #fff8e1; border: 1px solid #ffeaa0;
  border-radius: 8px; padding: 14px 18px; margin-bottom: 20px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.banner.error { background: var(--red-soft); border-color: #fac5cc; }
.banner-text strong { color: var(--text); }
.banner-text { font-size: 13px; }
.banner-text small { color: var(--text-muted); display: block; margin-top: 4px; }

/* === Page header === */
.page-header {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* === Tabs === */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab {
  background: none; border: none; color: var(--text-muted);
  padding: 10px 16px; cursor: pointer; font-size: 13px;
  font-family: inherit; border-bottom: 2px solid transparent; margin-bottom: -1px;
  font-weight: 500;
}
.tab.active { color: var(--text); border-bottom-color: var(--blue); }
.tab .count { color: var(--text-faint); margin-left: 6px; font-size: 11px; font-weight: 400; }
.panel { display: none; }
.panel.active { display: block; }

/* === Product cards (grid) === */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.product-card {
  background: var(--bg-card); border-radius: 8px;
  box-shadow: var(--shadow-sm);
  overflow: hidden; cursor: pointer;
  transition: all 0.15s;
  display: flex; flex-direction: column;
}
.product-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.product-card-img {
  width: 100%; aspect-ratio: 1.2;
  background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  position: relative;
}
.product-card-img img { width: 100%; height: 100%; object-fit: contain; }
.product-card-img-placeholder { color: var(--text-faint); font-size: 13px; }
.product-card-body { padding: 14px; flex: 1; display: flex; flex-direction: column; }
.product-card-name {
  font-size: 14px; font-weight: 500; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 36px;
}
.product-card-categoria { font-size: 11px; color: var(--text-faint); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.product-card-price {
  font-size: 22px; font-weight: 600; color: var(--text);
  margin-top: 12px; line-height: 1;
}
.product-card-price.below-target { color: var(--green); }
.product-card-price-empty { font-size: 13px; color: var(--text-faint); font-weight: 400; margin-top: 12px; }
.product-card-meta {
  display: flex; gap: 10px; margin-top: 10px; font-size: 11px; color: var(--text-muted);
  padding-top: 10px; border-top: 1px solid var(--border);
}
.product-card-meta span { display: inline-flex; align-items: center; gap: 4px; }
.product-card-status { position: absolute; top: 8px; right: 8px; padding: 3px 8px; border-radius: 4px; font-size: 10px; font-weight: 600; text-transform: uppercase; }
.product-card-status.ativo { background: var(--green); color: white; }
.product-card-status.pausado { background: var(--text-faint); color: white; }

/* === Empty state === */
.empty-state {
  text-align: center; padding: 60px 20px;
  background: var(--bg-card); border-radius: 8px;
  box-shadow: var(--shadow-sm);
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-title { font-size: 16px; color: var(--text); font-weight: 600; margin-bottom: 6px; }
.empty-state-body { font-size: 13px; color: var(--text-muted); max-width: 420px; margin: 0 auto 16px; }

/* === Forms === */
.form-section {
  background: var(--bg-card); border-radius: 8px;
  box-shadow: var(--shadow-sm); padding: 24px;
  margin-bottom: 16px;
}
.form-section-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.form-section-subtitle { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-full { grid-column: 1 / -1; }
.form-field { margin-bottom: 14px; }
.form-field label {
  display: block; font-size: 12px; font-weight: 500;
  color: var(--text-muted); margin-bottom: 5px;
}
.form-field input[type=text],
.form-field input[type=url],
.form-field input[type=number],
.form-field textarea,
.form-field select {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border-strong); border-radius: 6px;
  font-size: 14px; font-family: inherit; background: white;
  transition: border-color 0.15s;
}
.form-field input:focus, .form-field textarea:focus, .form-field select:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft);
}
.form-field textarea { resize: vertical; min-height: 120px; font-family: inherit; }
.form-field .hint { font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 16px; }
.form-actions.spread { justify-content: space-between; }

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; vertical-align: middle; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: #ccc; border-radius: 24px; transition: 0.2s; }
.toggle-slider:before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.2s; }
input:checked + .toggle-slider { background: var(--green); }
input:checked + .toggle-slider:before { transform: translateX(20px); }

/* Lista dinâmica (URLs, grupos) */
.dyn-list { display: flex; flex-direction: column; gap: 8px; }
.dyn-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }
.dyn-row.single { grid-template-columns: 1fr auto; }
.dyn-row input { padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 6px; font-size: 13px; font-family: inherit; }
.dyn-row input:focus { outline: none; border-color: var(--blue); }
.dyn-remove {
  background: white; border: 1px solid var(--border-strong); color: var(--red);
  width: 32px; height: 32px; border-radius: 6px; cursor: pointer; font-size: 16px; line-height: 1;
}
.dyn-remove:hover { background: var(--red-soft); border-color: #ffb3bd; }
.dyn-add {
  background: var(--blue-soft); border: 1px dashed var(--blue);
  color: var(--blue); font-weight: 500;
  padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 13px;
  font-family: inherit; margin-top: 8px;
}
.dyn-add:hover { background: #d2e2fb; }

/* Variáveis chips */
.var-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.var-chip {
  background: var(--blue-soft); color: var(--blue); border: 1px solid #c5d8f6;
  padding: 4px 10px; border-radius: 4px; font-size: 11px; font-family: ui-monospace, monospace;
  cursor: pointer;
}
.var-chip:hover { background: #d2e2fb; }
.var-chip-tip {
  display: block; font-size: 10px; color: var(--text-faint); margin-top: 1px;
}

/* Preview WhatsApp */
.wa-preview {
  background: #e5ddd5;
  border-radius: 10px; padding: 16px;
  background-image: linear-gradient(rgba(255,255,255,0.08), rgba(255,255,255,0.08));
  min-height: 120px;
}
.wa-preview-bubble {
  background: #dcf8c6; padding: 10px 14px; border-radius: 8px;
  max-width: 100%; white-space: pre-wrap;
  font-size: 13px; line-height: 1.5;
  box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}
.wa-preview-bubble.empty { background: white; color: var(--text-faint); font-style: italic; }

/* Detail page */
.detail-header {
  background: var(--bg-card); border-radius: 8px; box-shadow: var(--shadow-sm);
  padding: 20px; margin-bottom: 16px;
  display: grid; grid-template-columns: 160px 1fr auto; gap: 20px; align-items: center;
}
.detail-photo {
  width: 160px; height: 160px; background: var(--bg-soft); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.detail-photo img { width: 100%; height: 100%; object-fit: contain; }
.detail-photo-empty { color: var(--text-faint); font-size: 12px; }
.detail-title { font-size: 20px; font-weight: 700; line-height: 1.3; margin-bottom: 4px; }
.detail-categoria { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.detail-stats { display: flex; gap: 20px; margin-top: 14px; }
.detail-stat .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; }
.detail-stat .value { font-size: 18px; font-weight: 600; }
.detail-stat .value.price { color: var(--green); }
.detail-actions { display: flex; flex-direction: column; gap: 8px; }

/* URL table */
.url-table {
  background: var(--bg-card); border-radius: 8px; box-shadow: var(--shadow-sm);
  overflow: hidden; margin-bottom: 16px;
}
.url-table-head {
  display: grid; grid-template-columns: 1fr 110px 100px 130px 80px;
  gap: 12px; padding: 12px 16px; background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; color: var(--text-muted); font-weight: 600;
}
.url-row {
  display: grid; grid-template-columns: 1fr 110px 100px 130px 80px;
  gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border);
  align-items: center; font-size: 13px;
}
.url-row:last-child { border-bottom: none; }
.url-row.cheapest { background: linear-gradient(to right, #fffae0 0%, transparent 30%); position: relative; }
.url-row.cheapest::before {
  content: '🏆 menor'; position: absolute; left: 4px; top: 4px;
  background: var(--yellow); color: #333; font-size: 9px;
  padding: 1px 6px; border-radius: 3px; font-weight: 600;
}
.url-cell-link { overflow: hidden; }
.url-cell-link a { color: var(--blue); font-size: 12px; word-break: break-all; }
.url-cell-link .url-mono { font-family: ui-monospace, monospace; font-size: 11px; color: var(--text-muted); display: block; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-price { font-weight: 600; font-size: 15px; }
.url-price.cheapest-mark { color: var(--green); }
.url-price-original { font-size: 11px; color: var(--text-faint); text-decoration: line-through; margin-top: 2px; }
.url-status { font-size: 11px; font-weight: 600; }
.url-status.ok { color: var(--green); }
.url-status.err { color: var(--red); }

/* Section */
.section {
  background: var(--bg-card); border-radius: 8px; box-shadow: var(--shadow-sm);
  padding: 18px 20px; margin-bottom: 16px;
}
.section-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.section-title .badge { background: var(--bg-soft); color: var(--text-muted); padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; }

/* Alerts list */
.alert-item {
  border-left: 3px solid var(--yellow-dark);
  background: #fffae0; padding: 10px 14px; border-radius: 0 6px 6px 0; margin-bottom: 8px;
}
.alert-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; font-size: 13px; font-weight: 600; }
.alert-time { font-size: 11px; color: var(--text-muted); font-family: ui-monospace, monospace; }
.alert-detail { font-size: 12px; color: var(--text-muted); display: flex; gap: 14px; flex-wrap: wrap; }
.alert-detail b { color: var(--green); font-family: ui-monospace, monospace; }

/* Runs */
.run-item {
  background: var(--bg-card); border-radius: 6px; padding: 10px 14px; margin-bottom: 6px;
  display: grid; grid-template-columns: 200px 1fr; gap: 14px; align-items: center; font-size: 12px;
  border: 1px solid var(--border);
}
.run-time { font-family: ui-monospace, monospace; color: var(--text-muted); }
.run-stats { display: flex; gap: 14px; flex-wrap: wrap; }
.run-stats b { font-family: ui-monospace, monospace; }

/* Foto upload */
.photo-upload {
  width: 100%; aspect-ratio: 1; max-width: 200px;
  background: var(--bg-soft); border: 2px dashed var(--border-strong); border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; position: relative;
}
.photo-upload:hover { border-color: var(--blue); background: var(--blue-soft); }
.photo-upload img { width: 100%; height: 100%; object-fit: contain; }
.photo-upload-text { color: var(--text-muted); font-size: 12px; text-align: center; padding: 10px; }

/* Loader */
.loading { text-align: center; padding: 40px; color: var(--text-faint); }

/* Responsive */
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .detail-header { grid-template-columns: 100px 1fr; }
  .detail-photo { width: 100px; height: 100px; }
  .detail-actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
  .url-table-head { display: none; }
  .url-row { grid-template-columns: 1fr 1fr; gap: 6px; padding: 12px; }
  .url-row > * { font-size: 12px; }
}
