/* Copy of thread_mind_chrome_ext/content.css, so the homepage previews look exactly like the real popups.
   Keep it in step: cp ../thread_mind_chrome_ext/content.css app/assets/stylesheets/extension_popup.css (then re-add this note). */
/**
 * Styles for the UI Thread Mind injects into web pages (ellipsis icon, reply / summary / rewrite popups).
 *
 * It is loaded into a shadow root (see content/shared-ui.js), so page CSS cannot change how
 * these look and none of this leaks into the page.
 *
 * Colors: blue = summary, green = reply, orange = rewrite. Text colors on filled buttons
 * meet WCAG AA contrast.
 */

/* Stop anything inheritable (font, color, direction...) from the page reaching into the shadow root */
:host {
  all: initial;
}

.thread-mind-popup {
  --tm-text: #202124;
  --tm-muted: #5f6368;
  --tm-border: #dadce0;
  --tm-surface: #f8f9fa;
  --tm-blue: #1a73e8;
  --tm-blue-dark: #1557b0;
  --tm-green: #188038;
  --tm-green-dark: #0d652d;
  --tm-orange: #b85c00;
  --tm-orange-dark: #9a4d00;
  --tm-purple: #7627bb;
  --tm-purple-bg: #f3e8fd;
  --tm-purple-bg-hover: #e9d2fc;

  /* Button icons (Material Symbols, Apache 2.0), drawn with a CSS mask so they follow the text color */
  --tm-icon-copy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z'/%3E%3C/svg%3E");
  --tm-icon-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
  --tm-icon-summary: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M14 17H4v2h10v-2zm6-8H4v2h16V9zM4 15h16v-2H4v2zM4 5v2h16V5H4z'/%3E%3C/svg%3E");
  --tm-icon-reply: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 9V5l-7 7 7 7v-4.1c5 0 8.5 1.6 11 5.1-1-5-4-10-11-11z'/%3E%3C/svg%3E");
  --tm-icon-replace: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z'/%3E%3C/svg%3E");
  --tm-icon-rewrite: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7.5 5.6L10 7 8.6 4.5 10 2 7.5 3.4 5 2l1.4 2.5L5 7zm12 9.8L17 14l1.4 2.5L17 19l2.5-1.4L22 19l-1.4-2.5L22 14zM22 2l-2.5 1.4L17 2l1.4 2.5L17 7l2.5-1.4L22 7l-1.4-2.5zm-7.63 5.29c-.39-.39-1.02-.39-1.41 0L1.29 18.96c-.39.39-.39 1.02 0 1.41l2.34 2.34c.39.39 1.02.39 1.41 0L16.7 11.05c.39-.39.39-1.02 0-1.41l-2.33-2.35zm-1.03 5.49l-2.12-2.12 2.44-2.44 2.12 2.12-2.44 2.44z'/%3E%3C/svg%3E");
  --tm-icon-login: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M11 7L9.6 8.4l2.6 2.6H2v2h10.2l-2.6 2.6L11 17l5-5-5-5zm9 12h-8v2h8c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2h-8v2h8v14z'/%3E%3C/svg%3E");

  position: absolute;
  width: 460px;
  /* Keep it inside small iframes: 100vw minus padding (32px), border (2px) and a 20px margin */
  max-width: calc(100vw - 54px);
  max-height: calc(100vh - 20px);
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 2147483647;
  padding: 14px 16px 16px;
  border: 1px solid var(--tm-border);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.1);
  color: var(--tm-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Google Sans', sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
  letter-spacing: normal;
  user-select: none;
  animation: threadmind-pop-in 0.14s ease-out;
}

.thread-mind-popup,
.thread-mind-popup * {
  box-sizing: border-box;
}

/* Websites style bare form controls aggressively; start from a clean slate */
.thread-mind-popup button,
.thread-mind-popup input,
.thread-mind-popup select {
  margin: 0;
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
}

@keyframes threadmind-pop-in {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .thread-mind-popup { animation: none; }
}

/* Header: logo, title, token usage, close */
.thread-mind-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
}

.thread-mind-logo {
  display: block;
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 5px;
}

.thread-mind-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--tm-muted);
  font-size: 13px;
  font-weight: 600;
}

