/* ==========================================================================
   SEO Center — application shell and components

   Everything here is plain CSS on top of tokens.css. There is no JavaScript:
   tabs, segmented controls, toggles and dropdowns are driven by real form
   controls (radio / checkbox / select) so the back end gets a working form
   the moment it wires up an `action`.
   ========================================================================== */

/* ==========================================================================
   1. Shell
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

/* --- Sidebar -------------------------------------------------------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-4);
  background: var(--bg-1);
  border-inline-end: 1px solid var(--border-1);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) 0;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--radius-md);
  background: var(--color-primary);
}

/* Two-line label pairs (name over description) sit inside one wrapper span so
   the flex parent treats them as a single item. They must stack. */
.brand__name,
.brand__sub,
.user-card__name,
.user-card__role,
.agent-card__name,
.agent-card__role,
.integration__name,
.integration__meta,
.affiliate__name,
.affiliate__meta,
.dashed-card__title,
.dashed-card__desc,
.chat__name,
.run__title,
.run__time,
.stat-box__value,
.stat-box__label,
.source__title,
.source__url {
  display: block;
}

.brand__name {
  font-size: 18px;
  font-weight: var(--font-weight-bold);
  color: var(--color-secondary);
  line-height: 1.2;
}

.brand__sub {
  font-size: 12px;
  color: var(--fg-4);
  line-height: 1.4;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.nav__label {
  padding-inline: var(--space-3);
  margin-bottom: var(--space-2);
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-4);
}

.nav__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: var(--font-weight-medium);
  color: var(--fg-2);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav__item + .nav__item {
  margin-top: var(--space-1);
}

.nav__item:hover {
  background: var(--bg-2);
}

.nav__item[aria-current="page"] {
  background: var(--color-primary);
  color: var(--color-secondary);
  font-weight: var(--font-weight-bold);
}

.nav__item svg {
  flex: none;
}

.nav__badge {
  margin-inline-start: auto;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  background: var(--color-secondary);
  color: var(--color-primary);
  font-size: 10px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.04em;
}

.sidebar__footer {
  margin-top: auto;
}

.user-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--bg-2);
}

.user-card__avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-secondary);
  font-size: 14px;
  font-weight: var(--font-weight-bold);
}

.user-card__name {
  font-size: 14px;
  font-weight: var(--font-weight-semibold);
  line-height: 1.3;
}

.user-card__role {
  font-size: 12px;
  color: var(--fg-4);
  line-height: 1.3;
}

