/* ============================================================
   Thanh loc nhieu dieu kien - tab "Theo Ngay"
   Dung lai token theme cua dashboard (:root / body.light-theme)
   de khop voi phan con lai, khong tu dinh nghia mau rieng.
   ============================================================ */

:root {
  --dbf-accent: #60a5fa;
  --dbf-accent-strong: #2563eb;
  --dbf-chip-bg: rgba(96, 165, 250, 0.16);
  --dbf-chip-fg: #bfdbfe;
  --dbf-chip-border: rgba(96, 165, 250, 0.32);
  --dbf-danger: #fca5a5;
  --dbf-danger-bg: rgba(239, 68, 68, 0.16);
  --dbf-ring: rgba(96, 165, 250, 0.35);
  /* Chu phu: du tuong phan >= 4.5:1 tren nen cua ca hai theme. */
  --dbf-muted-fg: #94a3b8;
}

body.light-theme {
  --dbf-accent: #2563eb;
  --dbf-accent-strong: #1d4ed8;
  --dbf-chip-bg: rgba(37, 99, 235, 0.09);
  --dbf-chip-fg: #1d4ed8;
  --dbf-chip-border: rgba(37, 99, 235, 0.22);
  --dbf-danger: #b91c1c;
  --dbf-danger-bg: rgba(220, 38, 38, 0.1);
  --dbf-ring: rgba(37, 99, 235, 0.25);
  --dbf-muted-fg: #475569;
}

/* --- Nhan truong (input khong duoc chi dua vao placeholder) --- */

.dbf-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.dbf-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--dbf-chip-bg);
  color: var(--dbf-chip-fg);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}

/* --- Khu chip: rieng mot hang, khong chen vao o nhap --- */

.dbf-chip-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0;
}

.dbf-chip-row-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  margin-right: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--dbf-muted-fg);
}

.dbf-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

/* --- O tim kiem: luon full width, khong bao gio bi co lai --- */

.dbf-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 6px 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.dbf-bar:focus-within {
  border-color: var(--dbf-accent);
  box-shadow: 0 0 0 3px var(--dbf-ring);
}

.dbf-search-icon {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  color: var(--dbf-muted-fg);
}

/* --- Chip dieu kien --- */

.dbf-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  /* Nhan co the co lai nhung khong bao gio xuong dong thu hai. */
  min-width: 0;
  max-width: 100%;
  padding: 0 2px 0 10px;
  border: 1px solid var(--dbf-chip-border);
  border-radius: 999px;
  background: var(--dbf-chip-bg);
  color: var(--dbf-chip-fg);
  font-size: 12px;
  font-weight: 600;
  line-height: 26px;
  animation: dbf-chip-in 0.16s ease-out;
}

@keyframes dbf-chip-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: none; }
}

.dbf-chip-field {
  flex-shrink: 0;
  opacity: 0.75;
  font-weight: 500;
}

.dbf-chip-op {
  flex-shrink: 0;
  margin: 0 3px;
  opacity: 0.6;
  font-weight: 500;
}

.dbf-chip-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dbf-chip-remove {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.dbf-chip-remove svg { width: 11px; height: 11px; }
.dbf-chip-remove:hover { background: var(--dbf-danger-bg); color: var(--dbf-danger); }
.dbf-chip-remove:focus-visible { outline: 2px solid var(--dbf-accent); outline-offset: 1px; }

/* --- O nhap --- */

.dbf-search {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  outline: none;
}

.dbf-search::placeholder { color: var(--dbf-muted-fg); opacity: 1; }

.dbf-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.dbf-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--dbf-muted-fg);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, background-color 0.12s ease;
}

.dbf-icon-btn svg { width: 13px; height: 13px; }
.dbf-icon-btn:hover { border-color: var(--dbf-accent); color: var(--dbf-accent); background: var(--bg-hover); }
.dbf-icon-btn:focus-visible { outline: 2px solid var(--dbf-accent); outline-offset: 1px; }
.dbf-icon-btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.dbf-icon-btn[disabled]:hover { border-color: var(--border); color: var(--dbf-muted-fg); background: transparent; }

/* --- Menu chon truong --- */

.dbf-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 60;
  max-height: 360px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--filter-dropdown-bg);
  color: var(--filter-dropdown-text);
  box-shadow: 0 16px 40px var(--shadow);
  animation: dbf-menu-in 0.14s ease-out;
}

