/* Mermaid Studio - Modern Glassmorphic Dark Stylesheet */

:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-tertiary: #1f2937;
  --bg-hover: #374151;
  --border-color: #2e3846;
  --border-light: #3b4554;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --accent-emerald: #10b981;
  --accent-emerald-hover: #059669;
  --accent-danger: #ef4444;
  --accent-danger-hover: #dc2626;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --font-hand: 'Caveat', 'Kalam', cursive, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Header & Toolbar */
#appHeader {
  height: 52px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 100;
  gap: 12px;
  flex-shrink: 0;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 6px;
  user-select: none;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.brand-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.2px;
  color: #fff;
}

.brand-badge {
  font-size: 10px;
  font-weight: 700;
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
  padding: 1px 5px;
  border-radius: 4px;
  text-transform: uppercase;
}

.divider {
  width: 1px;
  height: 24px;
  background-color: var(--border-color);
  margin: 0 2px;
}

/* Inputs & Selects */
.select-styled,
.input-styled {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: all 0.15s ease;
}

.select-styled:focus,
.input-styled:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.input-styled {
  width: 140px;
}

.diagram-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-icon {
  font-size: 14px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.btn-primary {
  background-color: var(--accent-blue);
  color: #fff;
  box-shadow: 0 1px 3px rgba(59, 130, 246, 0.4);
}

.btn-primary:hover {
  background-color: var(--accent-blue-hover);
}

.btn-accent {
  background-color: var(--accent-emerald);
  color: #fff;
  box-shadow: 0 1px 3px rgba(16, 185, 129, 0.4);
}

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

.btn-secondary {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-tertiary);
  border-color: var(--border-light);
}

.btn-icon {
  padding: 6px 8px;
  background-color: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  color: #fff;
  background-color: var(--bg-tertiary);
}

.btn-danger:hover {
  color: #f87171;
  border-color: var(--accent-danger);
  background: rgba(239, 68, 68, 0.1);
}

.export-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.save-status {
  font-size: 11px;
  color: #34d399;
  opacity: 0;
  transition: opacity 0.2s ease;
  padding: 0 4px;
}

.save-status.visible {
  opacity: 1;
}

/* Main Workspace */
#main {
  flex: 1;
  display: grid;
  grid-template-columns: 420px 1fr;
  height: calc(100vh - 52px);
  overflow: hidden;
  transition: grid-template-columns 0.25s ease;
}

#main.editor-collapsed {
  grid-template-columns: 0px 1fr;
}

/* Editor Panel */
#editorPanel {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  overflow: hidden;
  height: 100%;
}

.editor-header {
  height: 38px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: rgba(17, 24, 39, 0.7);
}

.editor-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
}

.status-badge.valid {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-badge.error {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.status-badge.rendering {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.editor-body {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

.line-numbers {
  width: 42px;
  padding: 12px 6px 12px 0;
  background: #0d121c;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 20px;
  text-align: right;
  user-select: none;
  overflow: hidden;
  border-right: 1px solid #1a2230;
}

.code-textarea {
  flex: 1;
  background: #0d121c;
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 20px;
  padding: 12px;
  border: none;
  outline: none;
  resize: none;
  white-space: pre;
  tab-size: 2;
  overflow-y: auto;
}

.code-textarea::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.code-textarea::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.editor-footer {
  height: 28px;
  background: #0d121c;
  border-top: 1px solid #1a2230;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-muted);
}

/* Canvas Preview Area */
#preview {
  position: relative;
  overflow: hidden;
  height: 100%;
}

.preview-canvas {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  cursor: grab;
  user-select: none;
}

.preview-viewport {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.preview-svg-wrapper {
  padding: 60px;
  display: inline-block;
}

.preview-svg-wrapper svg {
  max-width: none !important;
  height: auto !important;
  overflow: visible !important;
}

/* Empty & Error States */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 400px;
  min-height: 300px;
  color: var(--text-muted);
  font-size: 16px;
}

.render-error-state {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  padding: 24px;
  max-width: 480px;
  color: #fca5a5;
}

.render-error-state .error-icon {
  font-size: 24px;
  margin-bottom: 8px;
}

.render-error-state .error-title {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 6px;
}

.render-error-state .error-detail {
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  background: rgba(0, 0, 0, 0.3);
  padding: 8px;
  border-radius: var(--radius-sm);
}

/* Non-destructive Error Banner */
.error-banner {
  position: absolute;
  bottom: 20px;
  left: 20px;
  max-width: 480px;
  background: rgba(30, 20, 25, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  animation: slideUp 0.2s ease;
}

.error-banner.hidden {
  display: none !important;
}

.error-banner .error-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.error-banner .error-content {
  flex: 1;
  overflow: hidden;
}

.error-banner .error-heading {
  font-weight: 600;
  font-size: 12px;
  color: #f87171;
  margin-bottom: 2px;
}

.error-banner .error-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #fca5a5;
  white-space: pre-wrap;
  max-height: 80px;
  overflow-y: auto;
}

.error-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
}

.error-close:hover {
  color: #fff;
}

/* Floating Canvas Controls */
.canvas-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: 30px;
  padding: 4px 8px;
  gap: 4px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
}

.ctrl-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s ease;
}

.ctrl-btn:hover {
  background: var(--bg-hover);
  color: #fff;
}

.zoom-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0 6px;
  min-width: 44px;
  text-align: center;
}

/* Disabled button state */
.btn.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Blueprint Read-Only Notice Banner */
.blueprint-banner {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.12), rgba(139, 92, 246, 0.12));
  border-bottom: 1px solid rgba(59, 130, 246, 0.3);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  animation: fadeIn 0.15s ease;
}

.blueprint-banner.hidden {
  display: none !important;
}

.blueprint-banner-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-weight: 500;
}

.blueprint-banner-icon {
  font-size: 14px;
}

.blueprint-banner-text {
  color: #93c5fd;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

/* Blueprints Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.15s ease;
}

.modal-overlay.hidden {
  display: none !important;
}

.modal-dialog {
  width: 100%;
  max-width: 1100px;
  max-height: 88vh;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scaleUp 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-title-group {
  display: flex;
  flex-direction: column;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.2px;
}

.modal-subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.modal-close-btn:hover {
  background: var(--bg-hover);
  color: #fff;
}

.modal-filter-bar {
  padding: 12px 20px;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
  align-items: center;
}

.search-box {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}

.bp-search-input {
  width: 100%;
  padding-left: 34px !important;
}

.bp-category-select {
  min-width: 240px;
}

.blueprints-grid {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  align-content: start;
}

.bp-card {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  transition: all 0.2s ease;
}

.bp-card:hover {
  border-color: var(--accent-blue);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.bp-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.bp-card-cat {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
}

.bp-card-badge {
  font-size: 10px;
  font-weight: 600;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
}

.bp-card-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bp-card-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background-color: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 0 0 12px;
  white-space: pre-wrap;
  max-height: 80px;
  overflow: hidden;
  line-height: 1.4;
}

.bp-load-btn {
  margin-top: auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleUp {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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