/* --- Topbar --------------------------------------------------------------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--topbar-height);
  padding: var(--space-4) var(--space-8);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-1);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__title {
  font-size: 22px;
  font-weight: var(--font-weight-bold);
  margin-inline-end: auto;
}

.search {
  position: relative;
  width: min(300px, 30vw);
}

.search__icon {
  position: absolute;
  inset-inline-start: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.search__input {
  width: 100%;
  padding: 10px var(--space-4) 10px 38px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--bg-1);
  font-size: 14px;
}

.search__input::placeholder {
  color: var(--fg-4);
}

/* Language switch — two radios rendered as one pill. */
.lang {
  display: flex;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.lang__option {
  padding: 9px var(--space-4);
  font-size: 13px;
  font-weight: var(--font-weight-bold);
  color: var(--fg-3);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.lang input:checked + .lang__option {
  background: var(--color-secondary);
  color: var(--color-shade-light);
}

.lang input:focus-visible + .lang__option {
  outline: 2px solid var(--color-secondary);
  outline-offset: -2px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--bg-1);
  color: var(--fg-2);
  transition: background-color 0.15s ease;
}

.icon-button:hover {
  background: var(--bg-2);
}

/* --- Page canvas ---------------------------------------------------------- */

.page {
  flex: 1;
  padding: var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.page__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.page__title {
  font-size: 30px;
  font-weight: var(--font-weight-extrabold);
  line-height: 1.25;
}

.page__sub {
  margin-top: var(--space-1);
  font-size: 15px;
  color: var(--fg-3);
}

.section__title {
  font-size: 20px;
  font-weight: var(--font-weight-bold);
}

.section__sub {
  margin-top: var(--space-1);
  font-size: 14px;
  color: var(--fg-3);
}

.section__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

/* --- Studio / settings tab strip ------------------------------------------ */

.tabs {
  display: flex;
  gap: var(--space-6);
  border-bottom: 1px solid var(--border-1);
}

.tabs__item {
  padding: var(--space-3) var(--space-1);
  font-size: 15px;
  font-weight: var(--font-weight-medium);
  color: var(--fg-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tabs__item:hover {
  color: var(--fg-1);
}

.tabs__item[aria-current="page"],
.tabs input:checked + .tabs__item {
  color: var(--color-secondary);
  font-weight: var(--font-weight-bold);
  border-bottom-color: var(--color-secondary);
}

/* CSS-only tab panels. The radios sit before the strip, so a checked one can
   reach its panel through the sibling combinator — no script involved. */
.tabpanel {
  display: none;
}

#tab-agents:checked        ~ .tabpanel--agents,
#tab-integrations:checked  ~ .tabpanel--integrations,
#tab-sources:checked       ~ .tabpanel--sources,
#tab-affiliate:checked     ~ .tabpanel--affiliate {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* …and mark the matching label as the current tab. */
#tab-agents:checked       ~ .tabs .tabs__item[for="tab-agents"],
#tab-integrations:checked ~ .tabs .tabs__item[for="tab-integrations"],
#tab-sources:checked      ~ .tabs .tabs__item[for="tab-sources"],
#tab-affiliate:checked    ~ .tabs .tabs__item[for="tab-affiliate"] {
  color: var(--color-secondary);
  font-weight: var(--font-weight-bold);
  border-bottom-color: var(--color-secondary);
}

.tabs__item[for] {
  cursor: pointer;
}

/* Keyboard focus lands on the hidden radio; show it on the visible label. */
#tab-agents:focus-visible       ~ .tabs .tabs__item[for="tab-agents"],
#tab-integrations:focus-visible ~ .tabs .tabs__item[for="tab-integrations"],
#tab-sources:focus-visible      ~ .tabs .tabs__item[for="tab-sources"],
#tab-affiliate:focus-visible    ~ .tabs .tabs__item[for="tab-affiliate"] {
  outline: 2px solid var(--color-secondary);
  outline-offset: 2px;
}

/* ==========================================================================
   2. Primitives
   ========================================================================== */

.card {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.card--pad {
  padding: var(--space-6);
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-1);
}

.card__title {
  font-size: 17px;
  font-weight: var(--font-weight-bold);
}

.card__link {
  font-size: 14px;
  font-weight: var(--font-weight-semibold);
  color: var(--color-secondary);
}

.card__link:hover {
  text-decoration: underline;
}

/* --- Buttons -------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 11px var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.button--primary {
  background: var(--color-primary);
  color: var(--color-secondary);
  font-weight: var(--font-weight-bold);
}

.button--primary:hover {
  box-shadow: var(--shadow-primary);
}

.button--secondary {
  background: var(--color-secondary);
  color: var(--color-shade-light);
}

.button--secondary:hover {
  background: var(--color-secondary-hover);
}

.button--ghost {
  background: var(--bg-1);
  border-color: var(--border-1);
  color: var(--fg-2);
}

.button--ghost:hover {
  background: var(--bg-2);
}

.button--dark {
  background: var(--color-secondary);
  color: var(--color-shade-light);
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
}

.button--block {
  width: 100%;
}

.button--lg {
  padding: var(--space-4);
  font-size: 15px;
}

/* Small square action buttons in the topics table. */
.action-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  background: var(--bg-1);
  color: var(--fg-4);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.action-button:hover {
  background: var(--bg-2);
  color: var(--fg-2);
}

.action-button--approved {
  background: var(--color-success);
  border-color: var(--color-success);
  color: var(--color-shade-light);
}

.action-button--approved:hover {
  background: var(--color-success);
  color: var(--color-shade-light);
}

.action-button--danger {
  color: var(--color-danger);
}

/* --- Pills, chips, dots --------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--bg-2);
  color: var(--fg-3);
  font-size: 12px;
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
}

.pill--success { background: var(--color-success-soft); color: #15803D; }
.pill--primary { background: var(--color-primary-tint); color: var(--color-text-accent); }
.pill--blue    { background: var(--color-blue-soft);    color: var(--color-blue); }
.pill--purple  { background: var(--color-purple-soft);  color: var(--color-purple); }
.pill--orange  { background: var(--color-orange-soft);  color: var(--color-orange); }
.pill--danger  { background: var(--color-danger-soft);  color: var(--color-danger); }

.dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: var(--radius-full);
  background: currentColor;
}

.dot--success { background: var(--color-success); }
.dot--blue    { background: var(--color-blue); }
.dot--purple  { background: var(--color-purple); }
.dot--orange  { background: var(--color-orange); }
.dot--danger  { background: var(--color-danger); }
.dot--muted   { background: var(--fg-4); }

/* Removable competitor-blog chips. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--bg-2);
  font-size: 13px;
  color: var(--fg-2);
}

.chip--accent {
  background: var(--color-primary-tint);
  color: var(--color-text-accent);
  font-weight: var(--font-weight-semibold);
}

.chip__remove {
  display: grid;
  place-items: center;
  color: var(--fg-4);
}

.chip__remove:hover {
  color: var(--fg-1);
}

/* Suggestion chips above the manager composer. */
.chip-button {
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-full);
  background: var(--bg-1);
  font-size: 14px;
  font-weight: var(--font-weight-medium);
  color: var(--fg-2);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chip-button:hover {
  background: var(--bg-2);
  border-color: var(--border-2);
}

/* --- Icon tiles ----------------------------------------------------------- */

.tile {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: var(--radius-md);
  background: var(--bg-2);
  color: var(--fg-2);
}

.tile--primary   { background: var(--color-primary-tint); color: var(--color-text-accent); }
.tile--secondary { background: var(--color-secondary);    color: var(--color-primary); }
.tile--blue      { background: var(--color-blue-soft);    color: var(--color-blue); }
.tile--purple    { background: var(--color-purple-soft);  color: var(--color-purple); }
.tile--orange    { background: var(--color-orange-soft);  color: var(--color-orange); }
.tile--success   { background: var(--color-success-soft); color: #15803D; }
.tile--sm { width: 34px; height: 34px; border-radius: var(--radius-sm); }
.tile--lg { width: 56px; height: 56px; border-radius: var(--radius-lg); }

/* --- Form controls -------------------------------------------------------- */

.field {
  display: block;
}

.field__label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: 14px;
  font-weight: var(--font-weight-medium);
  color: var(--fg-2);
}

.input {
  width: 100%;
  padding: 12px var(--space-4);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--bg-1);
  font-size: 15px;
}

.input::placeholder {
  color: var(--fg-4);
}

.input:focus-visible {
  border-color: var(--color-secondary);
}

.select-wrap {
  position: relative;
}

.select {
  width: 100%;
  padding: 12px 46px 12px var(--space-4);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--bg-1);
  font-size: 15px;
  font-weight: var(--font-weight-semibold);
  appearance: none;
  cursor: pointer;
}

