/* Copyright (c) 2026 Guido Esser
 * Licensed under the Elastic License 2.0 — see LICENSE file for details.
 * Community Edition — self-hosting free. SaaS/Managed Service requires commercial license. */
/* ============================================================
   BPMN Generator — Dark Theme Styles
   ============================================================ */

:root {
  --bg-primary: #1a1b26;
  --bg-surface: #24283b;
  --bg-surface-hover: #2a2f44;
  --bg-elevated: #2f3349;
  --bg-input: #1e2030;
  --bg-mermaid: #f5f5f5;
  --accent: #7aa2f7;
  --accent-hover: #8ab4f8;
  --accent-dim: #5a8bdf;
  --text-primary: #c0caf5;
  --text-secondary: #a9b1d6;
  --text-muted: #565f89;
  --text-inverse: #1a1b26;
  --border: #3b4261;
  --border-focus: #7aa2f7;
  --success: #9ece6a;
  --warning: #e0af68;
  --error: #f7768e;
  --error-bg: #2d1b24;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --transition: 0.2s ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
    'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
}

/* ---- Reset & Base ---- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---- Layout ---- */
.app-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---- Header ---- */
.app-header {
  text-align: center;
  margin-bottom: 40px;
  padding: 16px 0;
}

.app-header h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #bb9af7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.app-header .subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 4px;
  font-weight: 400;
}

.header-links {
  margin-top: 12px;
}

.header-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--accent);
  border-radius: 6px;
  transition: all var(--transition);
}

.header-link:hover {
  background: var(--accent);
  color: #fff;
}

/* ---- Cards / Sections ---- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.card:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(122, 162, 247, 0.15);
}

/* ---- Config Status ---- */
.config-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.85rem;
  margin-top: 12px;
  color: var(--text-muted);
}

.config-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--error);
  transition: background var(--transition);
}

.config-status .status-dot.connected {
  background: var(--success);
}

.config-status .status-dot.checking {
  background: var(--warning);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.config-status .status-label {
  color: var(--text-secondary);
}

.config-status .config-info {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.config-status .config-example {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.config-status .config-example select {
  appearance: none;
  background: var(--bg-elevated);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 24px 3px 8px;
  font-family: var(--font);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='6'%3E%3Cpath d='M0 0l4 6 4-6z' fill='%237aa2f7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

.config-status .config-example select:hover {
  border-color: var(--accent);
}

.config-status .config-example select:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* ---- Input Area ---- */
.input-section .input-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
  position: relative;
}

.input-wrapper textarea {
  width: 100%;
  min-height: 100px;
  max-height: 240px;
  padding: 14px 48px 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.5;
  resize: vertical;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.input-wrapper textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(122, 162, 247, 0.15);
}

/* ---- Mic Button ---- */
.mic-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  font-size: 1rem;
}

.mic-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--accent);
  border-color: var(--accent);
}

.mic-btn.recording {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
  animation: mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(247, 118, 142, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(247, 118, 142, 0); }
}

/* ---- Primary Button ---- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  background: var(--accent);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  height: fit-content;
  min-height: 48px;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(122, 162, 247, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary .spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--text-inverse);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn-primary.loading .spinner {
  display: inline-block;
}

.btn-primary.loading .btn-text {
  opacity: 0.7;
}

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

/* ---- Error Display ---- */
.error-display {
  display: none;
  padding: 12px 16px;
  background: var(--error-bg);
  border: 1px solid var(--error);
  border-radius: var(--radius);
  color: var(--error);
  font-size: 0.9rem;
  margin-bottom: 20px;
  align-items: center;
  gap: 10px;
}

.error-display.visible {
  display: flex;
}

.error-display .error-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.error-display .error-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 1.1rem;
  opacity: 0.7;
  transition: opacity var(--transition);
}

.error-display .error-close:hover {
  opacity: 1;
}

/* ---- Results Section ---- */
.results-section {
  display: none;
  animation: fadeUp 0.35s ease;
}

