/* ── toasts (stacked, typed, click-to-dismiss) ── */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bot) + 92px);
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: min(90vw, 440px);
}
.toast-item {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(20, 20, 22, 0.94);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-brd);
  color: #fff;
  padding: 10px 15px;
  border-radius: 13px;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  cursor: pointer;
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transition:
    opacity 0.26s,
    transform 0.26s;
}
.toast-item.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.toast-item .toast-ic {
  display: inline-flex;
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}
.toast-item .toast-ic .ic {
  width: 17px;
  height: 17px;
}
.toast-item .toast-msg {
  min-width: 0;
}
.toast-item.success {
  border-color: rgba(74, 222, 128, 0.5);
}
.toast-item.success .toast-ic {
  color: #4ade80;
}
.toast-item.error {
  border-color: rgba(239, 68, 68, 0.55);
}
.toast-item.error .toast-ic {
  color: #f87171;
}
.toast-item.info .toast-ic {
  color: rgba(255, 255, 255, 0.85);
}

/* ── motion: content entrance ────────────────────────────────────────────── */
@keyframes viewIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.view > * {
  animation: viewIn 0.34s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.view > *:nth-child(2) {
  animation-delay: 0.05s;
}
.view > *:nth-child(3) {
  animation-delay: 0.1s;
}
.view > *:nth-child(n + 4) {
  animation-delay: 0.13s;
}
/* subnav is sticky and subview is a bare wrapper — animate its children instead.
   Keep both inside --content-max; a later .subview { max-width: 100% } used to
   stretch History / Errors / Review across the whole main column. */
.view > .crumbs,
.view > .subnav,
.view > .subview {
  animation: none;
  width: 100%;
  max-width: var(--content-max);
}
.subview > * {
  animation: viewIn 0.34s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.subview > *:nth-child(2) {
  animation-delay: 0.06s;
}
.subview > *:nth-child(3) {
  animation-delay: 0.11s;
}
.subview > *:nth-child(4) {
  animation-delay: 0.15s;
}
.subview > *:nth-child(n + 5) {
  animation-delay: 0.18s;
}

.card {
  transition:
    box-shadow 0.2s,
    border-color 0.2s;
}

/* ── hover polish (pointer devices only) ─────────────────────────────────── */
@media (hover: hover) {
  .btn.primary:hover:not(:disabled) {
    filter: brightness(1.04);
    box-shadow:
      0 10px 26px rgba(0, 0, 0, 0.55),
      inset 0 1px 0 rgba(255, 255, 255, 0.85);
  }
  .btn.ghost:hover:not(:disabled) {
    background: rgba(var(--fg-rgb), 0.12);
    border-color: rgba(var(--fg-rgb), 0.2);
  }
  .btn.small:hover:not(:disabled),
  .btn.sm:hover:not(:disabled) {
    filter: brightness(1.04);
  }
  .tool-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.42);
  }
  .tool-card.soon:hover {
    transform: none;
    box-shadow: none;
  }
  .result:hover {
    border-color: rgba(var(--fg-rgb), 0.16);
    background: rgba(var(--fg-rgb), 0.06);
  }
  .list-item:hover {
    border-color: rgba(var(--fg-rgb), 0.18);
    background: rgba(var(--fg-rgb), 0.06);
  }
  .list-item button:hover {
    background: rgba(var(--fg-rgb), 0.14);
    color: var(--txt);
  }
  .tm-del:hover {
    background: rgba(239, 68, 68, 0.16) !important;
    border-color: rgba(239, 68, 68, 0.5) !important;
    color: #fff !important;
  }
  .tm-clear:hover {
    color: var(--txt);
    border-color: rgba(var(--fg-rgb), 0.22);
    background: rgba(var(--fg-rgb), 0.05);
  }
  .icon-btn:hover:not(:disabled) {
    background: rgba(var(--fg-rgb), 0.13);
    border-color: rgba(var(--fg-rgb), 0.22);
  }
  .toggle-field:hover {
    border-color: rgba(var(--fg-rgb), 0.14);
    background: rgba(var(--fg-rgb), 0.05);
  }
  .seg button:hover:not(.on) {
    color: var(--txt);
  }
  .sender-choice:hover:not(.on),
  .sender-settings-tile:hover:not(.active) {
    color: var(--txt);
    border-color: rgba(var(--fg-rgb), 0.2);
    background: rgba(var(--fg-rgb), 0.06);
  }
  .subtab:hover:not(.active) {
    color: var(--txt);
    background: rgba(var(--fg-rgb), 0.05);
  }
  .plan-col:hover {
    border-color: rgba(var(--fg-rgb), 0.24);
  }
  .input-toggle:hover {
    background: rgba(var(--fg-rgb), 0.16);
    color: #fff;
  }
}

