/* ==========================================================================
   CMS-Specific Admin Styles
   ========================================================================== */

/* Flow Editor Layout */
.flow-editor-header {
  margin-bottom: var(--space-lg);
}

.flow-editor-layout {
  display: flex;
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  min-height: 600px;
  overflow: hidden;
}

.flow-editor-left {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--color-border);
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
}

.flow-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-md);
  border-bottom: 1px solid var(--color-border);
}

.panel-title {
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
}

.flow-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm);
}

.flow-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-sm);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  margin-bottom: 2px;
}

.flow-list-item:hover {
  background: var(--color-surface);
}

.flow-list-item.active {
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.flow-list-item-info {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  overflow: hidden;
}

.flow-list-order {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.flow-list-item.active .flow-list-order {
  background: var(--color-primary);
  color: white;
}

.flow-list-name {
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flow-list-item-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.flow-list-item:hover .flow-list-item-actions {
  opacity: 1;
}

.flow-move-btn {
  padding: 2px 6px !important;
  font-size: var(--text-xs) !important;
  min-width: auto;
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.flow-move-btn:hover:not(:disabled) {
  background: var(--color-bg-alt);
  color: var(--color-text);
}

.flow-move-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Flow Detail (Main Panel) */
.flow-editor-main {
  flex: 1;
  padding: var(--space-lg);
  overflow-y: auto;
  max-height: 80vh;
}

.flow-empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
}

.flow-detail-header {
  margin-bottom: var(--space-lg);
}

.flow-detail-top {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.flow-name-input {
  font-size: var(--text-lg);
  font-weight: 600;
  border: 1px solid transparent;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast);
}

.flow-name-input:hover {
  border-color: var(--color-border);
}

.flow-name-input:focus {
  border-color: var(--color-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(43, 87, 151, 0.1);
}

.flow-desc-input {
  border: 1px solid transparent;
  resize: none;
  font-size: var(--text-sm);
  transition: border-color var(--transition-fast);
}

.flow-desc-input:hover {
  border-color: var(--color-border);
}

.flow-desc-input:focus {
  border-color: var(--color-primary);
  outline: none;
}

/* Step Cards */
.steps-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.step-card {
  transition: box-shadow var(--transition-fast);
  overflow: hidden;
}

.step-card:hover {
  box-shadow: var(--shadow-md);
}

.step-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: var(--space-sm) 0;
  user-select: none;
}

.step-card-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.step-order {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--color-bg-alt);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.step-type-icon {
  font-size: var(--text-base);
}

.step-title-text {
  font-weight: 500;
  font-size: var(--text-sm);
}

.step-card-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.step-duration {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.step-type-badge {
  font-size: 10px !important;
}

.step-move-btns {
  display: flex;
  gap: 2px;
}

.step-expand-icon {
  display: flex;
  color: var(--color-text-muted);
  transition: transform var(--transition-fast);
}

.step-expanded .step-expand-icon {
  transform: rotate(180deg);
}

/* Step Body (expandable) */
.step-card-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 0;
}

.step-expanded .step-card-body {
  max-height: 1200px;
  padding: var(--space-md) 0;
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-sm);
}

.step-row {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
}

.flex-1 {
  flex: 1;
}

.step-danger-zone {
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
}

/* Assets */
.step-assets {
  margin-top: var(--space-md);
}

.assets-grid {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-top: var(--space-sm);
}

.asset-thumb {
  position: relative;
  width: 80px;
  height: 80px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.asset-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.asset-file-icon {
  font-size: var(--text-xs);
  text-align: center;
  padding: var(--space-xs);
  word-break: break-all;
  color: var(--color-text-muted);
}

.asset-delete-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  width: 18px;
  height: 18px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.asset-thumb:hover .asset-delete-btn {
  opacity: 1;
}

.add-step-area {
  margin-top: var(--space-lg);
  text-align: center;
}

.add-step-btn {
  border-style: dashed;
}

/* AI Chat Side Panel */
.ai-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  height: 100vh;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-base);
}

.ai-panel-visible {
  transform: translateX(0);
}

.ai-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.ai-panel-title {
  font-size: var(--text-base);
  font-weight: 700;
}

.ai-panel-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.ai-panel-close {
  background: none;
  border: none;
  font-size: var(--text-xl);
  cursor: pointer;
  color: var(--color-text-muted);
  padding: var(--space-xs);
  line-height: 1;
}

.ai-panel-close:hover {
  color: var(--color-text);
}

/* Scope toggle */
.ai-scope-row,
.ai-model-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.ai-scope-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  width: 44px;
}

.ai-scope-toggle {
  display: flex;
  gap: 2px;
  background: var(--color-bg-alt);
  border-radius: var(--radius-md);
  padding: 2px;
}