.select-wrap__chevron {
  position: absolute;
  inset-inline-end: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

/* Count badge that sits between the label and the chevron. */
.select-wrap__count {
  position: absolute;
  inset-inline-end: 42px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 22px;
  padding: 1px var(--space-2);
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-accent);
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  text-align: center;
  pointer-events: none;
}

.select-wrap:has(.select-wrap__count) .select {
  padding-inline-end: 72px;
}

/* Segmented control — radios that look like one grouped button bar. */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: var(--space-2);
}

.segmented__option {
  padding: 11px var(--space-3);
  border-radius: var(--radius-md);
  background: var(--bg-2);
  color: var(--fg-3);
  font-size: 14px;
  font-weight: var(--font-weight-semibold);
  text-align: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.segmented__option:hover {
  background: var(--border-1);
}

.segmented input:checked + .segmented__option {
  background: var(--color-secondary);
  color: var(--color-shade-light);
}

.segmented input:focus-visible + .segmented__option {
  outline: 2px solid var(--color-secondary);
  outline-offset: 2px;
}

/* Toggle switch used by the affiliate-link rows. */
.switch {
  display: inline-block;
  width: 44px;
  height: 26px;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--border-2);
  cursor: pointer;
  transition: background-color 0.15s ease;
  position: relative;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--color-shade-light);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}