.thread-mind-header-tokens {
  display: inline-block;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 3px 10px;
  border-radius: 999px;
  background: #f1f3f4;
  color: #3c4043;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.thread-mind-header-tokens--warn { background: #fef7e0; color: #7a4b00; }
.thread-mind-header-tokens--danger { background: #fce8e6; color: #a50e0e; }

.thread-mind-popup button.thread-mind-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--tm-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.thread-mind-popup button.thread-mind-close:hover {
  background: #f1f3f4;
  color: var(--tm-text);
}

/* The text the user selected */
.thread-mind-content-display {
  max-height: 96px;
  margin: 0 0 12px;
  padding: 9px 12px;
  overflow-y: auto;
  border-left: 3px solid #9aa0a6;
  border-radius: 8px;
  background: var(--tm-surface);
  color: var(--tm-muted);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  user-select: text;
  scrollbar-width: thin;
  scrollbar-color: #dadce0 transparent;
}

.thread-mind-content-display::-webkit-scrollbar { width: 6px; }
.thread-mind-content-display::-webkit-scrollbar-thumb { background: #dadce0; border-radius: 3px; }
.thread-mind-content-display::-webkit-scrollbar-thumb:hover { background: #bdc1c6; }

/* The AI result */
.thread-mind-result {
  --tm-accent: var(--tm-green);
  --tm-accent-bg: #e6f4ea;

  margin: 0 0 12px;
  padding: 10px 12px 12px;
  border-left: 3px solid var(--tm-accent);
  border-radius: 10px;
  background: var(--tm-accent-bg);
}

.thread-mind-result[hidden] { display: none; }

.thread-mind-result--reply { --tm-accent: var(--tm-green); --tm-accent-bg: #e6f4ea; }
.thread-mind-result--summary { --tm-accent: var(--tm-blue); --tm-accent-bg: #e8f0fe; }
.thread-mind-result--rewrite { --tm-accent: var(--tm-orange); --tm-accent-bg: #fef3e0; }

.thread-mind-result-label {
  margin: 0 0 4px;
  color: var(--tm-accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.thread-mind-result-text {
  max-height: 220px;
  overflow-y: auto;
  color: var(--tm-text);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  user-select: text;
}

/* Loading skeleton */
.thread-mind-skeleton {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

.thread-mind-skeleton span {
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.06) 25%, rgba(0, 0, 0, 0.12) 50%, rgba(0, 0, 0, 0.06) 75%);
  background-size: 200% 100%;
  animation: threadmind-shimmer 1.4s infinite;
}

.thread-mind-skeleton span:nth-child(2) { width: 90%; }
.thread-mind-skeleton span:nth-child(3) { width: 65%; }

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

@media (prefers-reduced-motion: reduce) {
  .thread-mind-skeleton span { animation: none; }
}

/* Alerts: errors, warnings, success. An optional action button sits on the right. */
.thread-mind-message {
  display: none;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  padding: 9px 12px;
  border-left: 3px solid #d93025;
  border-radius: 8px;
  background: #fce8e6;
  color: #a50e0e;
  font-size: 13px;
  line-height: 1.4;
}

.thread-mind-message--warning { border-left-color: #f9ab00; background: #fef7e0; color: #7a4b00; }
.thread-mind-message--success { border-left-color: var(--tm-green); background: #e6f4ea; color: var(--tm-green-dark); }

.thread-mind-message-text {
  flex: 1;
  min-width: 0;
}

.thread-mind-popup button.thread-mind-message-action {
  flex: none;
  height: 26px;
  padding: 0 12px;
  border: 0;
  border-radius: 13px;
  background: #d93025;
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.thread-mind-popup button.thread-mind-message-action:hover { background: #b52218; }

.thread-mind-message--warning button.thread-mind-message-action { background: #b06000; }
.thread-mind-message--warning button.thread-mind-message-action:hover { background: #8f4e00; }

/* Actions bar and buttons */
.thread-mind-popup-actions {
  display: flex;
  flex-wrap: wrap; /* longer labels (French, Vietnamese...) move a button group to a second line instead of overflowing */
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid #e8eaed;
}

.thread-mind-popup-actions button,
.thread-mind-popup button.thread-mind-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 34px;
  padding: 0 16px;
  border: 0 !important;
  border-radius: 17px;
  background: #f1f3f4;
  color: #3c4043;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.thread-mind-popup-actions button:hover,
.thread-mind-popup button.thread-mind-btn:hover {
  background: #e8eaed;
}

.thread-mind-popup button:focus-visible,
.thread-mind-popup select:focus-visible,
.thread-mind-popup input:focus-visible,
.thread-mind-popup a:focus-visible {
  outline: 2px solid var(--tm-blue);
  outline-offset: 2px;
}

.thread-mind-popup button:disabled {
  cursor: default;
  opacity: 0.6;
}

.thread-mind-popup-actions button.copy {
  margin-right: auto;
}

/* Copy: a soft purple, distinct from the blue / green / orange action buttons */
.thread-mind-popup-actions button.copy,
.thread-mind-popup button.copy-result-btn {
  background: var(--tm-purple-bg);
  color: var(--tm-purple);
}

.thread-mind-popup-actions button.copy:hover,
.thread-mind-popup button.copy-result-btn:hover {
  background: var(--tm-purple-bg-hover);
}

.thread-mind-popup-actions button.copy.copied,
.thread-mind-popup button.copy-result-btn.copied {
  background: #e6f4ea;
  color: var(--tm-green-dark);
}

.thread-mind-popup-actions button.summary { background: var(--tm-blue); color: #ffffff; }
.thread-mind-popup-actions button.summary:hover { background: var(--tm-blue-dark); }

.thread-mind-popup-actions button.analyze,
.thread-mind-popup button.replace-original-btn { background: var(--tm-green); color: #ffffff; }
.thread-mind-popup-actions button.analyze:hover,
.thread-mind-popup button.replace-original-btn:hover { background: var(--tm-green-dark); }

.thread-mind-popup button.thread-mind-rewrite-btn { background: var(--tm-orange); color: #ffffff; }
.thread-mind-popup button.thread-mind-rewrite-btn:hover { background: var(--tm-orange-dark); }

/* Icon before the label; each button picks its icon with --tm-icon */
.thread-mind-popup-actions button.copy,
.thread-mind-popup button.copy-result-btn { --tm-icon: var(--tm-icon-copy); }
.thread-mind-popup-actions button.copy.copied,
.thread-mind-popup button.copy-result-btn.copied { --tm-icon: var(--tm-icon-check); }
.thread-mind-popup-actions button.summary { --tm-icon: var(--tm-icon-summary); }
.thread-mind-popup-actions button.analyze { --tm-icon: var(--tm-icon-reply); }
.thread-mind-popup button.replace-original-btn { --tm-icon: var(--tm-icon-replace); }
.thread-mind-popup button.thread-mind-rewrite-btn { --tm-icon: var(--tm-icon-rewrite); }
.thread-mind-popup-actions button.thread-mind-login-btn { --tm-icon: var(--tm-icon-login); }

.thread-mind-popup-actions button.copy::before,
.thread-mind-popup button.copy-result-btn::before,
.thread-mind-popup-actions button.summary::before,
.thread-mind-popup-actions button.analyze::before,
.thread-mind-popup button.replace-original-btn::before,
.thread-mind-popup button.thread-mind-rewrite-btn::before,
.thread-mind-popup-actions button.thread-mind-login-btn::before {
  content: '';
  flex: none;
  width: 16px;
  height: 16px;
  background-color: currentColor;
  -webkit-mask: var(--tm-icon) center / contain no-repeat;
  mask: var(--tm-icon) center / contain no-repeat;
}

/* Busy buttons swap the icon for a spinner (declared after the icons so it wins) */
.thread-mind-popup button.thread-mind-btn-loading {
  cursor: progress;
  opacity: 1;
}

.thread-mind-popup button.thread-mind-btn-loading::before {
  content: '';
  flex: none;
  width: 13px;
  height: 13px;
  background-color: transparent;
  -webkit-mask: none;
  mask: none;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: threadmind-spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .thread-mind-popup button.thread-mind-btn-loading::before { animation-duration: 2.4s; }
}

/* Rewrite popup: quick presets, template picker, request input */
.thread-mind-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
}

.thread-mind-popup button.thread-mind-chip {
  height: 26px;
  max-width: 100%;
  min-width: 0;
  padding: 0 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--tm-border);
  border-radius: 13px;
  background: #ffffff;
  color: #3c4043;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.thread-mind-popup button.thread-mind-chip:hover {
  border-color: #bdc1c6;
  background: #f1f3f4;
}

.thread-mind-popup button.thread-mind-chip:disabled {
  opacity: 0.5;
}

.thread-mind-manage-link {
  color: var(--tm-blue);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.thread-mind-manage-link:hover { text-decoration: underline; }

/* "Customize" at the end of the quick actions */
.thread-mind-refine-manage {
  align-self: center;
  margin-left: 4px;
}

.thread-mind-input-container {
  display: flex;
  align-items: center;
  margin: 0 0 10px;
}

.thread-mind-rewrite-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--tm-border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--tm-text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.thread-mind-rewrite-input::placeholder { color: #80868b; }

.thread-mind-rewrite-input:focus {
  border-color: var(--tm-blue);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.18);
}

.thread-mind-checkbox-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  color: var(--tm-muted);
  font-size: 12.5px;
}

.thread-mind-checkbox-container input[type='checkbox'] {
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
}

.thread-mind-checkbox-container label {
  cursor: pointer;
  user-select: none;
}

.thread-mind-popup-actions-left {
  margin-right: auto;
}

.thread-mind-popup-actions-left,
.thread-mind-popup-actions-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.thread-mind-popup-actions-right {
  justify-content: flex-end;
  min-width: 0;
}