/* On desktop, center toasts over the main column (not the whole window). */
@media (min-width: 861px) {
  .toasts {
    left: calc(50% + (var(--sidebar-w) / 2));
  }
}

/* ── responsive: tablet ──────────────────────────────────────────────────── */
@media (max-width: 1080px) and (min-width: 861px) {
  :root {
    --sidebar-w: 224px;
  }
  .main {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* ── responsive: mobile (sidebar collapses to a bottom bar) ──────────────── */
@media (max-width: 860px) {
  .app {
    flex-direction: column;
  }
  .objective-seg {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .main {
    order: 1;
    flex: 1 1 auto;
    min-height: 0;
    padding: calc(var(--safe-top) + 10px) 12px 10px;
    gap: 10px;
  }
  .view > *,
  .runbar {
    max-width: 720px;
  }
  .runbar {
    flex-direction: column;
    align-items: stretch;
  }

  .sidebar {
    order: 2;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    gap: 0;
    padding: 6px 8px calc(var(--safe-bot) + 6px);
    border-right: 0;
    border-top: 1px solid var(--glass-brd);
    border-radius: 0;
  }
  .sidebar-head,
  .sidebar-foot {
    display: none;
  }
  .sidebar .tabbar {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0;
    gap: 2px;
    width: 100%;
  }
  .sidebar .tab {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 8px 1px;
    font-size: 12px;
    letter-spacing: 0;
    min-width: 0;
  }
  .sidebar .tab > span:last-child {
    flex: 0 0 auto;
    text-align: center;
  }
  .sidebar .tab.active::before {
    display: none;
  }
}

@media (max-width: 560px) {
  .sender-choice-grid,
  .sender-choice-grid.compact {
    grid-template-columns: 1fr;
  }
  .sender-settings-tile {
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    padding: 10px 5px;
    text-align: center;
  }
  .sender-settings-copy {
    flex: 0 1 auto;
  }
  .sender-settings-copy small {
    display: none;
  }
  .sender-settings-count {
    min-width: 22px;
    padding: 3px 6px;
  }
  .page-head {
    gap: 10px;
  }
  .page-head-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }
  .page-head-icon .ic {
    width: 19px;
    height: 19px;
  }
  .page-head-copy h2 {
    font-size: 15px;
  }
  .page-head.has-action {
    flex-wrap: wrap;
  }
  .page-head.has-action > .btn {
    flex-basis: 100%;
    width: 100%;
    margin-left: 0;
  }
  .home-hero {
    padding: 16px;
  }
  .home-user {
    align-items: flex-start;
  }
  .home-user > .plan-badge {
    position: absolute;
    top: 16px;
    right: 16px;
  }
  .home-copy {
    padding-right: 52px;
  }
  .home-status-grid {
    grid-template-columns: 1fr;
  }
  .profile-head {
    align-items: center;
    flex-wrap: nowrap;
    padding-right: 62px;
  }
  .profile-head .plan-badge {
    position: absolute;
    top: 16px;
    right: 16px;
    margin: 0;
  }
  .plan-grid,
  .meta-grid {
    grid-template-columns: 1fr;
  }
  .admin-tools {
    flex-direction: column;
  }
  .admin-tools .seg,
  .admin-search,
  .admin-tools-actions {
    width: 100%;
    min-width: 0;
    max-width: none;
    margin-left: 0;
  }
  .results-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .rt-search,
  .rt-sort,
  .rt-verified {
    width: 100%;
    flex: 0 0 auto;
  }
}

/* ── keyboard focus rings (pointer clicks stay clean) ────────────────────── */
.btn:focus-visible,
.tab:focus-visible,
.subtab:focus-visible,
.icon-btn:focus-visible,
.tm-del:focus-visible,
.tm-clear:focus-visible,
.switch:focus-visible,
.seg button:focus-visible,
.side-user:focus-visible,
.tool-card:focus-visible,
.sender-choice:focus-visible,
.sender-settings-tile:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ── skeleton loaders (initial data fetch) ───────────────────────────────── */
@keyframes skShimmer {
  0% {
    background-position: -420px 0;
  }
  100% {
    background-position: 420px 0;
  }
}
.card.skeleton {
  pointer-events: none;
}
.card.skeleton .sk-line,
.card.skeleton .sk-box {
  background: linear-gradient(
    90deg,
    rgba(var(--fg-rgb), 0.05) 25%,
    rgba(var(--fg-rgb), 0.12) 37%,
    rgba(var(--fg-rgb), 0.05) 63%
  );
  background-size: 840px 100%;
  animation: skShimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
}
.card.skeleton .sk-line {
  height: 13px;
  margin-bottom: 11px;
}
.card.skeleton .sk-line.sk-title {
  height: 20px;
  width: 44%;
  margin-bottom: 18px;
  border-radius: 9px;
}
.card.skeleton .sk-line.short {
  width: 62%;
}
.card.skeleton .sk-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 16px;
}
.card.skeleton .sk-box {
  height: 58px;
  border-radius: 12px;
}

/* ── run progress bar (top edge of the runbar) ───────────────────────────── */
.run-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  overflow: hidden;
  border-radius: 2px 2px 0 0;
  background: rgba(var(--fg-rgb), 0.08);
}
.runbar {
  position: relative;
}
.run-progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, rgba(var(--fg-rgb), 0.6), rgb(var(--accent-rgb)));
  border-radius: inherit;
  transition: width 0.5s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.run-progress.indeterminate > span {
  width: 40% !important;
  transition: none;
  animation: runIndet 1.15s ease-in-out infinite;
}
@keyframes runIndet {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(320%);
  }
}

