:root {
  --bg-a: #f4f8ff;
  --bg-b: #f0fffb;
  --text: #102235;
  --muted: #4d647a;
  --card: #ffffff;
  --border: #d4e1f3;
  --primary: #0a84ff;
  --primary-dark: #066ed1;
  --danger: #b4233b;
  --danger-dark: #8f1b30;
  --success: #0a9f73;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--text);
  background: linear-gradient(145deg, var(--bg-a), var(--bg-b));
}

code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.9em;
}

.backend-info {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 0.5rem 0;
}

.page-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 8% 12%, rgba(10, 132, 255, 0.18) 0%, transparent 36%),
    radial-gradient(circle at 88% 8%, rgba(10, 159, 115, 0.16) 0%, transparent 34%),
    radial-gradient(circle at 50% 100%, rgba(10, 132, 255, 0.1) 0%, transparent 40%);
}

.container {
  position: relative;
  z-index: 1;
  max-width: 1220px;
  margin: 0 auto;
  padding: 26px 16px 32px;
  display: grid;
  gap: 14px;
}

.card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 14px 30px rgba(16, 34, 53, 0.08);
  padding: 16px;
}

.hero h1 {
  margin: 8px 0;
  font-size: clamp(1.6rem, 2.8vw, 2.1rem);
}

.hero .subtitle {
  margin: 0;
  color: var(--muted);
  max-width: 920px;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #0d8f70;
  font-weight: 700;
}

h2 {
  margin: 0 0 10px;
  font-size: 1.18rem;
}

h3 {
  margin: 16px 0 8px;
  font-size: 1rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.86rem;
  color: var(--muted);
}

.checkbox-label {
  justify-content: center;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #b8c9de;
  border-radius: 8px;
  padding: 8px 9px;
  background: #ffffff;
  color: var(--text);
}

.checkbox-row input[type="checkbox"] {
  margin: 0;
}

.checkbox-row small {
  line-height: 1.3;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border: 1px solid #b8c9de;
  border-radius: 8px;
  padding: 8px 9px;
  background: #ffffff;
  color: var(--text);
}

