/* ============================================================
   TribeMate — AI assistant surfaces
   Built on the global.css token set (see public/css/global.css)
   ============================================================ */

:root {
  --tm-glow: linear-gradient(135deg, #5850ec 0%, #8b5cf6 50%, #ec4899 100%);
  --tm-glow-soft: linear-gradient(135deg, rgba(88, 80, 236, .12), rgba(139, 92, 246, .12));
}

/* ── Shared mark ─────────────────────────────────────────── */
.tm-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: var(--r-full);
  background: var(--tm-glow);
  color: #fff;
}

.tm-mark svg { width: 58%; height: 58%; }
.tm-mark-sm { width: 24px; height: 24px; }
.tm-mark-md { width: 34px; height: 34px; }
.tm-mark-lg { width: 52px; height: 52px; }

/* ── Floating launcher ───────────────────────────────────── */
.tm-launcher {
  --tm-launcher-lift: 0px;
  position: fixed;
  right: 22px;
  bottom: calc(24px + var(--tm-launcher-lift));
  z-index: var(--z-drawer);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: none;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, #5850ec, #ec4899, #06b6d4, #5850ec);
  background-size: 300% 300%;
  color: #fff;
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(88, 80, 236, .38);
  transition: bottom var(--dur-base) var(--ease), transform var(--dur-base) var(--ease-spring), box-shadow var(--dur-base) var(--ease);
  animation: tm-launcher-bg 3.2s linear infinite;
}

.tm-launcher:hover {
  transform: translateY(-2px) scale(1.06);
  box-shadow: 0 12px 36px rgba(88, 80, 236, .48);
}
.tm-launcher:active { transform: translateY(0) scale(.96); }
.tm-launcher svg {
  width: 22px;
  height: 22px;
  animation: tm-launcher-spin 4.5s linear infinite;
}
.tm-launcher .tm-launcher-label { display: none; }
.tm-launcher.is-hidden { display: none; }

@media (max-width: 1023px) {
  .tm-launcher {
    right: 16px;
    bottom: calc(var(--bottom-nav-h) + 16px + var(--tm-launcher-lift));
    width: 48px;
    height: 48px;
  }
  .tm-launcher svg { width: 20px; height: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .tm-launcher,
  .tm-launcher svg { animation: none; }
}

@keyframes tm-launcher-bg {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

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

/* ── Slide-in panel ──────────────────────────────────────── */
.tm-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform var(--dur-slow) var(--ease), visibility 0s linear var(--dur-slow);
  overflow: hidden;
}

.tm-panel.is-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition: transform var(--dur-slow) var(--ease), visibility 0s;
}

.tm-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: rgba(12, 11, 20, .45);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease), visibility var(--dur-base);
}

.tm-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.tm-panel-header {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tm-panel-header .tm-mark { flex-shrink: 0; margin-top: 2px; }
.tm-panel-header .tm-icon-btn { flex-shrink: 0; }

.tm-panel-title {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1.3;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow-wrap: break-word;
  word-break: normal;
}

.tm-panel-title[contenteditable="true"] {
  display: block;
  -webkit-line-clamp: unset;
  line-clamp: unset;
  overflow: visible;
  white-space: normal;
}

.tm-panel-sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tm-panel-head-text { flex: 1; min-width: 0; overflow: hidden; }
.tm-panel-title.is-editable { cursor: text; }
.tm-panel-title.is-editable:hover { color: var(--primary); }

.tm-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.tm-icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.tm-icon-btn svg { width: 17px; height: 17px; }

/* Context chip */
.tm-context {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--primary-faint);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-xs);
  color: var(--primary-dark);
}

[data-theme="dark"] .tm-context { background: rgba(88, 80, 236, .12); color: var(--primary-light); }
.tm-context svg { width: 13px; height: 13px; flex-shrink: 0; }
.tm-context span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Messages */
.tm-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.tm-msg { display: flex; gap: var(--sp-3); animation: tm-rise var(--dur-base) var(--ease-out); }
.tm-msg-user { flex-direction: row-reverse; }

