/* Scale Winners — Phase 1 + 1.5 + 1.6 + 1.7 styles
   App Shell (sidebar) styles → ./app-shell.css (shared)
*/

/* Override KPI grid: Scale Winners chỉ có 4 KPI (không phải 6 như do-luong) */
.app-main .dl-kpi-grid {
  grid-template-columns: repeat(4, 1fr);
}

/* Compact section spacing để tận dụng full screen */
.dl-header {
  padding: 8px 0 4px !important;
}
.dl-toolbar,
.sw-filters,
.sw-bulk {
  margin: 8px 0 !important;
}

.sw-filters {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px 16px;
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sw-filter-group {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 13px;
}

.sw-filter-group strong {
  color: #374151;
  min-width: 120px;
}

.sw-filter-group label {
  cursor: pointer;
  color: #4b5563;
}

.sw-filter-group input[type="radio"] {
  margin-right: 4px;
  cursor: pointer;
}

/* ===== Account Dropdown (Phase 1.6c — searchable multi-select) ===== */
.sw-acc-dropdown {
  position: relative;
  display: inline-block;
}

.sw-acc-trigger {
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 240px;
  text-align: left;
}

.sw-acc-trigger:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.sw-acc-trigger .sw-acc-caret {
  margin-left: auto;
  color: #9ca3af;
  font-size: 10px;
}

.sw-acc-trigger.active {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1e40af;
  font-weight: 500;
}

.sw-acc-panel {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  width: 360px;
  max-height: 420px;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

/* Override default display:flex khi attribute [hidden] được set
   (vì display:flex có specificity cao hơn HTML5 hidden) */
.sw-acc-panel[hidden] {
  display: none !important;
}

.sw-acc-panel-head {
  padding: 10px 12px;
  border-bottom: 1px solid #f3f4f6;
}

.sw-acc-panel-head input[type="text"] {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
}

.sw-acc-quick {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
}

.btn-link {
  background: none;
  border: none;
  color: #2563eb;
  cursor: pointer;
  padding: 0;
  font-size: 12px;
  text-decoration: underline;
}
.btn-link:hover { color: #1d4ed8; }

.sw-acc-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  max-height: 260px;
}

.sw-acc-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.sw-acc-list label:hover {
  background: #f9fafb;
  border-left-color: #93c5fd;
}

.sw-acc-list label.checked {
  background: #eff6ff;
  border-left-color: #2563eb;
}

.sw-acc-list input[type="checkbox"] {
  cursor: pointer;
  flex-shrink: 0;
}

.sw-acc-list .acc-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sw-acc-list .acc-id {
  color: #9ca3af;
  font-size: 10px;
  font-family: monospace;
  flex-shrink: 0;
}

.sw-acc-list .empty-search {
  padding: 16px;
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
}

.sw-acc-panel-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-top: 1px solid #f3f4f6;
  background: #f9fafb;
  border-radius: 0 0 8px 8px;
}


.sw-bulk {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  background: #fff7e6;
  border: 1px solid #ffd591;
  border-radius: 8px;
  margin: 12px 0;
}

.sw-table-wrap {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow-x: auto;            /* horizontal scroll khi nhiều cột */
  margin-bottom: 16px;
}

.sw-table {
  width: 100%;
  min-width: 1400px;           /* đảm bảo bảng đủ rộng cho ~14 cột */
  border-collapse: collapse;
  font-size: 13px;
}

.sw-table th,
.sw-table td {
  padding: 8px 8px;
  border-bottom: 1px solid #f3f4f6;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.sw-table th[title] {
  cursor: help;
  border-bottom: 2px solid transparent;
}
.sw-table th[title]:hover {
  border-bottom: 2px dotted #9ca3af;
}

.sw-table th {
  background: #f9fafb;
  font-weight: 600;
  font-size: 12px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sw-table tr:hover td {
  background: #fafbfc;
}

.sw-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sw-verdict-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.sw-verdict-scale    { background: #dcfce7; color: #166534; }
.sw-verdict-increase { background: #dbeafe; color: #1e40af; }
.sw-verdict-keep     { background: #f3f4f6; color: #4b5563; }
.sw-verdict-watch    { background: #fef3c7; color: #92400e; }
.sw-verdict-kill     { background: #fee2e2; color: #991b1b; }

/* Visual separator giữa winners và rest */
.sw-table tr.sw-divider td {
  background: #fafbfc;
  text-align: center;
  font-size: 11px;
  color: #6b7280;
  font-style: italic;
  padding: 6px;
  border-bottom: 2px dashed #e5e7eb;
}

.sw-actions {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.sw-actions .btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.sw-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.sw-name-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sw-name-cell .ad-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sw-name-cell .ad-name {
  font-weight: 500;
  color: #111827;
}

.sw-name-cell .campaign-name {
  font-size: 12px;
  color: #6b7280;
  margin-top: 3px;
}

.sw-name-cell .acc-tag {
  font-size: 11px;
  color: #4f46e5;
  background: #eef2ff;
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  margin-top: 4px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

/* ==== STATUS BADGE (Phase 1.8) ==== */
.sw-status-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.sw-status-badge.status-active {
  background: #dcfce7;
  color: #166534;
}
.sw-status-badge.status-paused {
  background: #f3f4f6;
  color: #6b7280;
}
.sw-status-badge.status-paused-parent {
  background: #fee2e2;
  color: #991b1b;
}
.sw-status-badge.status-issue {
  background: #fef3c7;
  color: #92400e;
  animation: pulse-warn 2s infinite;
}
.sw-status-badge.status-pending {
  background: #dbeafe;
  color: #1e40af;
}
.sw-status-badge.status-archived {
  background: #f3f4f6;
  color: #9ca3af;
  text-decoration: line-through;
}
.sw-status-badge.status-unknown {
  background: #f9fafb;
  color: #9ca3af;
  font-style: italic;
}

@keyframes pulse-warn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Modal customization grid */
.clone-form {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px 16px;
  align-items: center;
  margin-top: 8px;
}

.clone-form label {
  font-size: 13px;
  font-weight: 500;
  color: #374151;
}

.clone-form .clone-source-info {
  grid-column: 1 / -1;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
}

.clone-form .clone-source-info strong {
  color: #111827;
}

.clone-form input[type="number"] {
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  width: 100px;
}

.clone-form .age-pair {
  display: flex;
  gap: 8px;
  align-items: center;
}

.clone-form .age-pair span {
  color: #6b7280;
}

.clone-form .gender-radio label {
  font-weight: 400;
  margin-right: 16px;
  cursor: pointer;
}

.clone-form .schedule-grid {
  display: flex;
  gap: 8px;
  align-items: center;
}

.clone-form .deferred-note {
  grid-column: 1 / -1;
  font-size: 12px;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 8px 10px;
}

.clone-payload-preview {
  margin-top: 12px;
  background: #1e293b;
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 12px;
  border-radius: 6px;
  max-height: 300px;
  overflow: auto;
  white-space: pre;
}

.clone-payload-preview h4 {
  color: #94a3b8;
  font-size: 11px;
  text-transform: uppercase;
  margin: 0 0 8px;
  font-weight: 600;
}

.modal-footer {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 20px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

.dryrun-active {
  color: #1e40af;
}

.dryrun-off {
  color: #b91c1c;
  font-weight: 600;
}

#btn-toggle-dryrun.dryrun-off-btn {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

/* Phase 2.0.2 — Modal clone 2-col layout: Form | FB Structure preview */
.modal-card-wide {
  max-width: 1100px !important;
  width: 96vw;
}

.clone-modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .clone-modal-grid { grid-template-columns: 1fr; }
}

.clone-modal-left {
  min-width: 0;
}

.clone-modal-right {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 14px;
  max-height: 480px;
  overflow-y: auto;
}

.cf-fb-title {
  font-size: 13px;
  margin: 0 0 10px;
  color: #374151;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
}

.fb-structure {
  font-size: 12.5px;
  color: #374151;
}

.fb-section {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px dashed #e5e7eb;
}
.fb-section:last-child { border-bottom: none; }
.fb-section h4 {
  font-size: 12px;
  margin: 0 0 6px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.fb-row {
  margin: 3px 0;
  line-height: 1.4;
}
.fb-key {
  color: #9ca3af;
  margin-right: 4px;
}

.fb-stat-active {
  color: #047857;
  font-weight: 600;
}
.fb-stat-paused {
  color: #b45309;
  font-weight: 600;
}

.fb-adset {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
}
.fb-adset-name {
  font-weight: 600;
  font-size: 12.5px;
  color: #111827;
  margin-bottom: 4px;
}
.fb-adset-targeting {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 11.5px;
  color: #4b5563;
}
.fb-adset-targeting span b {
  color: #1f2937;
}

/* Phase 2.1c — Per-adset edit cards trong clone modal */
.cf-section-title {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
  margin: 16px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e5e7eb;
}

#cf-per-adset-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.cf-adset-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
}

.cf-adset-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px dashed #e5e7eb;
}
.cf-adset-head strong {
  font-size: 13px;
  color: #111827;
}
.cf-adset-head .muted-sm {
  font-size: 11px;
  color: #6b7280;
}

.cf-adset-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  font-size: 12px;
}

.cf-adset-form label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
  color: #4b5563;
}

.cf-adset-form input[type="number"] {
  width: 70px;
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 12px;
}

.cf-adset-form .age-input {
  width: 50px;
}

.cf-adset-form select {
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 12px;
  background: #fff;
}

.cf-fallback-section {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 12px;
}

/* Phase 2.2 — Sở thích/Hành vi autocomplete + chips + Schedule */
.cf-target-section,
.cf-schedule-section {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed #f3f4f6;
}
.cf-target-section > label,
.cf-schedule-section > label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}
.cf-search-wrap {
  position: relative;
}
.cf-search-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
}
.cf-search-input:focus {
  border-color: #6366f1;
  outline: 2px solid #c7d2fe;
}
.cf-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 2px;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.cf-search-results[hidden] { display: none; }
.cf-search-item {
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
}
.cf-search-item:last-child { border-bottom: none; }
.cf-search-item:hover { background: #eef2ff; }
.cf-aud {
  color: #9ca3af;
  font-size: 11px;
  font-family: monospace;
  margin-left: 6px;
}
.cf-search-loading,
.cf-search-empty {
  padding: 10px;
  font-size: 12px;
  color: #9ca3af;
  text-align: center;
  font-style: italic;
}

.cf-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  min-height: 22px;
}
.cf-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 8px;
  background: #eef2ff;
  color: #4338ca;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.cf-chip-remove {
  background: transparent;
  border: 0;
  color: #6366f1;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 3px;
}
.cf-chip-remove:hover {
  background: rgba(99, 102, 241, 0.2);
  color: #1e1b4b;
}

.cf-schedule-custom {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
}
.cf-schedule-custom .hour-input {
  width: 50px;
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 12px;
}