.switch-input:checked + .switch {
  background: var(--color-primary);
}

.switch-input:checked + .switch::after {
  transform: translateX(18px);
}

[dir="rtl"] .switch-input:checked + .switch::after {
  transform: translateX(-18px);
}

.switch-input:focus-visible + .switch {
  outline: 2px solid var(--color-secondary);
  outline-offset: 2px;
}

/* Stepper for the internal-links count. */
.stepper {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.stepper__button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  background: var(--bg-1);
  color: var(--fg-2);
}

.stepper__button:hover {
  background: var(--bg-1);
  border-color: var(--border-2);
}

.stepper__value {
  width: 34px;
  border: none;
  background: none;
  text-align: center;
  font-size: 15px;
  font-weight: var(--font-weight-bold);
  appearance: textfield;
}

.stepper__value::-webkit-outer-spin-button,
.stepper__value::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

/* Grouped field-set headings ("TOPIC", "SEO & LINKS", …). */
.fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

.fieldset + .fieldset {
  margin-top: var(--space-6);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-1);
}

.fieldset__legend {
  padding: 0;
  margin-bottom: var(--space-3);
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-4);
}

.fieldset__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-2);
}

/* ==========================================================================
   3. Dashboard
   ========================================================================== */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: box-shadow 0.15s ease;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-card--accent {
  background: #F6FCE9;
  border-color: var(--color-primary);
}

.stat-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.stat-card__value {
  font-size: 34px;
  font-weight: var(--font-weight-extrabold);
  line-height: 1.1;
}

.stat-card__foot {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 14px;
  color: var(--fg-3);
}

.stat-card--accent .stat-card__foot {
  color: var(--color-text-accent);
  font-weight: var(--font-weight-semibold);
}

.stat-card__chevron {
  margin-inline-start: auto;
}

.agent-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
}

.agent-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.agent-card__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.agent-card__name {
  font-size: 17px;
  font-weight: var(--font-weight-bold);
}

.agent-card__role {
  font-size: 13px;
  color: var(--fg-4);
}

.agent-card__head .pill {
  margin-inline-start: auto;
}

.agent-card__desc {
  font-size: 14px;
  color: var(--fg-3);
}

/* Label / value rows inside agent and provider cards. */
.spec {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.spec--boxed {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--bg-2);
}

.spec__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  font-size: 14px;
}

.spec__label {
  color: var(--fg-4);
}

.spec__value {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--font-weight-bold);
}

.agent-card .spec {
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-1);
}

.agent-card--boxed .spec {
  padding-top: 0;
  border-top: none;
}

/* Responsibilities checklist on the Settings page. */
.checklist {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.checklist__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: 14px;
  color: var(--fg-2);
}

/* --- Latest articles / research lists ------------------------------------- */

.list__row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  transition: background-color 0.15s ease;
}

.list__row + .list__row {
  border-top: 1px solid var(--border-1);
}

.list__row:hover {
  background: var(--bg-2);
}

.list__row--highlight {
  background: var(--color-orange-soft);
}

.list__row--highlight:hover {
  background: var(--color-orange-soft);
}

.list__body {
  min-width: 0;
  flex: 1;
}

.list__title {
  font-size: 15px;
  font-weight: var(--font-weight-semibold);
}

.list__meta {
  margin-top: var(--space-1);
  font-size: 13px;
  color: var(--fg-4);
}

.list__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-1);
  font-size: 14px;
  font-weight: var(--font-weight-semibold);
  color: var(--color-secondary);
}

.list__foot:hover {
  background: var(--bg-2);
}

/* --- Cost card ------------------------------------------------------------ */

.cost-card {
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  background: var(--color-secondary);
  color: var(--color-shade-light);
}

.cost-card__label {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.75);
}

.cost-card__value {
  margin-top: var(--space-2);
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-size: 34px;
  font-weight: var(--font-weight-extrabold);
  line-height: 1.1;
}

.cost-card__budget {
  font-size: 14px;
  font-weight: var(--font-weight-semibold);
  color: var(--color-primary);
}