@keyframes tm-rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.tm-bubble {
  max-width: 82%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  font-size: var(--text-sm);
  line-height: 1.62;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.tm-msg-user .tm-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: var(--r-xs);
}

.tm-msg-ai .tm-bubble {
  background: var(--surface-alt);
  color: var(--text);
  border-bottom-left-radius: var(--r-xs);
}

/* Markdown inside bubbles */
.tm-bubble p { margin: 0 0 .6em; }
.tm-bubble p:last-child { margin-bottom: 0; }
.tm-bubble ul, .tm-bubble ol { margin: 0 0 .6em; padding-left: 1.15em; }
.tm-bubble li { margin-bottom: .25em; }
.tm-bubble strong { font-weight: 700; }
.tm-bubble h1, .tm-bubble h2, .tm-bubble h3 {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  margin: .8em 0 .4em;
}
.tm-bubble h1:first-child, .tm-bubble h2:first-child, .tm-bubble h3:first-child { margin-top: 0; }
.tm-bubble blockquote {
  margin: 0 0 .6em;
  padding: 0 0 0 .75em;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}
.tm-bubble a { color: var(--primary); text-decoration: underline; }
.tm-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .86em;
  padding: 1px 5px;
  border-radius: var(--r-xs);
  background: rgba(88, 80, 236, .12);
}
.tm-msg-user .tm-bubble code { background: rgba(255, 255, 255, .22); }
.tm-bubble pre {
  margin: 0 0 .6em;
  padding: var(--sp-3);
  border-radius: var(--r-sm);
  background: #16151f;
  color: #e6e4f5;
  overflow-x: auto;
  font-size: .82em;
  line-height: 1.5;
}
.tm-bubble pre code { background: none; padding: 0; color: inherit; }
.tm-bubble hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: .7em 0;
}
.tm-bubble .tm-table-wrap {
  overflow-x: auto;
  margin: 0 0 .6em;
  max-width: 100%;
}
.tm-bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92em;
}
.tm-bubble th,
.tm-bubble td {
  border: 1px solid var(--border);
  padding: .35em .55em;
  text-align: left;
  vertical-align: top;
}
.tm-bubble th {
  font-weight: 700;
  background: var(--surface);
}

/* Typing indicator */
.tm-typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.tm-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: tm-bounce 1.3s infinite ease-in-out;
}
.tm-typing i:nth-child(2) { animation-delay: .16s; }
.tm-typing i:nth-child(3) { animation-delay: .32s; }

@keyframes tm-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Message actions (copy / feedback) */
.tm-msg-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-top: var(--sp-2);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}

.tm-msg-ai:hover .tm-msg-actions, .tm-msg-actions.is-set { opacity: 1; }

.tm-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.tm-act:hover { background: var(--surface-hover); color: var(--text-secondary); }
.tm-act svg { width: 14px; height: 14px; }
.tm-act.is-active-up { color: var(--success); }
.tm-act.is-active-down { color: var(--danger); }

/* Empty state + suggestion chips */
.tm-empty { text-align: center; padding: var(--sp-8) var(--sp-4); }
.tm-empty-title { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 700; margin: var(--sp-4) 0 var(--sp-2); }
.tm-empty-text { font-size: var(--text-sm); color: var(--text-muted); line-height: 1.6; max-width: 300px; margin: 0 auto var(--sp-5); }

.tm-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; }

.tm-chip {
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}

.tm-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-faint); }

.tm-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--sp-2);
}
.tm-suggest[hidden] { display: none !important; }
.tm-suggest-chip {
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-alt);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}
.tm-suggest-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-faint);
}