/* ── animated counter bump ───────────────────────────────────────────────── */
.run-found b {
  display: inline-block;
  transition: transform 0.18s ease;
}
.run-found b.bump {
  transform: scale(1.28);
}

/* ── token/proxy line validation ─────────────────────────────────────────── */
.tm-add textarea.invalid {
  box-shadow: inset 0 0 0 1.5px rgba(239, 68, 68, 0.7);
  border-radius: 12px;
}
.tm-invalid {
  margin: 8px 2px 0;
  font-size: 12px;
  color: #f87171;
  line-height: 1.4;
}

/* ── results toolbar (filter + sort) ─────────────────────────────────────── */
.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.results-count {
  color: var(--muted);
  font-weight: 500;
}
.results-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.result-list {
  margin-top: 12px;
}
.rt-search {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 40px;
  border-radius: 12px;
}
.rt-search .rt-ic {
  display: inline-flex;
  width: 16px;
  height: 16px;
  color: var(--muted);
  flex: 0 0 auto;
}
.rt-search .rt-ic .ic {
  width: 16px;
  height: 16px;
}
.rt-input {
  flex: 1 1 auto;
  background: none;
  border: 0;
  outline: none;
  color: var(--txt);
  font-size: 13.5px;
  font-family: inherit;
  height: 100%;
}
.rt-input::placeholder {
  color: var(--muted);
}
.rt-sort {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 34px 0 13px;
  border-radius: 12px;
  background: rgba(var(--fg-rgb), 0.05);
  border: 1px solid rgba(var(--fg-rgb), 0.09);
  color: var(--txt);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.rt-sort option {
  background: #17171a;
  color: var(--txt);
}

/* ── themed select control — avoids the native Windows option popup ─────── */
.select-control {
  position: relative;
  min-width: 0;
  height: 40px;
  color: var(--txt);
  font-size: 13px;
  font-family: inherit;
}
.select-control.rt-sort,
.select-control.proxy-move,
.select-control.account-role-move {
  padding: 0;
  border: 0;
  background: none;
  background-image: none;
}
.select-control.proxy-move {
  width: 106px;
  height: 32px;
  min-height: 32px;
  font-size: 10.5px;
}
.select-control.proxy-move .select-trigger {
  padding: 0 7px 0 9px;
  border-radius: 9px;
}
.select-trigger {
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 0 11px 0 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--txt);
  font: inherit;
  text-align: left;
  border-radius: 12px;
  border: 1px solid rgba(var(--fg-rgb), 0.11);
  background: linear-gradient(180deg, rgba(var(--fg-rgb), 0.07), rgba(var(--fg-rgb), 0.035));
  box-shadow: inset 0 1px 0 rgba(var(--fg-rgb), 0.035);
  transition:
    border-color 0.16s,
    background 0.16s,
    box-shadow 0.16s;
}
.select-value {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.select-arrow {
  flex: 0 0 auto;
  color: var(--muted);
  transition:
    transform 0.18s ease,
    color 0.18s;
}
.select-arrow .ic {
  width: 15px;
  height: 15px;
}
.select-control.open .select-trigger {
  border-color: rgba(var(--fg-rgb), 0.4);
  background: rgba(var(--fg-rgb), 0.09);
  box-shadow: 0 0 0 3px rgba(var(--fg-rgb), 0.08);
}
.select-control.open .select-arrow {
  transform: rotate(180deg);
  color: var(--txt);
}
.select-control.disabled {
  opacity: 0.48;
  pointer-events: none;
}
.select-popover {
  position: fixed;
  z-index: 220;
  padding: 5px;
  overflow-y: auto;
  opacity: 0;
  transform: translateY(-5px) scale(0.985);
  transform-origin: top center;
  border-radius: 13px;
  background: rgba(18, 18, 21, 0.98);
  box-shadow:
    0 18px 55px rgba(0, 0, 0, 0.72),
    inset 0 1px 0 rgba(var(--fg-rgb), 0.08);
  transition:
    opacity 0.14s ease,
    transform 0.14s ease;
}
.select-popover.show {
  opacity: 1;
  transform: none;
}
.select-option {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  transition:
    color 0.12s,
    background 0.12s;
}
.select-option > span:first-child {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.select-option .ic {
  width: 15px;
  height: 15px;
}
.select-option.selected {
  color: var(--txt);
  background: rgba(var(--fg-rgb), 0.09);
  font-weight: 650;
}
.select-option:hover,
.select-option:focus-visible {
  color: var(--txt);
  background: rgba(var(--fg-rgb), 0.12);
  outline: none;
}
.select-option:disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* ── command palette (Ctrl / ⌘ + K) ──────────────────────────────────────── */
.cmdk-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 16px;
  animation: cmdkFade 0.16s ease both;
}
@keyframes cmdkFade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.cmdk {
  width: min(560px, 96vw);
  max-height: 62vh;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: cmdkPop 0.2s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
@keyframes cmdkPop {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.cmdk-input {
  border: 0;
  outline: none;
  background: rgba(var(--fg-rgb), 0.04);
  color: var(--txt);
  font-size: 15px;
  font-family: inherit;
  padding: 17px 18px;
  border-bottom: 1px solid var(--glass-brd);
}
.cmdk-input::placeholder {
  color: var(--muted);
}
.cmdk-list {
  overflow-y: auto;
  padding: 7px;
}
.cmdk-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 11px;
  cursor: pointer;
  color: var(--txt);
}
.cmdk-item.active {
  background: rgba(var(--fg-rgb), 0.09);
}
.cmdk-ic {
  display: inline-flex;
  width: 17px;
  height: 17px;
  color: var(--muted);
  flex: 0 0 auto;
}
.cmdk-ic .ic {
  width: 17px;
  height: 17px;
}
.cmdk-label {
  flex: 1 1 auto;
  font-size: 13.5px;
}
.cmdk-hint {
  flex: 0 0 auto;
  font-size: 10.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(var(--fg-rgb), 0.05);
  padding: 3px 8px;
  border-radius: 999px;
}
.cmdk-empty {
  padding: 22px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ── keyboard focus rings for new controls ───────────────────────────────── */
.rt-input:focus-visible,
.rt-sort:focus-visible,
.select-trigger:focus-visible,
.cmdk-input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ── reduced motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .blob {
    animation: none !important;
  }
  .fx {
    display: none !important;
  }
  .card.skeleton .sk-line,
  .card.skeleton .sk-box {
    animation: none !important;
  }
  .run-progress.indeterminate > span {
    animation: none !important;
  }
}
