:root {
  --bg: #f3f2ef;
  --surface: #fbfaf8;
  --ink: #2e2c28;
  --muted: #6b6862;
  --line: #ddd9d2;
  --accent: #5c6b73;
  --accent-strong: #46535a;
  --selected: #eef1f0;
  --row-hover: #d4e2de;
  --danger: #875449;
  --danger-hover: #6f4037;
  --gradient-ramp: linear-gradient(
    47deg,
    #8e9b90,
    #93c0a4,
    #b6c4a2 /* #d4cdab #dce2bd */
  );
  --gradient-size: 500% 500%;
  --gradient-duration: 6s;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

header {
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: 0.5px; }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.gradient-text {
  background-image: var(--gradient-ramp);
  color: transparent;
  background-clip: text;
  -webkit-background-clip: text;
  background-size: var(--gradient-size);
  animation: gradient-animation var(--gradient-duration) ease infinite;
}
@keyframes gradient-animation {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}
h2 { margin: 0 0 14px; font-size: 16px; font-weight: 600; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

textarea, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}
textarea { resize: vertical; }
textarea:focus, select:focus {
  outline: 2px solid rgba(92, 107, 115, 0.25);
  border-color: var(--accent);
}

.controls {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.field { flex: 1 1 200px; min-width: 180px; }
.field label { margin-bottom: 6px; }

.profile-select-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.profile-select-row select {
  flex: 1 1 auto;
}

.btn-icon {
  min-width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 13px;
}

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

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

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
  margin: 0;
}
.checkbox input { margin: 0; }

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  cursor: pointer;
}
button:hover { background: var(--accent-strong); }
button:disabled { opacity: 0.6; cursor: default; }

.status {
  margin: 14px 0 0;
  font-size: 14px;
  color: var(--muted);
}
.status.error { color: #8a4a3c; }

.status-working {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  max-width: 100%;
}

.status-text {
  display: block;
}

.status-progress {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.summary { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: top;
}
th {
  color: var(--muted);
  font-weight: 600;
  position: relative;
  user-select: none;
  overflow: visible;
}
.num { text-align: right; white-space: nowrap; width: 1%; }

tr.selected { background: var(--selected); }
tbody tr:hover { background: var(--row-hover); }

.title { font-weight: 600; }
.title a { color: var(--accent-strong); text-decoration: none; }
.title a:hover { text-decoration: underline; }
.meta, .reason { color: var(--muted); font-size: 13px; margin-top: 3px; }

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}
.badge.on { border-color: var(--accent); color: var(--accent-strong); }

.bar {
  display: block;
  width: min(560px, 62vw);
  min-width: 220px;
  flex: 0 0 auto;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  margin-top: 0;
}
.bar::after {
  content: "";
  display: block;
  width: 67%;
  height: 100%;
  background-image: var(--gradient-ramp);
  background-size: var(--gradient-size);
  animation:
    gradient-animation var(--gradient-duration) ease infinite,
    slide 2s ease-in-out infinite;
}
@keyframes slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(167%); }
}

@media (max-width: 640px) {
  main { padding: 16px; }
  .controls { gap: 12px; }
  .results-controls { gap: 8px; }
  .status-working {
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .bar {
    width: 100%;
    min-width: 0;
  }
}

/* ── Results controls bar ───────────────────────────────────────────────────── */
.results-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.table-wrap {
  overflow-x: auto;
}

#results-table {
  table-layout: fixed;
}

/* Ghost / outline button ────────────────────────────────────────────────────── */
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 13px;
  padding: 6px 12px;
  font-weight: 500;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg);
  color: var(--ink);
  border-color: var(--accent);
}

/* ── Column resize handle ───────────────────────────────────────────────────── */
.col-resize {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 9px;
  cursor: col-resize;
  z-index: 1;
  padding-left: 9px;
}
.col-resize::after {
  content: "";
  position: absolute;
  top: 25%;
  bottom: 25%;
  width: 1px;
  background: var(--line);
  transition: background 0.15s;
}
.col-resize:hover::after {
  background: var(--accent);
}

/* ── Column picker (details/summary dropdown) ───────────────────────────────── */
#col-picker {
  position: relative;
}
#col-picker > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  background: transparent;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  user-select: none;
  font-family: inherit;
}
#col-picker > summary::-webkit-details-marker { display: none; }
#col-picker > summary::marker { display: none; }
#col-picker > summary::after {
  content: "\25BE";
  font-size: 10px;
  margin-left: 2px;
  display: inline-block;
  transition: transform 0.15s;
}
#col-picker[open] > summary::after { transform: rotate(-180deg); }
#col-picker > summary:hover {
  background: var(--bg);
  color: var(--ink);
  border-color: var(--accent);
}

.col-picker-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 130px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

/* Subtle row transition ─────────────────────────────────────────────────────── */
tbody tr { transition: background 0.1s; }

/* ── Settings panel ──────────────────────────────────────────────────────────── */
.settings-panel > summary,
.settings-advanced > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.settings-panel > summary::-webkit-details-marker,
.settings-advanced > summary::-webkit-details-marker { display: none; }
.settings-panel > summary::marker,
.settings-advanced > summary::marker { display: none; }