.tm-attach-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: var(--sp-2);
  padding: 8px 10px;
  border: 1px solid rgba(88, 80, 236, 0.25);
  border-radius: var(--r-md);
  background: var(--primary-faint, rgba(88, 80, 236, 0.08));
}
.tm-attach-file {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tm-attach-modes { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.tm-mode-chip {
  padding: 5px 10px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
}
.tm-mode-chip.is-active {
  border-color: rgba(88, 80, 236, .45);
  background: var(--surface);
  color: var(--primary);
}
.tm-attach-clear {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.tm-attach-clear svg { width: 14px; height: 14px; }
.tm-attach-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.tm-attach-btn:hover { color: var(--primary); background: var(--primary-faint); }
.tm-attach-btn svg { width: 18px; height: 18px; }
.tm-attach-btn:disabled { opacity: .45; cursor: not-allowed; }

/* Composer */
.tm-composer { border-top: 1px solid var(--border); padding: var(--sp-3) var(--sp-4) var(--sp-4); background: var(--surface); }

.tm-composer-row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-alt);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.tm-composer-row:focus-within { border-color: var(--primary); box-shadow: var(--shadow-glow-sm); }

.tm-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.55;
  max-height: 132px;
  padding: 6px 4px;
}

.tm-input::placeholder { color: var(--text-faint); }

.tm-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--r-md);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}

.tm-send:hover:not(:disabled) { background: var(--primary-dark); }
.tm-send:disabled { opacity: .45; cursor: not-allowed; }
.tm-send svg { width: 16px; height: 16px; }

.tm-quota {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.tm-quota a { color: var(--primary); font-weight: 600; text-decoration: none; }
.tm-quota a:hover { text-decoration: underline; }
.tm-quota-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: var(--r-full);
  background: var(--tm-glow);
  color: #fff;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* ── Paywall modal ───────────────────────────────────────── */
.tm-paywall {
  position: fixed;
  inset: 0;
  z-index: var(--z-toast);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: rgba(12, 11, 20, .6);
  backdrop-filter: blur(4px);
}

.tm-paywall.is-open { display: flex; animation: tm-fade var(--dur-base) var(--ease-out); }

@keyframes tm-fade { from { opacity: 0; } to { opacity: 1; } }

.tm-paywall-card {
  position: relative;
  width: min(440px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  animation: tm-pop var(--dur-slow) var(--ease-spring);
}

@keyframes tm-pop {
  from { opacity: 0; transform: translateY(18px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.tm-paywall-top {
  padding: var(--sp-8) var(--sp-6) var(--sp-6);
  text-align: center;
  background: var(--tm-glow);
  color: #fff;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
}

.tm-paywall-top .tm-mark { background: rgba(255, 255, 255, .2); margin: 0 auto var(--sp-4); }
.tm-paywall-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; opacity: .85; }
.tm-paywall-title { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 800; margin: var(--sp-2) 0 var(--sp-2); line-height: 1.18; }
.tm-paywall-lead { font-size: var(--text-sm); opacity: .92; line-height: 1.55; }

.tm-paywall-body { padding: var(--sp-6); }

.tm-price { text-align: center; margin-bottom: var(--sp-5); }
.tm-price-amount { font-family: var(--font-display); font-size: var(--text-4xl); font-weight: 800; color: var(--text); line-height: 1; }
.tm-price-period { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--sp-1); }

.tm-perks { list-style: none; margin: 0 0 var(--sp-6); padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.tm-perks li { display: flex; align-items: flex-start; gap: var(--sp-3); font-size: var(--text-sm); color: var(--text-secondary); line-height: 1.5; }
.tm-perks svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; color: var(--success); }

.tm-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--r-md);
  background: var(--tm-glow);
  color: #fff;
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-base) var(--ease);
}

.tm-cta:hover { transform: translateY(-1px); box-shadow: 0 10px 26px rgba(88, 80, 236, .34); }

.tm-paywall-dismiss {
  display: block;
  width: 100%;
  margin-top: var(--sp-3);
  padding: 9px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  cursor: pointer;
}

.tm-paywall-dismiss:hover { color: var(--text); }

