/* ==========================================================================
   AI Content Generator — Frontend Styles
   ========================================================================== */

/* ─── Reset & base ─────────────────────────────────────────────────────── */
.aicg-app *,
.aicg-app *::before,
.aicg-app *::after { box-sizing: border-box; }

.aicg-app {
  position: relative;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  font-size: 15px;
  color: #1f2937;
  line-height: 1.6;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 60px;
}

/* ─── Screens ──────────────────────────────────────────────────────────── */
/* All screens hidden by default — JS adds .aicg-active to reveal one at a time. */
.aicg-screen { display: none; }
.aicg-screen.aicg-active { display: block; animation: aicgFadeIn 0.2s ease; }
/* Generating screen needs flex layout for vertical centering */
#aicg-screen-generating.aicg-active {
  display: flex;
  min-height: 60vh;
  align-items: center;
  justify-content: center;
}
@keyframes aicgFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ─── Header ───────────────────────────────────────────────────────────── */
.aicg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 0 20px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 24px;
}
.aicg-header h2 { margin: 0; font-size: 1.6rem; color: #111827; }

.aicg-screen-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 0 16px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 24px;
}
.aicg-screen-header h2 { margin: 0; font-size: 1.4rem; }
.aicg-editor-header-info { display: flex; align-items: center; gap: 12px; flex: 1; }
.aicg-editor-screen-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}
.aicg-editor-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