/* Reuse the date filters inside the compact Ads popover without stretching it. */
#adsCampaignFilterBar { height: 34px; border-radius: 8px; padding-left: 8px; }
#adsCampaignFilterBar .dbf-search-icon { display: none; }
#adsCampaignFilterBar .dbf-icon-btn { font-size: 0; gap: 0; padding: 0 5px; border: 0; }
#adsCampaignFilterMenu { width: min(360px, calc(100vw - 48px)); right: auto; max-height: min(360px, 55vh); }
#adsCampaignFilterChipRow { margin-top: 8px; }
#adsCampaignFilterChipRow[hidden], .dbf-field [hidden] { display: none !important; }
#adsCampaignFilterMenu .dbf-select { max-width: 100%; }
#adsCampaignFilterMenu .dbf-value { width: 100%; min-width: 0; }
@media (max-width: 760px) {
  #adsCampaignFilterMenu { left: auto; right: 0; }
}

@keyframes dbf-menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.dbf-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dbf-muted-fg);
}

.dbf-menu-empty {
  padding: 12px 10px;
  font-size: 12px;
  color: var(--dbf-muted-fg);
}

.dbf-field-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.dbf-field-option:hover,
.dbf-field-option:focus-visible,
.dbf-field-option[data-active="true"] {
  background: var(--filter-option-hover);
  outline: none;
}

.dbf-field-option:focus-visible { box-shadow: inset 0 0 0 2px var(--dbf-accent); }

.dbf-field-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 7px;
  background: var(--dbf-chip-bg);
  color: var(--dbf-chip-fg);
}

.dbf-field-icon svg { width: 14px; height: 14px; }
.dbf-field-kind { margin-left: auto; font-size: 10px; color: var(--dbf-muted-fg); }

/* --- Buoc 2: dieu kien + gia tri --- */

.dbf-draft-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 8px;
  font-size: 13px;
  font-weight: 700;
}

.dbf-back {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.dbf-back svg { width: 15px; height: 15px; }
.dbf-back:hover { background: var(--filter-option-hover); }
.dbf-back:focus-visible { outline: 2px solid var(--dbf-accent); outline-offset: 1px; }

.dbf-draft-body {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 4px 6px;
}

.dbf-select,
.dbf-value {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
}

.dbf-select { flex: 0 0 auto; cursor: pointer; }
.dbf-value { flex: 1 1 170px; min-width: 140px; }

.dbf-select:focus-visible,
.dbf-value:focus-visible {
  outline: none;
  border-color: var(--dbf-accent);
  box-shadow: 0 0 0 3px var(--dbf-ring);
}

.dbf-hint {
  width: 100%;
  padding: 0 4px 6px;
  font-size: 11px;
  color: var(--dbf-muted-fg);
}

.dbf-apply {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--dbf-accent-strong);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.dbf-apply:hover { filter: brightness(1.08); }
.dbf-apply:focus-visible { outline: 2px solid var(--dbf-accent); outline-offset: 2px; }

/* --- Bo loc da luu --- */

.dbf-presets {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.dbf-preset { display: flex; align-items: center; gap: 4px; }

.dbf-preset-apply {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 38px;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.dbf-preset-apply:hover,
.dbf-preset-apply:focus-visible { background: var(--filter-option-hover); outline: none; }
.dbf-preset-apply:focus-visible { box-shadow: inset 0 0 0 2px var(--dbf-accent); }
.dbf-preset-apply strong { font-size: 13px; }

.dbf-preset-apply small {
  font-size: 11px;
  color: var(--dbf-muted-fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dbf-preset-remove {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--dbf-muted-fg);
  cursor: pointer;
}

.dbf-preset-remove svg { width: 13px; height: 13px; }
.dbf-preset-remove:hover { background: var(--dbf-danger-bg); color: var(--dbf-danger); }
.dbf-preset-remove:focus-visible { outline: 2px solid var(--dbf-accent); outline-offset: 1px; }

/* --- Man hinh cam tay: vung cham >= 44px --- */

@media (pointer: coarse) {
  .dbf-chip { line-height: 34px; }
  .dbf-chip-remove { width: 30px; height: 30px; }
  .dbf-icon-btn { height: 40px; padding: 0 14px; }
  .dbf-field-option { min-height: 44px; }
  .dbf-preset-apply { min-height: 44px; }
  .dbf-preset-remove { width: 40px; height: 40px; }
  .dbf-back { width: 40px; height: 40px; }
  .dbf-select, .dbf-value, .dbf-apply { height: 44px; }
}

@media (max-width: 640px) {
  .dbf-icon-btn { padding: 0 8px; font-size: 0; gap: 0; }
  .dbf-icon-btn svg { width: 15px; height: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .dbf-bar,
  .dbf-chip,
  .dbf-menu,
  .dbf-chip-remove,
  .dbf-icon-btn,
  .dbf-field-option,
  .dbf-preset-apply,
  .dbf-apply { transition: none; animation: none; }
}