.tm-paywall-close {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, .2);
  color: #fff;
  cursor: pointer;
}

.tm-paywall-close:hover { background: rgba(255, 255, 255, .32); }
.tm-paywall-close svg { width: 15px; height: 15px; }

/* ── Inline "generate with TribeMate" buttons ────────────── */
.tm-inline-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: var(--tm-glow-soft);
  color: var(--primary);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}

.tm-inline-btn:hover:not(:disabled) { background: var(--primary); color: #fff; }
.tm-inline-btn:disabled { opacity: .6; cursor: not-allowed; }
.tm-inline-btn svg { width: 14px; height: 14px; }

.tm-spin { animation: tm-rotate .9s linear infinite; }
@keyframes tm-rotate { to { transform: rotate(360deg); } }

/* ── AI author badge (comments, chat, profile) ───────────── */
.tm-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: var(--r-full);
  background: var(--tm-glow);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  vertical-align: middle;
}

.tm-badge svg { width: 9px; height: 9px; }

/* Placeholder shown between tagging TribeMate and its reply arriving. */
.tm-awaiting {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-lg);
  background: var(--tm-tint, var(--surface-2));
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
}

/* ── Generation modal (owner tools / post writer) ────────── */
.tm-gen-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: rgba(12, 11, 20, .55);
  backdrop-filter: blur(3px);
}

.tm-gen-backdrop.is-open { display: flex; }

.tm-gen-card {
  width: min(520px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  animation: tm-pop var(--dur-base) var(--ease-spring);
}

.tm-gen-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.tm-gen-title { font-family: var(--font-display); font-size: var(--text-base); font-weight: 700; }
.tm-gen-sub { font-size: var(--text-xs); color: var(--text-muted); margin-top: 1px; }
.tm-gen-body { padding: var(--sp-5); overflow-y: auto; }
.tm-gen-foot { display: flex; gap: var(--sp-2); justify-content: flex-end; padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); }

.tm-field { margin-bottom: var(--sp-4); }
.tm-field:last-child { margin-bottom: 0; }
.tm-label { display: block; font-size: var(--text-xs); font-weight: 600; color: var(--text-secondary); margin-bottom: var(--sp-2); }

.tm-control {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-alt);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.tm-control:focus { border-color: var(--primary); box-shadow: var(--shadow-glow-sm); }
textarea.tm-control { resize: vertical; min-height: 88px; line-height: 1.55; }

.tm-row { display: flex; gap: var(--sp-3); }
.tm-row > * { flex: 1; }

.tm-preview {
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-alt);
  font-size: var(--text-sm);
  line-height: 1.62;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}

.tm-hidden { display: none !important; }

