/* ── Tagshop AI Agent – Light Theme ── */

@keyframes ts-grad {
  0%   { background-position: 0%   0%;   }
  25%  { background-position: 100% 0%;   }
  50%  { background-position: 100% 100%; }
  75%  { background-position: 0%   100%; }
  100% { background-position: 0%   0%;   }
}

.tsaa-agent-wrap {
  max-width: 1000px;
  width: 100%;
  margin: 0 auto 20px;
  padding: 0 16px;
  box-sizing: border-box;
  position: relative;
  /* This shortcode gets embedded at very different widths across the site (full-width
     page vs. a narrower column/sidebar). The row-wrapping/truncation rules below need
     to react to THIS widget's own rendered width, not the viewport's - a narrow embed
     inside a wide viewport would otherwise never trigger the "narrow" @media rules and
     the controls would overflow instead of wrapping/shrinking. container-type turns
     this element into a query container so @container rules below can target it. */
  container-type: inline-size;
  container-name: ts-agent;
}

/* Animated gradient border */
.ts-agent-border-outer {
  position: relative;
  border-radius: 16px;
  padding: 2px;
  background: linear-gradient(135deg, #4824fb, #1e3a8a, #2563eb);
  background-size: 300% 300%;
  animation: ts-grad 2s ease-in-out infinite;
}

/* Light inner card. overflow stays visible (not hidden) so absolutely-positioned
   dropdown menus that extend past the card's edges aren't clipped. */
.ts-agent-border-inner {
  background: #ffffff;
  border-radius: 14px;
  padding: 0;
  overflow: visible;
}

.ts-tabs {
  border-radius: 14px 14px 0 0;
  overflow: hidden;
}

.ts-body { padding: 8px; }

/* ── Tabs ── */
.ts-tabs {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
}

.ts-tab {
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 500;
  color: #6b7280;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s;
}

/* This theme's own global `button:hover` rule (style.css) paints every button's
   background purple on hover, including these tabs - text needs to switch to white
   in that state or it's unreadable against it. */
.ts-tab:hover,
.ts-tab.ts-tab-active:hover {
  color: #ffffff;
}

.ts-tab.ts-tab-active {
  color: #111827;
  border-bottom-color: #111827;
}

/* ── Generic upload stub (no real upload — redirects to app) ── */
.ts-upload-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  color: #9ca3af;
  cursor: pointer;
  gap: 3px;
  font-family: inherit;
  transition: background 0.15s;
}

.ts-upload-btn:hover { background: #e5e7eb; }

.ts-upload-label {
  font-size: 9px;
  color: #6b7280;
  line-height: 1.2;
  max-width: 56px;
  text-align: center;
}

/* ── Assets row ── */
.ts-assets-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 4px 0;
}

.ts-assets-row:empty { display: none; }

.ts-asset-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ts-asset-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 12px;
  overflow: visible;
  flex-shrink: 0;
}

.ts-asset-thumb-inner {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  background: #f3f4f6;
}

.ts-asset-thumb-inner img,
.ts-asset-thumb-inner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ts-asset-audio-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.ts-asset-remove {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 0;
  z-index: 2;
}

.ts-asset-thumb:hover .ts-asset-remove { opacity: 1; }

.ts-asset-name {
  font-size: 10px;
  color: #6b7280;
  margin-top: 3px;
}

/* ── Textarea ── */
.ts-textarea-wrap { position: relative; }

.ts-textarea {
  width: 100%;
  min-height: 80px;
  background: transparent;
  color: #111827;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  line-height: 1.5;
  padding: 8px;
  box-sizing: border-box;
  font-family: inherit;
  caret-color: #111827;
}

/* Typing-animation overlay */
.ts-placeholder {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 14px;
  color: #9ca3af;
  pointer-events: none;
  line-height: 1.5;
}

.ts-placeholder.ts-hide { display: none; }

.ts-cursor {
  display: inline-block;
  width: 1px;
  height: 16px;
  background: #9ca3af;
  margin-left: 1px;
  vertical-align: middle;
  animation: ts-blink 1s step-end infinite;
}