.controls,
.hero-actions {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.reward-policy {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #f9fbff;
}

.reward-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.reward-grid label {
  font-size: 0.82rem;
}

.reward-grid input[type="range"] {
  width: 100%;
  padding: 0;
}

.reward-value {
  margin-top: 4px;
  display: inline-block;
  font-weight: 700;
  color: #26425f;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 13px;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.14s ease, transform 0.12s ease;
}

.btn:hover:not([disabled]) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not([disabled]) {
  background: var(--primary-dark);
}

.btn-secondary {
  background: #ffffff;
  border-color: var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover:not([disabled]) {
  background: var(--danger-dark);
}

.status-head,
.results-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-kpis {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.status-kpis p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.job-id {
  font-size: 0.82rem;
  color: #3f5a74;
  font-family: Consolas, "Courier New", monospace;
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e7eef8;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #0780c4 0%, #16aa78 100%);
  transition: width 0.24s ease;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.error {
  margin: 8px 0 0;
  color: var(--danger);
  font-weight: 700;
  font-size: 0.88rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: #f9fbff;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  margin-bottom: 4px;
}

.summary-card strong {
  display: block;
  font-size: 1rem;
}

.table-wrap {
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: min(62vh, 760px);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
  table-layout: fixed;
  background: #ffffff;
}

th,
td {
  border-bottom: 1px solid #e4ecf8;
  padding: 6px 7px;
  font-size: clamp(0.68rem, 0.78vw, 0.78rem);
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
}

th {
  background: #f2f7ff;
  color: #26425f;
  position: sticky;
  top: 0;
  z-index: 1;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable::after {
  content: " \21C5";
  font-size: 0.72rem;
  opacity: 0.45;
}

th.sortable.sorted-asc::after {
  content: " \2191";
  opacity: 0.9;
}

th.sortable.sorted-desc::after {
  content: " \2193";
  opacity: 0.9;
}

tbody tr:nth-child(odd) {
  background: #fcfdff;
}

.good {
  color: var(--success);
  font-weight: 700;
}

.bad {
  color: var(--danger);
  font-weight: 700;
}

.open-online-banner {
  margin-bottom: 1rem;
  padding: 1rem 1.25rem;
  background: #fff8e6;
  border: 1px solid #e6c200;
  border-radius: 10px;
  color: #5c4a00;
}

.open-online-banner a {
  color: var(--primary-dark);
  font-weight: 700;
}

.backend-status {
  margin: 0 0 0.75rem 0;
  font-size: 0.88rem;
}

.backend-status.ok {
  color: var(--success);
}

.backend-status.fail {
  color: var(--danger);
}

#data-source-panel {
  border-left: 4px solid var(--accent, #2563eb);
}
#data-source-panel .ds-toggle {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f2f7ff;
  color: #214361;
  font-weight: 700;
  padding: 8px 10px;
  cursor: pointer;
}
#data-source-panel h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
}
.ds-block {
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  line-height: 1.6;
}
.ds-block code {
  font-size: 0.78rem;
  word-break: break-all;
}
.ds-block .good { color: #16a34a; font-weight: 600; }
.ds-block .warn { color: #d97706; font-weight: 600; }
.ds-block .bad { color: #dc2626; font-weight: 600; }
.warn-block {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
}
.warn-block ul { margin: 0.25rem 0 0 1.2rem; padding: 0; }
.ds-errors { margin: 0.25rem 0 0 1.2rem; padding: 0; }

.table-section {
  margin-top: 10px;
}

.table-section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.table-section-head .table-section-toggle {
  flex: 1;
  min-width: 0;
}

.table-section-csv {
  display: flex;
  gap: 4px;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.8rem;
}

.results-export {
  display: flex;
  gap: 6px;
}

.domain-filters {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.domain-filters label {
  min-width: 180px;
}

.domain-filters input {
  min-width: 180px;
}

.domain-filter-status {
  font-size: 0.8rem;
  color: var(--muted);
}

.table-section-toggle {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f2f7ff;
  color: #214361;
  font-weight: 700;
  padding: 9px 11px;
  cursor: pointer;
}

.table-section-panel {
  margin-top: 8px;
}

.table-pager {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-pager span {
  font-size: 0.8rem;
  color: var(--muted);
}

.history-notice {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: #6b4f00;
}

.keyword-library-meta {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.keyword-row-active {
  background: rgba(22, 163, 74, 0.12) !important;
}

.perf-token {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  color: #ffffff;
  font-weight: 700;
  line-height: 1.3;
}

/* Underpriced domain highlighting */
.underpriced-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  background: #059669;
  color: #fff;
  vertical-align: middle;
  margin-left: 4px;
}
.underpriced-row {
  background: rgba(5, 150, 105, 0.06);
}
.underpriced-row:hover {
  background: rgba(5, 150, 105, 0.12);
}
td.est-val {
  font-weight: 600;
  color: #1d4ed8;
  cursor: help;
}

/* Column Picker Modal */
.column-picker-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 34, 53, 0.6);
  backdrop-filter: blur(4px);
  padding: 20px;
}

.column-picker-dialog {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(16, 34, 53, 0.3);
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.column-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: #f2f7ff;
}

.column-picker-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text);
}

.column-picker-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.14s ease;
}

.column-picker-close:hover {
  background: rgba(16, 34, 53, 0.1);
  color: var(--text);
}

.column-picker-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.column-picker-hint {
  margin: 0 0 12px 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.column-picker-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.column-picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: move;
  transition: background-color 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}

.column-picker-item:hover:not(.column-picker-item-dragging) {
  background: #f9fbff;
  border-color: var(--primary);
}

.column-picker-item-dragging {
  opacity: 0.5;
  border-color: var(--primary);
  background: #f0f7ff;
}

.column-picker-item-hidden {
  opacity: 0.5;
  background: #f9f9f9;
}

.column-picker-item input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.column-picker-item label {
  flex: 1;
  margin: 0;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  display: flex;
  flex-direction: row;
  align-items: center;
}

.column-picker-drag-handle {
  color: var(--muted);
  font-size: 1.2rem;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background-color 0.14s ease, color 0.14s ease;
}

.column-picker-drag-handle:hover {
  background: rgba(16, 34, 53, 0.1);
  color: var(--text);
}

.column-picker-drag-handle:active {
  cursor: grabbing;
}

.column-picker-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: #f9fbff;
  gap: 12px;
  flex-wrap: wrap;
}

.column-picker-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

@media (max-width: 900px) {
  .container {
    padding: 14px 10px 20px;
  }

  .card {
    padding: 12px;
  }

  .status-kpis {
    gap: 8px 12px;
  }

  .column-picker-dialog {
    max-width: 95vw;
    max-height: 90vh;
  }

  .column-picker-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .column-picker-actions {
    margin-left: 0;
    width: 100%;
  }

  .column-picker-actions .btn {
    flex: 1;
  }
}