/* ── Post view count ─────────────────────────────────────── */
.tm-views {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.tm-views svg { width: 14px; height: 14px; }

.tm-fill-mount {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.tm-fill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(88, 80, 236, 0.28);
  background: linear-gradient(135deg, rgba(88, 80, 236, 0.12), rgba(236, 72, 153, 0.1));
  color: var(--primary, #5850ec);
  font-size: 11px;
  font-weight: 800;
  font-family: var(--font-display, inherit);
  cursor: pointer;
  white-space: nowrap;
}

.tm-fill-btn svg {
  width: 12px;
  height: 12px;
  animation: tm-sidebar-spin 3.2s ease-in-out infinite;
}

.tm-fill-btn:hover {
  border-color: rgba(88, 80, 236, 0.5);
}

.tm-fill-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

.tm-fill-btn[hidden] { display: none; }

.tm-fill-spin {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(88, 80, 236, 0.25);
  border-top-color: var(--primary, #5850ec);
  border-radius: 999px;
  animation: tm-spin 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .tm-fill-btn svg,
  .tm-fill-spin { animation: none; }
}

.sidebar-link-tribemate {
  background: linear-gradient(135deg, rgba(88, 80, 236, 0.12), rgba(236, 72, 153, 0.1));
  border: 1px solid rgba(88, 80, 236, 0.22);
}

.sidebar-link-tribemate.active,
.sidebar-link-tribemate:hover {
  background: linear-gradient(135deg, rgba(88, 80, 236, 0.2), rgba(236, 72, 153, 0.16));
}

.tm-sidebar-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: linear-gradient(135deg, #5850ec, #ec4899, #06b6d4, #5850ec);
  background-size: 300% 300%;
  color: #fff;
  flex-shrink: 0;
  animation: tm-sidebar-icon-bg 3.2s linear infinite;
}

.tm-sidebar-icon svg {
  width: 13px;
  height: 13px;
  animation: tm-sidebar-spin 3.2s ease-in-out infinite;
}

.sidebar-link-tribemate .sidebar-link-label {
  background: linear-gradient(90deg, #5850ec, #ec4899, #06b6d4, #5850ec);
  background-size: 300% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: tm-sidebar-hue 3.5s linear infinite;
  font-weight: 800;
}

.tm-sidebar-badge {
  margin-left: auto;
  font-size: 9px;
  font-weight: 800;
  font-family: var(--font-display);
  letter-spacing: .02em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(90deg, #5850ec, #ec4899);
  white-space: nowrap;
  flex-shrink: 0;
}

.sidebar-owner-icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: currentColor;
}

.sidebar-owner-icon svg {
  width: 20px;
  height: 20px;
}

.sidebar-owner-badge {
  margin-left: auto;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #5850ec, #8b5cf6);
  color: #fff;
  flex-shrink: 0;
}

.sidebar-owner-badge svg {
  width: 11px;
  height: 11px;
}

@keyframes tm-sidebar-spin {
  0%, 70%, 100% { transform: rotate(0deg) scale(1); }
  78% { transform: rotate(20deg) scale(1.12); }
  86% { transform: rotate(-14deg) scale(1.08); }
  92% { transform: rotate(0deg) scale(1); }
}

@keyframes tm-sidebar-hue {
  0% { background-position: 0% center; }
  100% { background-position: 300% center; }
}

@keyframes tm-sidebar-icon-bg {
  0% { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .tm-sidebar-icon,
  .tm-sidebar-icon svg,
  .sidebar-link-tribemate .sidebar-link-label {
    animation: none;
  }
}

/* ── Chat history drawer ─────────────────────────────────── */

.tm-history {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease);
}

.tm-history.is-open { transform: translateX(0); }

.tm-history-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.tm-history-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
}

.tm-history-search-wrap {
  padding: var(--sp-3) var(--sp-4) 0;
}

.tm-history-search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-alt);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  outline: none;
}

.tm-history-search:focus {
  border-color: var(--primary);
  box-shadow: var(--shadow-glow-sm);
}

.tm-history-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3) var(--sp-4);
}

.tm-history-foot {
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  border-top: 1px solid var(--border);
}

.tm-history-load-more {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-alt);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.tm-history-load-more:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tm-history-group { margin-bottom: var(--sp-4); }

.tm-history-group-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
  padding: 0 var(--sp-1);
}

.tm-history-item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.tm-history-item:hover { background: var(--surface-hover); }
.tm-history-item.is-active {
  background: var(--primary-faint);
  border-color: rgba(88, 80, 236, .22);
}

.tm-history-item-main { flex: 1; min-width: 0; }