@keyframes ts-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Controls row ──
   .ts-controls is a flex row with exactly two items: .ts-controls-left (every
   dropdown/button) and .ts-send-wrap. Video Agent and AI Video both have real Model +
   Reference/Duration-worth of controls - confirmed against the real product, they read
   as two deliberate rows (#ts-row-1: Product/Avatar/Model, #ts-row-2: Ratio/Quality/
   Duration), so .ts-row defaults to a real full-width row, not a fluid pool. AI Image
   is the one exception - it only ever has Model + Ratio + Quality, which the real
   product shows on a single continuous line - JS adds .ts-single-line to
   .ts-controls-left for that tab only, collapsing #ts-row-1/#ts-row-2 into one fluid
   flex-wrap pool via display:contents. Send stays pinned to the top-right of the whole
   block in both cases, never joining either flow, so it can't get stranded mid-wrap. */
.ts-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
}

.ts-controls-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.ts-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.ts-controls-left.ts-single-line {
  flex-direction: row;
  flex-wrap: wrap;
}

.ts-controls-left.ts-single-line .ts-row {
  display: contents;
}

.ts-send-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

/* Continuous 10-60s duration slider (Video Agent tab only) - rendered inside the
   otherwise-generic #ts-duration-menu dropdown panel in place of a preset list. */
.ts-duration-slider-panel {
  padding: 14px 16px;
  width: 160px;
}
.ts-duration-slider-value {
  text-align: center;
  font-weight: 700;
  font-size: 18px;
  color: #111827;
  margin-bottom: 10px;
}
.ts-duration-slider-panel input[type="range"] {
  width: 100%;
  accent-color: #4824fb;
}
.ts-duration-slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #9ca3af;
  margin-top: 6px;
}

@container ts-agent (max-width: 860px) {
  .ts-controls,
  .ts-controls-left,
  .ts-row {
    gap: 6px;
  }
}

/* Below ~480px the controls themselves (not just row gaps) need to shrink, otherwise
   two rows' worth of buttons don't fit on a phone-width screen and wrap into extra
   lines. Shrinking padding/font-size and truncating the longest labels (model name,
   reference type - e.g. "First & Last Frame") keeps every row on one line down to
   narrow phone widths, while everything above 480px stays untouched. */
@container ts-agent (max-width: 480px) {
  .ts-ctrl-btn {
    padding: 5px 8px;
    gap: 4px;
    font-size: 11px;
    height: 30px;
  }

  .ts-model-logo {
    width: 14px;
    height: 14px;
  }

  .ts-model-name {
    max-width: 60px;
  }

  #ts-ref-label {
    display: inline-block;
    max-width: 84px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ts-controls,
  .ts-controls-left,
  .ts-row {
    gap: 4px;
  }

}

/* Genuinely tiny screens (~360px and below): shrink further still. Real truncation on
   .ts-model-name/#ts-ref-label (fixed above) plus these smaller sizes keep both rows
   fitting without any horizontal scroll. */
@container ts-agent (max-width: 360px) {
  .ts-ctrl-btn {
    padding: 4px 6px;
    gap: 3px;
    font-size: 10px;
    height: 28px;
  }

  .ts-model-logo {
    width: 12px;
    height: 12px;
  }

  .ts-model-name {
    max-width: 42px;
  }

  #ts-ref-label {
    max-width: 62px;
  }

  /* Redundant with the ratio text itself (e.g. "9:16") at this size - dropping it
     buys back ~16px, which is the difference between fitting on 2 rows or not. */
  #ts-ratio-icon {
    display: none;
  }

  .ts-controls,
  .ts-controls-left,
  .ts-row {
    gap: 3px;
  }
}

/* Extremely narrow (~340px and below, e.g. an original iPhone SE): every remaining
   bit of width matters. Model logo is decorative once the name itself is already
   truncated, so it's the next thing to drop; labels shrink a little further too. */
@container ts-agent (max-width: 340px) {
  .ts-model-logo {
    display: none;
  }

  .ts-model-name {
    max-width: 36px;
  }

  #ts-ref-label {
    max-width: 54px;
  }
}

/* ── Model dropdown trigger ── */
.ts-model-logo {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}