.results-section.visible {
  display: block;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---- Mermaid Diagram ---- */
.mermaid-container {
  background: var(--bg-mermaid);
  border-radius: var(--radius);
  padding: 24px;
  overflow-x: auto;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.mermaid-container .mermaid-loading {
  color: var(--text-muted);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.mermaid-container .mermaid-placeholder {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.mermaid-container svg {
  max-width: 100%;
  height: auto;
  cursor: zoom-in;
}

.mermaid-container .zoom-badge {
  position: absolute;
  top: 8px;
  right: 12px;
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  opacity: 0;
  transition: opacity var(--transition);
}

.mermaid-container:hover .zoom-badge {
  opacity: 1;
}

/* ---- Mermaid Zoom Modal ---- */
.zoom-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.92);
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.zoom-modal.open {
  display: flex;
}

.zoom-modal .zoom-wrapper {
  width: 90vw;
  height: 85vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-mermaid);
  border-radius: var(--radius-lg);
  position: relative;
}

.zoom-modal .zoom-wrapper svg {
  transform-origin: center;
  transition: transform 0.15s ease;
}

.zoom-modal .zoom-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: all var(--transition);
}

.zoom-modal .zoom-close:hover {
  background: var(--bg-surface-hover);
  color: var(--error);
}

.zoom-modal .zoom-controls {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.zoom-modal .zoom-controls button {
  padding: 8px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition);
}

.zoom-modal .zoom-controls button:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent);
}

.zoom-modal .zoom-level {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* ---- Tabbed Panel ---- */
.tab-panel {
  margin-top: 20px;
}

.tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.tab-btn {
  padding: 10px 20px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: -1px;
}

.tab-btn:hover {
  color: var(--text-secondary);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 20px;
  max-height: 350px;
  overflow-y: auto;
}

.tab-content.active {
  display: block;
  animation: fadeUp 0.2s ease;
}

.tab-content pre {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

.tab-content .notes-content {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.tab-content .notes-content p {
  margin-bottom: 8px;
}

.tab-content .structure-content {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  line-height: 1.6;
}

.tab-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.tab-actions .btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-family: var(--font);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.tab-actions .btn-sm:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

.tab-actions .btn-sm:active {
  transform: scale(0.97);
}

.tab-actions .btn-sm.copy-success {
  border-color: var(--success);
  color: var(--success);
}

/* ---- Iteration Input ---- */
.iteration-section {
  margin-top: 20px;
  animation: fadeUp 0.3s ease;
}

.iteration-section .iteration-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.iteration-section .iteration-input-wrapper {
  flex: 1;
}

.iteration-section input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.iteration-section input::placeholder {
  color: var(--text-muted);
}

.iteration-section input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(122, 162, 247, 0.15);
}

/* ---- Downloads Section ---- */
.download-section {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  font-size: 0.88rem;
  font-family: var(--font);
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-download:hover {
  background: var(--accent-hover);
}

.btn-download:active {
  transform: scale(0.97);
}

.btn-download:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-editor {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  font-size: 0.88rem;
  font-family: var(--font);
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-editor:hover {
  background: var(--accent-hover);
}

.btn-editor:active {
  transform: scale(0.97);
}

.btn-editor:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.download-section {
  display: flex;
  gap: 10px;
  padding: 16px 0 8px 0;
}

/* ---- Guide Section ---- */
details.guide-section {
  cursor: pointer;
}

details.guide-section summary {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 4px 0;
  transition: color var(--transition);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

details.guide-section summary::before {
  content: '▸';
  display: inline-block;
  font-size: 0.7rem;
  transition: transform var(--transition);
  color: var(--text-muted);
}

details.guide-section[open] summary::before {
  transform: rotate(90deg);
}

details.guide-section summary:hover {
  color: var(--accent);
}

.guide-content {
  margin-top: 16px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.guide-content ul {
  padding-left: 20px;
  margin: 10px 0;
}

.guide-content ul li {
  margin-bottom: 6px;
}

.guide-content ul li strong {
  color: var(--accent);
}

.guide-content .guide-hint {
  margin-top: 14px;
  padding: 10px 14px;
  background: rgba(122, 162, 247, 0.08);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .app-container {
    padding: 20px 16px 48px;
  }

  .app-header h1 {
    font-size: 1.5rem;
  }

  .input-section .input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-primary {
    justify-content: center;
  }

  .iteration-section .iteration-row {
    flex-direction: column;
    align-items: stretch;
  }

  .tab-btn {
    padding: 8px 12px;
    font-size: 0.82rem;
  }

  .tab-content {
    max-height: 250px;
  }

  .card {
    padding: 16px;
  }
}

/* ---- Utility ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