.tm-history-item-title {
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tm-history-item-preview {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.45;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tm-history-item-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  font-size: 11px;
  color: var(--text-faint);
}

.tm-history-chip {
  display: inline-flex;
  padding: 2px 7px;
  border-radius: var(--r-full);
  background: var(--surface-alt);
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.tm-history-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.tm-history-item:hover .tm-history-delete,
.tm-history-delete:focus { opacity: 1; }

.tm-history-pin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.tm-history-item:hover .tm-history-pin,
.tm-history-pin:focus,
.tm-history-pin.is-active { opacity: 1; }

.tm-history-pin:hover,
.tm-history-pin.is-active {
  background: rgba(88, 80, 236, .12);
  color: var(--primary);
}

.tm-history-pin svg { width: 15px; height: 15px; }

.tm-icon-btn.is-active {
  background: rgba(88, 80, 236, .12);
  color: var(--primary);
}

.tm-history-delete:hover {
  background: rgba(239, 68, 68, .12);
  color: var(--danger);
}

.tm-history-delete svg { width: 15px; height: 15px; }

.tm-history-empty,
.tm-history-skeleton {
  text-align: center;
  padding: var(--sp-8) var(--sp-4);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.tm-history-skeleton {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  align-items: stretch;
}

.tm-history-skeleton i {
  display: block;
  height: 64px;
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--surface-alt), var(--surface-hover), var(--surface-alt));
  background-size: 200% 100%;
  animation: tm-shimmer 1.2s infinite linear;
}

@keyframes tm-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Tabs (Chat | Images) ───────────────────────────────── */
.tm-tabs {
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tm-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.tm-tab svg { width: 14px; height: 14px; }
.tm-tab:hover { background: var(--surface-hover); color: var(--text); }
.tm-tab.is-active {
  background: var(--tm-glow-soft);
  color: var(--primary);
  border-color: rgba(88, 80, 236, .18);
}

.tm-tab-panels {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tm-tab-panel {
  flex: 1;
  min-height: 0;
  display: none;
  flex-direction: column;
}

.tm-tab-panel.is-active { display: flex; }

/* ── Image Studio ───────────────────────────────────────── */
.tm-studio {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.tm-studio-intro {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: 1.5;
  padding: var(--sp-3);
  border-radius: var(--r-md);
  background: var(--tm-glow-soft);
}

.tm-studio-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.tm-studio-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tm-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.tm-chip:has(input:checked) {
  border-color: rgba(88, 80, 236, .45);
  background: var(--tm-glow-soft);
  color: var(--primary);
}

.tm-chip input { accent-color: var(--primary); }

.tm-studio-price-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}

.tm-studio-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
}

.tm-studio-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-glow-sm);
}

.tm-studio-drop {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-lg);
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  cursor: pointer;
  background: var(--surface-alt);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}

.tm-studio-drop:hover,
.tm-studio-drop.is-drag {
  border-color: var(--primary);
  background: var(--tm-glow-soft);
}

.tm-studio-drop-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.tm-studio-drop-copy span {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.tm-studio-queue {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: var(--sp-2);
}

.tm-studio-thumb {
  position: relative;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  aspect-ratio: 1;
}

.tm-studio-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tm-studio-thumb-x {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: var(--r-full);
  background: rgba(12, 11, 20, .72);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.tm-studio-thumb-x svg { width: 12px; height: 12px; }

.tm-studio-thumb-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 4px 6px;
  font-size: 9px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.7));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tm-studio-progress {
  font-size: var(--text-xs);
  color: var(--primary);
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: var(--tm-glow-soft);
}

.tm-studio-run {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: var(--r-full);
  background: var(--tm-glow);
  color: #fff;
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(88, 80, 236, .28);
}

.tm-studio-run:disabled {
  opacity: .45;
  cursor: not-allowed;
  box-shadow: none;
}

.tm-studio-run svg { width: 16px; height: 16px; }

.tm-studio-results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--sp-2);
  font-size: var(--text-sm);
}

.tm-studio-dl-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: var(--r-full);
  padding: 6px 10px;
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
}

.tm-studio-dl-all svg { width: 14px; height: 14px; }

.tm-studio-results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

.tm-studio-result {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
}

.tm-studio-result img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background:
    linear-gradient(45deg, #e8e6f5 25%, transparent 25%),
    linear-gradient(-45deg, #e8e6f5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e6f5 75%),
    linear-gradient(-45deg, transparent 75%, #e8e6f5 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #fff;
}

.tm-studio-result span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tm-studio-result svg { width: 13px; height: 13px; }