.ts-model-name {
  /* display:inline-block (+ white-space:nowrap) is required for max-width/ellipsis to
     have any effect at all on a <span> - without it, a plain inline element ignores
     max-width and just renders its full text width, which is what was actually
     forcing the row to overflow on narrow screens despite the max-width being set. */
  display: inline-block;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

/* ── Model dropdown menu (search + list) ── */
.ts-model-menu {
  min-width: 260px;
  max-width: 280px;
  padding: 0;
  display: none;
  flex-direction: column;
  z-index: 999999;
}

.ts-model-menu.ts-open { display: flex; }

.ts-model-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f3f4f6;
  color: #9ca3af;
  flex-shrink: 0;
}

.ts-model-search {
  border: none;
  outline: none;
  background: transparent;
  font-size: 13px;
  color: #111827;
  width: 100%;
  font-family: inherit;
}

.ts-model-list {
  overflow-y: auto;
  max-height: 260px;
  padding-bottom: 6px;
}

.ts-model-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.1s;
}

.ts-model-item:hover,
.ts-model-item.ts-sel { background: #f3f4f6; }

.ts-model-item-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: #f3f4f6;
}

.ts-model-item-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }

.ts-model-item-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.ts-model-item-name {
  font-size: 13px;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: capitalize;
}

.ts-model-item-meta {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: #9ca3af;
}

.ts-model-item-meta-icon {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.ts-model-empty {
  padding: 16px 12px;
  font-size: 12px;
  color: #9ca3af;
  text-align: center;
}

.ts-model-featured-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 12px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: #8b5cf6;
}

/* ── Credits (on send button) ── */
.ts-credits {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* The "N credits" pill (icon + text) is one of the widest controls on the page -
   dropped entirely on mobile to save space (Send still works identically, it just
   shows the arrow icon only there). Placed after the base .ts-credits rule above so
   it actually wins the cascade at this width - an earlier attempt at this same rule
   was placed before the base rule in the file and got silently overridden by it. */
@container ts-agent (max-width: 480px) {
  .ts-credits {
    display: none;
  }
}

.ts-send-btn { gap: 8px; }

/* Base control button – light style */
.ts-ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: #374151;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  font-family: inherit;
  line-height: 1;
  height: 36px;
}

@container ts-agent (min-width: 861px) { .ts-ctrl-btn { padding: 6px 14px; font-size: 13px; } }

.ts-ctrl-btn:hover:not(:disabled) { background: #e5e7eb; }
.ts-ctrl-btn:disabled { opacity: 0.45; pointer-events: none; }

/* Hide label text on mobile */
.ts-label-sm { display: none; }
@container ts-agent (min-width: 640px) { .ts-label-sm { display: inline; } }

/* Send button active */
.ts-send-btn.ts-active {
  background: #111827;
  color: #fff;
  border-color: #111827;
}
.ts-send-btn.ts-active:hover { background: #1f2937; }

/* Chevron */
.ts-chevron { flex-shrink: 0; transition: transform 0.15s; }
.ts-chevron.ts-open { transform: rotate(180deg); }

/* ── Dropdowns ── */
.ts-dd { position: relative; }

.ts-dd-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  /* Higher than this theme's fixed sticky promo bar (z-index: 99999) and any other
     page chrome, so the menu never renders behind something else on the page. */
  z-index: 999999;
  min-width: 100px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
}

.ts-dd-menu.ts-open { display: block; }

.ts-dd-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  text-align: left;
  color: #374151;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
  font-family: inherit;
  box-sizing: border-box;
  white-space: nowrap;
}

.ts-dd-item:hover,
.ts-dd-item.ts-sel { background: #f3f4f6; color: #111827; }

.ts-dd-item-between { justify-content: space-between; align-items: center; }

.ts-dd-item-desc {
  font-size: 10px;
  color: #9ca3af;
  margin-top: 2px;
  white-space: normal;
  max-width: 260px;
  display: block;
}

/* ── Spinner ── */
.ts-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0,0,0,0.15);
  border-top-color: #111;
  border-radius: 50%;
  animation: ts-spin 0.6s linear infinite;
}

@keyframes ts-spin { to { transform: rotate(360deg); } }

/* Backdrop */
.ts-backdrop { position: fixed; inset: 0; z-index: 999998; }