.ai-scope-btn {
  flex: 1;
  padding: 3px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  border: none;
  cursor: pointer;
  background: transparent;
  color: var(--color-text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.ai-scope-btn-active {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.ai-scope-btn-off {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Model selector */
.ai-model-select {
  flex: 1;
  font-size: var(--text-xs);
  padding: 4px var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  max-width: 280px;
}

.ai-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.ai-message {
  max-width: 90%;
}

.ai-message-user {
  align-self: flex-end;
}

.ai-message-assistant {
  align-self: flex-start;
}

.ai-message-content {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.ai-message-user .ai-message-content {
  background: var(--color-primary);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

.ai-message-assistant .ai-message-content {
  background: var(--color-bg-alt);
  color: var(--color-text);
  border-bottom-left-radius: var(--radius-sm);
}

.ai-tool-result {
  margin-top: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background: #c6f6d5;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: #22543d;
}

.ai-panel-input {
  padding: var(--space-md);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  flex-shrink: 0;
}

.ai-input-field {
  width: 100%;
  resize: none;
  min-height: auto;
  box-sizing: border-box;
}

.ai-input-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Pending attachments */
.ai-attachments {
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding-bottom: var(--space-xs);
}

.ai-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px var(--space-sm) 2px var(--space-sm);
  font-size: var(--text-xs);
}

.ai-attachment-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-secondary);
}

.ai-attachment-remove {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  color: var(--color-text-muted);
  padding: 0 2px;
}

.ai-attachment-remove:hover {
  color: var(--color-error, #e53e3e);
}

/* Typing indicator (reused in AI panel) */
.ai-typing .ai-message-content {
  padding: var(--space-sm) var(--space-md);
}

.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

/* Preview Frames */
.preview-container {
  display: flex;
  justify-content: center;
  padding: var(--space-xl) 0;
}

.preview-frame {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.preview-phone {
  width: 375px;
}

.phone-bezel {
  background: #1a1a1a;
  border-radius: 36px;
  padding: 12px;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.phone-notch {
  width: 120px;
  height: 24px;
  background: #1a1a1a;
  border-radius: 0 0 14px 14px;
  margin: -12px auto 8px;
  position: relative;
  z-index: 1;
}

.preview-iframe {
  width: 100%;
  height: 667px;
  border: none;
  border-radius: 24px;
  background: white;
}

.preview-print {
  width: 210mm;
  max-width: 100%;
}

.preview-iframe-print {
  width: 100%;
  height: 297mm;
  max-height: 80vh;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: white;
}

.preview-meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Responsive */
@media (max-width: 1200px) {
  .flow-editor-layout {
    flex-direction: column;
  }

  .flow-editor-left {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    max-height: 200px;
  }

  .flow-list {
    display: flex;
    overflow-x: auto;
    padding: var(--space-sm);
    gap: var(--space-sm);
  }

  .flow-list-item {
    white-space: nowrap;
    margin-bottom: 0;
  }

  .ai-chat-panel {
    width: 100%;
  }

  .preview-phone {
    width: 100%;
    max-width: 375px;
  }
}

/* ==========================================================================
   View Instance Detail page
   ========================================================================== */

.detail-header { margin-bottom: var(--space-lg); }
.detail-breadcrumb { margin-bottom: var(--space-sm); }
.detail-back {
  font-size: 13px;
  color: var(--color-text-muted);
  text-decoration: none;
}
.detail-back:hover { color: var(--color-primary); }
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
  margin-top: var(--space-sm);
  font-size: 13px;
  color: var(--color-text-muted);
}
.detail-meta-item { font-size: 13px; }

.detail-actions {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-bottom: var(--space-lg);
}

.pdf-status-banner {
  margin-bottom: var(--space-lg);
}
.pdf-status-banner p {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin: 0;
}
.pdf-status-banner .pdf-ok {
  background: #E6F4EA;
  color: #22543D;
  border-left: 3px solid #22543D;
}
.pdf-status-banner .pdf-stale {
  background: #FFF3E0;
  color: #9C4221;
  border-left: 3px solid #D4740A;
}

.detail-section { margin-top: var(--space-xl); }
.detail-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}
.detail-section-title { font-size: 18px; margin: 0; }

.responses-summary {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
}

.response-session-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--color-surface);
}
.response-session-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}
.session-id {
  font-family: monospace;
  font-size: 12px;
  background: var(--color-bg);
  padding: 2px 6px;
  border-radius: 4px;
}
.response-meta { font-size: 12px; color: var(--color-text-muted); }

.response-step-block { margin-bottom: 14px; }
.response-step-title {
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--color-text-muted);
}
.response-step-flow { font-weight: 600; color: var(--color-primary); }

.response-answer-row {
  background: var(--color-bg);
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 6px;
}
.response-answer-name {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}
.response-answer-type { color: var(--color-text-muted); }
.response-value {
  font-size: 14px;
  white-space: pre-wrap;
  color: var(--color-text);
}

.short-code-link {
  font-family: monospace;
  font-size: 12px;
  color: var(--color-primary);
  text-decoration: underline;
}

/* AI directive cheat-sheet modal */
.ai-cheatsheet {
  font-size: 13px;
  line-height: 1.55;
  max-width: 540px;
}
.ai-cheatsheet h4 {
  font-size: 13px;
  margin: 12px 0 4px;
  color: var(--color-primary);
}
.ai-cheatsheet pre {
  background: var(--color-bg);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12px;
  overflow-x: auto;
  margin: 6px 0;
}
.ai-cheatsheet code { font-size: 12px; }
.ai-help-btn {
  margin-left: 6px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 12px;
  cursor: pointer;
  color: var(--color-text-muted);
}
.ai-help-btn:hover { color: var(--color-primary); border-color: var(--color-primary); }