.progress {
  margin-top: var(--space-4);
  height: 8px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-primary);
}

/* --- Integrations --------------------------------------------------------- */

.integration {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) 0;
}

.integration + .integration {
  border-top: 1px solid var(--border-1);
}

.integration__name {
  font-size: 15px;
  font-weight: var(--font-weight-semibold);
}

.integration__meta {
  font-size: 13px;
  color: var(--fg-4);
}

.integration__status {
  margin-inline-start: auto;
}

/* Dashboard bottom band: lists on the left, cost + integrations on the right. */
.dashboard-columns {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: var(--space-4);
  align-items: start;
}

.dashboard-columns__stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ==========================================================================
   4. AI Manager
   ========================================================================== */

.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: var(--space-6);
  max-width: 940px;
  width: 100%;
  margin-inline: auto;
}

.chat__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--border-1);
}

.chat__name {
  font-size: 17px;
  font-weight: var(--font-weight-bold);
}

.chat__status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
  color: var(--fg-3);
}

.chat__thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.message {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  max-width: 780px;
}

.message__body {
  padding-top: var(--space-1);
  font-size: 16px;
  line-height: 1.6;
  color: var(--fg-2);
}

.chat__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.composer {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  background: var(--bg-1);
  box-shadow: var(--shadow-sm);
}

.composer__input {
  flex: 1;
  border: none;
  background: none;
  padding: var(--space-3) 0;
  font-size: 15px;
}

.composer__input:focus-visible {
  outline: none;
}

.composer__send {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: var(--color-text-accent);
}

.composer__send:hover {
  box-shadow: var(--shadow-primary);
}

.chat__note {
  text-align: center;
  font-size: 13px;
  color: var(--fg-4);
}

/* ==========================================================================
   5. Blog Research
   ========================================================================== */

.research-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  align-items: start;
}

.research-form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.input-row {
  display: flex;
  gap: var(--space-3);
}

.input-row .input {
  flex: 1;
}

.table-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-1);
}

.table-card__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 15px;
  font-weight: var(--font-weight-bold);
}

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

.table {
  min-width: 1020px;
  font-size: 14px;
}

.table th {
  padding: var(--space-3);
  text-align: start;
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-4);
  border-bottom: 1px solid var(--border-1);
  white-space: nowrap;
}

.table td {
  padding: var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border-1);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: var(--bg-2);
}

.table__topic {
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
}

/* Keywords are the one column allowed to truncate — the full value stays in
   the DOM, so a title attribute or tooltip can surface it later. */
.table__keyword {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-4);
}

.table__intent {
  font-weight: var(--font-weight-semibold);
}

.table__intent--commercial    { color: var(--color-purple); }
.table__intent--informational { color: var(--color-blue); }
.table__intent--transactional { color: var(--color-secondary); }

.table__actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

/* Opportunity score: number then a proportional bar. */
.score {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 130px;
}

.score__value {
  font-weight: var(--font-weight-bold);
  font-variant-numeric: tabular-nums;
}

.score__track {
  flex: 1;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--border-1);
  overflow: hidden;
}

.score__bar {
  display: block;
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-primary);
}

.score__bar--strong {
  background: var(--color-success);
}

/* ==========================================================================
   6. Write
   ========================================================================== */

.write-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  align-items: start;
}

.write-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.field + .field,
.field-grid + .field,
.field + .field-grid,
.segmented + .field {
  margin-top: var(--space-4);
}

/* Boxed row: label on the left, a control on the right. */
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: var(--font-weight-medium);
}

.affiliate {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
}

.affiliate + .affiliate {
  margin-top: var(--space-3);
}

.affiliate__avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--color-primary-tint);
  color: var(--color-text-accent);
  font-size: 13px;
  font-weight: var(--font-weight-bold);
}

.affiliate__name {
  font-size: 15px;
  font-weight: var(--font-weight-semibold);
}

.affiliate__meta {
  font-size: 13px;
  color: var(--fg-4);
}

.affiliate__controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-inline-start: auto;
}

.dashed-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-md);
}

.dashed-card__title {
  font-size: 15px;
  font-weight: var(--font-weight-semibold);
}

