:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e3e8f0;
  --text: #1c2434;
  --muted: #6b7686;
  --primary: #3b5bff;
  --primary-hover: #2c49e6;
  --secondary: #eef1fb;
  --danger: #e5484d;
  --ok: #2b8a5b;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.06), 0 8px 24px rgba(20, 30, 60, 0.05);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eef2fc, #f7f8fc);
  z-index: 50;
}
.login-card {
  width: 320px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-title { margin: 0; font-size: 20px; text-align: center; }
.login-sub { margin: 0; text-align: center; color: var(--muted); font-size: 13px; }
.login-error { margin: 0; text-align: center; color: var(--danger); font-size: 13px; }

/* ---------- Layout ---------- */
.topbar {
  height: 60px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 4px rgba(59, 91, 255, 0.15);
}
.container { max-width: 1080px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---------- Filters ---------- */
.filters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 160px auto;
  gap: 16px;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field-label em { color: var(--danger); font-style: normal; }
.field-action { align-self: end; }
.hint { margin: 12px 0 0; font-size: 12px; color: var(--muted); }

.input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 91, 255, 0.12); }

/* ---------- Buttons ---------- */
.btn {
  height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: var(--primary); border-color: var(--border); }
.btn-secondary:not(:disabled):hover { background: #e3e8fb; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--secondary); }
.btn-block { width: 100%; }
.btn-row {
  height: 32px; padding: 0 12px; font-size: 13px;
  background: var(--secondary); color: var(--primary); border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer;
}
.btn-row:hover { background: #e3e8fb; }
.btn-row:disabled { opacity: .5; cursor: progress; }

/* ---------- Results ---------- */
.results-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.results-count { font-weight: 600; }
.results-actions { display: flex; gap: 10px; }

.result-filters {
  display: grid;
  grid-template-columns: repeat(4, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  margin-bottom: 14px;
  background: #fafbff;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.rf-field { display: flex; flex-direction: column; gap: 5px; }
.rf-label { font-size: 11px; color: var(--muted); font-weight: 500; }
.rf-field .input { height: 36px; font-size: 13px; }
.rf-reset { align-self: end; }
.rf-reset .btn { height: 36px; }

/* Multi-select dropdown (agent filter) */
.ms { position: relative; }
.ms-toggle {
  text-align: left;
  cursor: pointer;
  background: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 26px;
}
.ms-toggle::after {
  content: "▾";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.ms-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
}
.ms-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.ms-option:hover { background: var(--secondary); }
.ms-option input { cursor: pointer; margin: 0; }

.bulk-panel {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 14px; margin-bottom: 14px;
  background: var(--secondary); border: 1px solid var(--border); border-radius: 8px;
}
.bulk-row { display: flex; align-items: center; gap: 12px; flex: 1; }
.progress { flex: 1; height: 8px; background: #dfe4f3; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: var(--primary); transition: width .3s ease; }
.bulk-text { font-size: 13px; color: var(--muted); min-width: 120px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: #fafbff; }
.table .col-action { text-align: right; }
.table td.col-action { text-align: right; }
.empty-row td { text-align: center; color: var(--muted); padding: 32px; }

.table .col-select { width: 36px; text-align: center; }
.table td.col-select, .table th.col-select { text-align: center; }
.table tbody tr.selectable { cursor: default; }
.table tbody tr.selected { background: #eaf0ff; }
.table tbody tr.selected:hover { background: #e1eaff; }
/* Prevent text-selection while drag-selecting rows. */
.table.selecting { user-select: none; }
.row-check { cursor: pointer; }

.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; background: var(--secondary); color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1c2434; color: #fff; padding: 12px 20px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow); z-index: 80; max-width: 90vw;
}

@media (max-width: 760px) {
  .filters-grid { grid-template-columns: 1fr 1fr; }
  .field-action { grid-column: 1 / -1; }
  .field-action .btn { width: 100%; }
  .result-filters { grid-template-columns: 1fr 1fr; }
  .rf-reset { grid-column: 1 / -1; }
}