.settings-panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.settings-panel > summary::before {
  content: "▶";
  display: inline-block;
  font-size: 10px;
  margin-right: 8px;
  transition: transform 0.15s;
  color: var(--muted);
}
.settings-panel[open] > summary::before { transform: rotate(90deg); }

.settings-body {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.setting-label {
  flex: 0 0 190px;
  font-size: 13px;
  color: var(--muted);
}

/* Numeric stepper */
.num-ctl {
  display: flex;
  align-items: center;
  gap: 4px;
}

.num-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  padding: 1px 7px;
  line-height: 1.6;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.num-btn:hover { background: var(--bg); color: var(--ink); border-color: var(--accent); }

.num-val {
  display: inline-block;
  min-width: 36px;
  text-align: center;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: text;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: border-color 0.12s, background 0.12s;
}
.num-val:hover { border-color: var(--line); background: #fff; }

.num-inline {
  width: 58px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 2px 6px;
  text-align: center;
}

/* Text inputs for email / API keys */
.setting-text {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
  flex: 1 1 auto;
  max-width: 300px;
}
.setting-text:focus { outline: 2px solid rgba(92, 107, 115, 0.25); border-color: var(--accent); }

/* Sources toggles */
.sources-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Advanced nested panel */
.settings-advanced {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.settings-advanced > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  padding-right: 128px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0;
}
.settings-panel > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  padding-right: 128px;
}
.settings-summary-label {
  flex: 1 1 auto;
  min-width: 0;
}
.settings-advanced > summary::before {
  content: "▶";
  display: inline-block;
  font-size: 9px;
  margin-right: 6px;
  transition: transform 0.15s;
}
.settings-advanced[open] > summary::before { transform: rotate(90deg); }
.settings-advanced > .settings-group { margin-top: 12px; }

.settings-summary-actions {
  display: none;
  align-items: center;
  gap: 8px;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  flex: 0 0 auto;
}
.settings-panel[open] > summary .settings-summary-actions,
.settings-advanced[open] > summary .settings-summary-actions {
  display: inline-flex;
}

/* Small button modifier — pairs with .btn-ghost */
.btn-small {
  font-size: 10px;
  padding: 3px 8px;
}

/* ── Profile modal/editor ──────────────────────────────────────────────────── */
.profile-modal {
  width: min(940px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  overflow: hidden;
  box-shadow: 0 22px 54px rgba(46, 44, 40, 0.16);
}

.profile-modal::backdrop {
  background: rgba(39, 37, 35, 0.48);
  backdrop-filter: blur(2px);
}

.profile-form {
  padding: 20px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  max-height: calc(100vh - 48px);
}

.profile-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.profile-modal-head h3 {
  margin: 0;
  font-size: 20px;
}

.profile-modal-note {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  max-width: 64ch;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-field-wide {
  grid-column: 1 / -1;
}

.profile-field input,
.profile-field textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.profile-field textarea {
  min-height: 72px;
  resize: vertical;
  line-height: 1.5;
}

.profile-field input:focus,
.profile-field textarea:focus {
  outline: 2px solid rgba(92, 107, 115, 0.25);
  border-color: var(--accent);
}

.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #fff;
  cursor: help;
  margin-left: 3px;
}

.profile-list-label {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-bottom: 0;
}

.label-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.profile-list-add {
  min-width: 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.profile-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.98));
}

.profile-item-body {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
}

.profile-subfield {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}

.profile-subfield-label {
  font-size: 12px;
  color: var(--muted);
}

.profile-subfield-compact textarea {
  min-height: 72px;
}

.profile-subfield-wide {
  grid-column: span 2;
}

.profile-item-input {
  width: 100%;
}

.profile-item-remove {
  align-self: start;
  min-width: 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}

.tip:focus-visible {
  outline: 2px solid rgba(92, 107, 115, 0.25);
  outline-offset: 2px;
}

.hover-tip {
  position: fixed;
  z-index: 9999;
  max-width: min(360px, calc(100vw - 24px));
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 500;
  white-space: pre-line;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.10);
  pointer-events: none;
}

.hover-tip[hidden] {
  display: none;
}

.profile-advanced {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.5);
}

.profile-advanced > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.profile-advanced > summary::-webkit-details-marker { display: none; }
.profile-advanced > summary::marker { display: none; }

.profile-advanced > summary::before {
  content: "▶";
  display: inline-block;
  font-size: 9px;
  margin-right: 6px;
  transition: transform 0.15s;
}

.profile-advanced[open] > summary::before {
  transform: rotate(90deg);
}

.profile-advanced-body {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}

.profile-ai-open-btn {
  margin-right: auto;
}

.profile-ai-modal {
  width: min(760px, calc(100vw - 32px));
}

.profile-ai-modal .profile-field textarea {
  min-height: 140px;
}

@media (max-width: 760px) {
  .profile-grid {
    grid-template-columns: 1fr;
  }

  .profile-list-label {
    align-items: flex-start;
    flex-direction: column;
  }

  .profile-item,
  .profile-item-body,
  .profile-item-body:has(textarea) {
    grid-template-columns: 1fr;
  }

  .profile-item-remove {
    justify-self: end;
  }

  .profile-select-row {
    flex-wrap: wrap;
  }

  .btn-icon {
    height: 34px;
  }
}