.dashed-card__desc {
  font-size: 13px;
  color: var(--fg-4);
}

.dashed-card .button {
  margin-inline-start: auto;
}

/* "Add agent" placeholder on Settings. */
.add-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-lg);
  text-align: center;
  color: var(--fg-3);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.add-card:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-tint-soft);
}

.add-card__title {
  font-size: 17px;
  font-weight: var(--font-weight-bold);
  color: var(--fg-1);
}

.add-card__desc {
  font-size: 14px;
  max-width: 22ch;
}

.preview {
  display: flex;
  flex-direction: column;
  min-height: 500px;
}

.preview__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-1);
}

.preview__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 16px;
  font-weight: var(--font-weight-bold);
}

.preview__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-8);
  text-align: center;
}

.preview__heading {
  font-size: 20px;
  font-weight: var(--font-weight-bold);
}

.preview__desc {
  font-size: 15px;
  color: var(--fg-3);
  max-width: 38ch;
}

/* ==========================================================================
   7. Content Calendar
   ========================================================================== */

.calendar-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--bg-1);
}

.calendar-nav__label {
  min-width: 130px;
  text-align: center;
  font-size: 15px;
  font-weight: var(--font-weight-bold);
}

.calendar-nav__button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--fg-2);
}

.calendar-nav__button:hover {
  background: var(--bg-2);
}

.calendar-hint {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
  color: var(--fg-4);
}

.calendar {
  overflow: hidden;
}

.calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.calendar__weekday {
  padding: var(--space-3);
  text-align: center;
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-4);
  border-bottom: 1px solid var(--border-1);
}

.calendar__day {
  min-height: 104px;
  padding: var(--space-2);
  border-inline-end: 1px solid var(--border-1);
  border-bottom: 1px solid var(--border-1);
}

.calendar__day:nth-child(7n) {
  border-inline-end: none;
}

.calendar__grid > .calendar__day:nth-last-child(-n + 7) {
  border-bottom: none;
}

.calendar__day--muted {
  background: var(--bg-2);
}

.calendar__date {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding-inline: 6px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-full);
  font-size: 13px;
  color: var(--fg-3);
}

.calendar__date--today {
  background: var(--color-primary);
  color: var(--color-text-accent);
  font-weight: var(--font-weight-bold);
}

.event {
  display: block;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: var(--font-weight-semibold);
  line-height: 1.35;
}

.event + .event {
  margin-top: var(--space-1);
}

.event--published { background: var(--color-success-soft); color: #15803D; }
.event--scheduled { background: var(--color-blue-soft);    color: var(--color-blue); }
.event--draft     { background: var(--bg-2);               color: var(--fg-3); }

.legend {
  display: flex;
  gap: var(--space-6);
  font-size: 13px;
  color: var(--fg-3);
}

.legend__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ==========================================================================
   8. Logs & Trace
   ========================================================================== */

.logs-columns {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: var(--space-6);
  align-items: start;
}

.run {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  padding: var(--space-4) var(--space-6);
  text-align: start;
  transition: background-color 0.15s ease;
}

.run + .run {
  border-top: 1px solid var(--border-1);
}

.run:hover {
  background: var(--bg-2);
}

.run--active {
  background: #FCFEF5;
}

.run__title {
  font-size: 15px;
  font-weight: var(--font-weight-semibold);
}

.run__time {
  margin-top: var(--space-1);
  font-size: 13px;
  color: var(--fg-4);
}

.run .pill {
  margin-inline-start: auto;
}

/* --- Trace timeline ------------------------------------------------------- */

.trace {
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
}

.trace__step {
  position: relative;
  padding-inline-start: var(--space-8);
  padding-bottom: var(--space-6);
}

.trace__step:last-child {
  padding-bottom: 0;
}

/* The connector runs from each dot down to the next one. */
.trace__step::before {
  content: "";
  position: absolute;
  inset-inline-start: 6px;
  top: 16px;
  bottom: -4px;
  width: 2px;
  background: var(--border-1);
}

.trace__step:last-child::before {
  display: none;
}

.trace__dot {
  position: absolute;
  inset-inline-start: 0;
  top: 6px;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--fg-4);
}

