/**
 * AI Tools menu and popup
 * Toolbar dropdown + full-view iframe with Export / Share / Email
 */

/* ========================================
   SEPARATOR (logo | AI Tools)
   ======================================== */

.header__left-sep {
  width: 1px;
  height: 20px;
  background: var(--color-border, #e2e8f0);
  margin: 0 4px;
  flex-shrink: 0;
}

/* ========================================
   AI TOOLS TRIGGER & DROPDOWN
   ======================================== */

.ai-tools {
  position: relative;
  flex-shrink: 0;
}

.ai-tools__trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  background: var(--color-surface, #fff);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text, #334155);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ai-tools__trigger:hover {
  background: var(--color-surface-secondary, #f8fafc);
  border-color: var(--color-border-strong, #cbd5e1);
}

.ai-tools__trigger[aria-expanded="true"] {
  background: var(--color-surface-secondary, #f1f5f9);
  border-color: var(--color-primary, #2563EB);
  color: var(--color-primary, #2563EB);
}

.ai-tools__icon {
  font-size: 16px;
  line-height: 1;
}

.ai-tools__label {
  white-space: nowrap;
}

.ai-tools__caret {
  font-size: 10px;
  opacity: 0.8;
  transition: transform 0.2s ease;
}

.ai-tools[aria-expanded="true"] .ai-tools__caret {
  transform: rotate(180deg);
}

/* Dropdown panel */
.ai-tools__dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  padding: 12px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  z-index: 1000;
}

.ai-tools.is-open .ai-tools__dropdown {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.ai-tools__tiles {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-tools__tile {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 10px;
  background: var(--color-surface-secondary, #f8fafc);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text, #334155);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.ai-tools__tile:hover {
  background: var(--color-surface-hover, #f1f5f9);
}

.ai-tools__tile:active {
  transform: scale(0.98);
}

.ai-tools__tile-icon {
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.ai-tools__tile-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========================================
   AI TOOL POPUP (iframe 80–90% viewport)
   ======================================== */

.ai-tool-popup {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
}

.ai-tool-popup[hidden] {
  display: none;
}

.ai-tool-popup__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.ai-tool-popup__wrap {
  position: relative;
  width: 90%;
  height: 90%;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  background: var(--color-surface, #fff);
}

.ai-tool-popup__content {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.ai-tool-popup__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-surface-secondary, #f8fafc);
  position: relative;
  z-index: 1;
}

.ai-tool-popup__title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-tool-popup__title-icon {
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.ai-tool-popup__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text, #334155);
}

.ai-tool-popup__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-tool-popup__checkbox-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.ai-tool-popup__checkbox-group:hover {
  background: var(--color-surface-hover, #f1f5f9);
}

.ai-tool-popup__checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin: 0;
}

.ai-tool-popup__checkbox-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text, #334155);
  cursor: pointer;
  white-space: nowrap;
}

.ai-tool-popup__btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  background: var(--color-surface, #fff);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text, #334155);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ai-tool-popup__btn:hover {
  background: var(--color-surface-secondary, #f1f5f9);
  border-color: var(--color-border-strong, #cbd5e1);
}

.ai-tool-popup__btn--primary {
  background: var(--color-primary, #2563eb);
  border-color: var(--color-primary, #2563eb);
  color: #fff;
}

.ai-tool-popup__btn--primary:hover {
  background: var(--color-primary-hover, #1d4ed8);
  border-color: var(--color-primary-hover, #1d4ed8);
  color: #fff;
}

.ai-tool-popup__sep {
  width: 1px;
  height: 24px;
  background: var(--color-border, #e2e8f0);
  margin: 0 4px;
}

.ai-tool-popup__btn-icon {
  font-size: 14px;
  line-height: 1;
}

.ai-tool-popup__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-left: 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  color: var(--color-text-muted, #64748b);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.ai-tool-popup__close:hover {
  background: var(--color-surface-hover, #f1f5f9);
  color: var(--color-text, #334155);
}

.ai-tool-popup__toast {
  flex-shrink: 0;
  padding: 10px 16px;
  font-size: 13px;
  min-height: 20px;
  background: var(--color-surface-secondary, #f1f5f9);
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  color: var(--color-text, #334155);
  transition: opacity 0.2s ease;
}

.ai-tool-popup__toast:empty {
  display: none;
}

.ai-tool-popup__toast.is-success {
  background: #ecfdf5;
  color: #065f46;
}

.ai-tool-popup__toast.is-info {
  background: #eff6ff;
  color: #1e40af;
}

.ai-tool-popup__toast.is-warning {
  background: #fffbeb;
  color: #92400e;
}

.ai-tool-popup__toast.is-error {
  background: #fef2f2;
  color: #991b1b;
}

.ai-tool-popup__frame-wrap {
  flex: 1;
  min-height: 0;
  background: #fff;
}

.ai-tool-popup__frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

@media (max-width: 768px) {
  .ai-tool-popup__btn-label {
    display: none;
  }

  .ai-tool-popup {
    padding: 12px;
  }

  .ai-tool-popup__wrap {
    width: 95%;
    height: 95%;
  }
}

@media (max-width: 1024px) {
  .ai-tools__label {
    display: none;
  }
}