/* ─── Buttons ──────────────────────────────────────────────────────────── */
.aicg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}
.aicg-btn:disabled, .aicg-btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.aicg-btn-primary   { background: #2563eb; color: #fff; }
.aicg-btn-primary:hover { background: #1d4ed8; }
.aicg-btn-success   { background: #059669; color: #fff; }
.aicg-btn-success:hover { background: #047857; }
.aicg-btn-outline   { background: transparent; color: #374151; border-color: #d1d5db; }
.aicg-btn-outline:hover { background: #f9fafb; border-color: #9ca3af; color: #000 !important; }
.aicg-btn-ghost     { background: transparent; color: #6b7280; border-color: transparent; }
.aicg-btn-ghost:hover { color: #1f2937; background: #f3f4f6; }
.aicg-btn-back      { font-size: 13px; padding: 6px 12px; }
.aicg-btn-sm        { padding: 6px 12px; font-size: 13px; }
.aicg-btn-xs        { padding: 4px 8px; font-size: 12px; }
.aicg-btn-lg        { padding: 12px 24px; font-size: 15px; font-weight: 600; }
.aicg-btn-full      { width: 100%; justify-content: center; }

/* ─── Cards ────────────────────────────────────────────────────────────── */
.aicg-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.aicg-card h3 { margin: 0 0 20px; font-size: 1rem; color: #374151; font-weight: 600; }
.aicg-card-disabled { opacity: 0.5; pointer-events: none; }

/* ─── Forms ────────────────────────────────────────────────────────────── */
.aicg-form-group { margin-bottom: 16px; }
.aicg-form-group label { display: block; font-weight: 500; font-size: 13px; color: #374151; margin-bottom: 6px; }
.aicg-form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .aicg-form-row-2 { grid-template-columns: 1fr; } }

.aicg-input, .aicg-select, .aicg-article-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  color: #1f2937;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  font-family: inherit;
}
.aicg-input:focus, .aicg-select:focus, .aicg-article-textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.aicg-input-sm { font-size: 13px; padding: 7px 10px; }
.aicg-required { color: #ef4444; }
.aicg-optional { color: #9ca3af; font-weight: 400; font-size: 12px; }
.aicg-hint { color: #6b7280; font-size: 12px; font-weight: 400; }
.aicg-field-hint { font-size: 12px; color: #6b7280; margin: 4px 0 0; }

/* ─── Tags input ───────────────────────────────────────────────────────── */
.aicg-tag-input-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  min-height: 42px;
  align-items: center;
  cursor: text;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.aicg-tag-input-wrap:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.aicg-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 13px;
  font-weight: 500;
}
.aicg-tag-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #6b7280;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}
.aicg-tag-remove:hover { color: #ef4444; }
.aicg-tag-input { border: none; outline: none; font-size: 13px; min-width: 120px; flex: 1; padding: 2px 0; }

/* ─── Tabs ─────────────────────────────────────────────────────────────── */
.aicg-tab-nav {
  display: flex;
  border-bottom: 2px solid #e5e7eb;
  margin-bottom: 24px;
  gap: 0;
}
.aicg-tab-btn {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 14px;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.aicg-tab-btn:hover { color: #374151; }
.aicg-tab-btn.aicg-tab-active { color: #2563eb; border-bottom-color: #2563eb; }

/* ─── Keyword list ─────────────────────────────────────────────────────── */
.aicg-keyword-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.aicg-keyword-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.aicg-keyword-item:hover { border-color: #93c5fd; background: #eff6ff; }
.aicg-keyword-item.selected { border-color: #2563eb; background: #eff6ff; }
.aicg-keyword-item input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: #2563eb; }
.aicg-keyword-name { font-weight: 500; flex: 1; font-size: 14px; }
.aicg-keyword-meta { display: flex; gap: 16px; }
.aicg-kw-stat { text-align: right; }
.aicg-kw-stat .aicg-kw-val { font-size: 14px; font-weight: 600; color: #1f2937; }
.aicg-kw-stat .aicg-kw-lbl { font-size: 11px; color: #9ca3af; display: block; }

/* ─── Topic list ───────────────────────────────────────────────────────── */
.aicg-topic-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.aicg-topic-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: #fff;
}
.aicg-topic-item:hover { border-color: #93c5fd; background: #eff6ff; }
.aicg-topic-item.selected { border-color: #2563eb; background: #eff6ff; font-weight: 500; }
.aicg-topic-item input[type="radio"] { width: 18px; height: 18px; cursor: pointer; accent-color: #2563eb; margin: 0; }
.aicg-topic-text { font-size: 14px; flex: 1; }

/* ─── Locked summary ───────────────────────────────────────────────────── */
.aicg-locked-summary {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 18px 20px;
  margin-top: 16px;
}
.aicg-summary-item { margin-bottom: 8px; font-size: 14px; }
.aicg-summary-item strong { color: #374151; margin-right: 8px; }
.aicg-btn-group-stack { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* ─── Context bar ──────────────────────────────────────────────────────── */
.aicg-context-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #374151;
  margin-bottom: 8px;
}
.aicg-ctx-sep { color: #d1d5db; }
.aicg-ctx-topic { font-weight: 600; color: #1d4ed8; }
.aicg-keywords-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.aicg-kw-chip {
  background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe;
  border-radius: 4px; padding: 3px 10px; font-size: 12px; font-weight: 500;
}

/* ─── Version navigation ───────────────────────────────────────────────── */
.aicg-version-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f3f4f6;
  margin-bottom: 16px;
}
.aicg-version-indicator { font-size: 13px; color: #6b7280; font-weight: 500; }

/* ─── Editor layout ────────────────────────────────────────────────────── */
.aicg-editor-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) { .aicg-editor-layout { grid-template-columns: 1fr; } }

.aicg-editor-main { flex: 1; }
.aicg-editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}
.aicg-editor-label { font-size: 13px; font-weight: 600; color: #374151; }
.aicg-editor-toggle { display: flex; gap: 4px; }
.aicg-editor-toggle .aicg-active { background: #eff6ff; color: #2563eb; }

.aicg-article-preview {
  border: 1px solid #e5e7eb;
  border-radius: 0 0 8px 8px;
  padding: 24px;
  min-height: 400px;
  background: #fff;
  overflow-x: auto;
}
.aicg-article-textarea {
  border-radius: 0 0 8px 8px;
  border-top: 1px solid #e5e7eb;
  min-height: 500px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
}

/* ─── Article prose styles ─────────────────────────────────────────────── */
.aicg-prose h1 { font-size: 1.9rem; font-weight: 700; color: #111827; margin: 0 0 16px; line-height: 1.25; }
.aicg-prose h2 { font-size: 1.3rem; font-weight: 600; color: #1f2937; margin: 28px 0 12px; }
.aicg-prose h3 { font-size: 1.1rem; font-weight: 600; color: #374151; margin: 20px 0 10px; }
.aicg-prose p  { margin: 0 0 14px; color: #374151; }
.aicg-prose ul, .aicg-prose ol { padding-left: 24px; margin: 0 0 14px; }
.aicg-prose li { margin-bottom: 6px; }
.aicg-prose a  { color: #2563eb; text-decoration: underline; }
.aicg-prose strong { font-weight: 600; }
.aicg-prose em { font-style: italic; }

/* ─── Sidebar ──────────────────────────────────────────────────────────── */
.aicg-editor-sidebar { position: sticky; top: 20px; }
.aicg-sidebar-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 16px;
}
.aicg-sidebar-card h4 { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: #374151; }

/* ─── Metadata panel ───────────────────────────────────────────────────── */
.aicg-metadata-panel { margin-top: 20px; }
.aicg-meta-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.aicg-meta-header h3 { margin: 0; font-size: 1.1rem; }
.aicg-meta-field { margin-bottom: 20px; }
.aicg-meta-field label { display: block; font-size: 12px; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.aicg-meta-value { font-size: 14px; color: #1f2937; background: #f9fafb; padding: 10px 12px; border-radius: 6px; border: 1px solid #e5e7eb; margin: 0; }
.aicg-code-block {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  background: #1e293b;
  color: #e2e8f0;
  padding: 16px;
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
  margin: 0;
}

/* ─── Dashboard table ──────────────────────────────────────────────────── */
.aicg-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
}
.aicg-table thead { background: #f9fafb; }
.aicg-table th { padding: 12px 16px; font-weight: 600; color: #374151; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; text-align: left; border-bottom: 1px solid #e5e7eb; }
.aicg-table td { padding: 14px 16px; border-bottom: 1px solid #f3f4f6; color: #374151; vertical-align: middle; }
.aicg-table tr:last-child td { border-bottom: none; }
.aicg-table tr:hover td { background: #fafafa; }
.aicg-table-actions { white-space: nowrap; }
.aicg-table-loading { text-align: center; padding: 32px; color: #9ca3af; }

/* ─── Status badges ────────────────────────────────────────────────────── */
.aicg-status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  text-transform: capitalize;
}
.aicg-status-draft          { background: #f3f4f6; color: #6b7280; }
.aicg-status-generated      { background: #dbeafe; color: #1d4ed8; }
.aicg-status-sent_for_review { background: #d1fae5; color: #047857; }

/* ─── Notices ──────────────────────────────────────────────────────────── */
.aicg-notice {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  border-left: 4px solid transparent;
}
.aicg-notice:empty {
  display: none !important;
}
.aicg-notice-success { background: #f0fdf4; border-color: #22c55e; color: #166534; }
.aicg-notice-error   { background: #fef2f2; border-color: #ef4444; color: #991b1b; }
.aicg-notice-info    { background: #eff6ff; border-color: #3b82f6; color: #1e40af; }

/* ─── Loading overlays ─────────────────────────────────────────────────── */
.aicg-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.aicg-loading-box {
  background: #fff;
  border-radius: 12px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  max-width: 360px;
}
.aicg-loading-message { margin: 16px 0 0; font-size: 15px; color: #374151; font-weight: 500; }

.aicg-section-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  gap: 14px;
  color: #6b7280;
  font-size: 14px;
}
.aicg-editor-inline-loading { display: flex; align-items: center; gap: 10px; padding: 12px 0; color: #6b7280; font-size: 13px; }

/* ─── Spinners ─────────────────────────────────────────────────────────── */
.aicg-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: aicgSpin 0.7s linear infinite;
  margin: 0 auto;
}
.aicg-spinner-sm { width: 18px; height: 18px; border-width: 2px; }
.aicg-spinner-lg { width: 56px; height: 56px; border-width: 4px; }
@keyframes aicgSpin { to { transform: rotate(360deg); } }

/* ─── Generating screen ────────────────────────────────────────────────── */
.aicg-generating-box {
  text-align: center;
  max-width: 420px;
}
.aicg-generating-box h3 { font-size: 1.2rem; margin: 24px 0 12px; }
.aicg-generating-msg { color: #6b7280; font-size: 15px; min-height: 24px; transition: opacity 0.3s; }
.aicg-generating-context { margin-top: 20px; display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.aicg-generating-context span { background: #f3f4f6; color: #6b7280; padding: 4px 12px; border-radius: 999px; font-size: 12px; }

/* ─── Empty state ──────────────────────────────────────────────────────── */
.aicg-empty-state { text-align: center; padding: 60px 20px; }
.aicg-empty-icon { font-size: 48px; margin-bottom: 16px; }
.aicg-empty-state p { color: #6b7280; font-size: 15px; margin-bottom: 20px; }

/* ─── Login notice ─────────────────────────────────────────────────────── */
.aicg-login-notice {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 20px 24px;
  text-align: center;
  margin: 40px auto;
  max-width: 500px;
}
.aicg-login-notice a { color: #2563eb; }

/* ─── Context status ───────────────────────────────────────────────────── */
.aicg-context-status { margin-top: 12px; font-size: 13px; }
.aicg-context-status .aicg-ctx-complete { color: #059669; font-weight: 500; }
.aicg-context-status .aicg-ctx-incomplete { color: #9ca3af; }

/* ─── Step panel indicators ────────────────────────────────────────────── */
.aicg-step-panel { padding: 4px 0; }
.aicg-step-panel + .aicg-step-panel { margin-top: 16px; padding-top: 16px; border-top: 1px solid #f3f4f6; }
.aicg-step-panel h4 { margin: 0 0 12px; font-size: 14px; font-weight: 600; color: #374151; }

/* Disabled topic list when generating directly */
.aicg-topic-list.aicg-disabled {
  opacity: 0.6;
  pointer-events: none;
}

/* ─── Tooltips ─────────────────────────────────────────────────────────── */
.aicg-tooltip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  cursor: pointer;
  vertical-align: middle;
}

.aicg-tooltip-icon {
  font-style: normal;
  font-weight: normal;
  color: #9ca3af;
  font-size: 14px;
  line-height: 1;
  display: inline-block;
  transition: color 0.15s;
}

.aicg-tooltip-icon:hover,
.aicg-tooltip-icon:focus,
.aicg-tooltip-wrap.aicg-active .aicg-tooltip-icon {
  color: #2563eb;
  outline: none;
}

.aicg-tooltip-content {
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 400;
  width: 260px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, transform 0.15s;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  pointer-events: none;
  text-align: left;
  white-space: normal;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  text-transform: none;
  letter-spacing: normal;
}

/* Arrow */
.aicg-tooltip-content::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 5px;
  border-style: solid;
  border-color: #1f2937 transparent transparent transparent;
}

/* Hover state on desktop */
@media (hover: hover) {
  .aicg-tooltip-wrap:hover .aicg-tooltip-content {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-4px);
  }
}

/* Active state for tap on touch screens */
.aicg-tooltip-wrap.aicg-active .aicg-tooltip-content {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(-4px);
}

/* Tooltips next to action buttons */
.aicg-btn-tooltip-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