.trace__dot--done    { background: var(--color-success); }
.trace__dot--error   { background: var(--color-danger); }
.trace__dot--running { background: #C084FC; }
.trace__dot--pending { background: #374151; }

.trace__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.trace__title {
  font-size: 15px;
  font-weight: var(--font-weight-bold);
}

.trace__meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--fg-4);
}

.trace__agent {
  padding: 2px var(--space-2);
  border-radius: var(--radius-xs);
  background: var(--bg-2);
  font-size: 12px;
  font-weight: var(--font-weight-semibold);
  color: var(--fg-2);
}

.trace__error {
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--color-danger-soft);
  color: var(--color-danger);
  font-size: 14px;
}

/* ==========================================================================
   9. Settings
   ========================================================================== */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  align-items: stretch;
}

.settings-grid--2 {
  grid-template-columns: repeat(2, 1fr);
}

.agent-card--settings {
  gap: var(--space-6);
}

.agent-card__actions {
  display: flex;
  gap: var(--space-3);
}

.agent-card__actions .button:first-child {
  flex: 1;
}

/* Headline figure inside an integration card. */
.stat-box {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--bg-2);
}

.stat-box__value {
  font-size: 30px;
  font-weight: var(--font-weight-extrabold);
  line-height: 1.1;
}

.stat-box__label {
  margin-top: var(--space-1);
  font-size: 13px;
  color: var(--fg-4);
}

.stat-box__delta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 14px;
  font-weight: var(--font-weight-bold);
  color: #15803D;
}

.card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-1);
}

/* Informational strip above the affiliate table. */
.banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  background: var(--color-primary-tint-soft);
  font-size: 15px;
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-accent);
}

/* Square letter avatar for brands and affiliate programs. */
.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: var(--radius-sm);
  background: var(--color-primary-tint);
  color: var(--color-text-accent);
  font-size: 14px;
  font-weight: var(--font-weight-bold);
}

.avatar--purple {
  background: var(--color-purple);
  color: var(--color-shade-light);
}

.opportunity {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-1);
}

.opportunity__name {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 15px;
  font-weight: var(--font-weight-bold);
}

.opportunity__meta {
  margin-top: var(--space-1);
  font-size: 13px;
  color: var(--fg-4);
}

.opportunity__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-inline-start: auto;
}

.label-heading {
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-4);
}

.source__title {
  font-size: 15px;
  font-weight: var(--font-weight-semibold);
}

.source__url {
  margin-top: 2px;
  font-size: 13px;
  color: var(--fg-4);
}

.table__num {
  text-align: end;
  font-variant-numeric: tabular-nums;
}

.table__end {
  text-align: end;
}

.table--auto {
  min-width: 0;
}

/* ==========================================================================
   10. Utilities
   ========================================================================== */

.stack        { display: flex; flex-direction: column; gap: var(--space-4); }
.stack--sm    { gap: var(--space-2); }
.stack--lg    { gap: var(--space-6); }
.row          { display: flex; align-items: center; gap: var(--space-3); }
.row--between { justify-content: space-between; }
.row--wrap    { flex-wrap: wrap; }
.push-end     { margin-inline-start: auto; }
.muted        { color: var(--fg-4); }
.text-sm      { font-size: 14px; }
.text-xs      { font-size: 13px; }

/* ==========================================================================
   11. Responsive
   ========================================================================== */

@media (max-width: 1240px) {
  .dashboard-columns,
  .write-columns,
  .logs-columns,
  .research-form {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    border-inline-end: none;
    border-bottom: 1px solid var(--border-1);
  }

  .sidebar__footer {
    margin-top: var(--space-4);
  }

  .stat-grid,
  .agent-grid,
  .settings-grid,
  .settings-grid--2 {
    grid-template-columns: 1fr;
  }

  .page,
  .topbar {
    padding-inline: var(--space-4);
  }

  .topbar {
    flex-wrap: wrap;
  }

  .search {
    width: 100%;
    order: 3;
  }
}

@media (max-width: 640px) {
  .field-grid,
  .segmented {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
  }

  .calendar__grid {
    min-width: 640px;
  }

  .calendar {
    overflow-x: auto;
  }
}
