/* api_diagram app-specific styles */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: 'Figtree', system-ui, sans-serif;
  color: #fff;
}

body {
  background: linear-gradient(135deg, #2c5171 0%, #4682b4 50%, #6a9bc3 100%);
  min-height: 100vh;
  min-height: 100dvh;
}

/* Layout */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  height: 48px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.app-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
}

.app-header-title img { width: 24px; height: 24px; display: block; }

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-header-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}
.app-header-btn:hover { background: rgba(255, 255, 255, 0.15); }
.app-header-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }

/* Lang switcher */
.lang-switch { display: inline-flex; gap: 2px; background: rgba(255,255,255,0.1); border-radius: 6px; padding: 2px; margin-right: 4px; }
.lang-btn { border: none; background: transparent; color: rgba(255,255,255,0.7); padding: 4px 8px; font-size: 0.75rem; font-weight: 500; cursor: pointer; border-radius: 4px; letter-spacing: 0.5px; }
.lang-btn.active { background: rgba(255,255,255,0.2); color: #fff; }

/* Main */
.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: var(--left-w, 1fr) 6px 1fr;
  gap: 0;
  padding: 12px;
  overflow: hidden;
}
.app-main > .pane:first-child { margin-right: 6px; }
.app-main > .pane:last-child  { margin-left: 6px; }

.splitter {
  cursor: col-resize;
  background: transparent;
  position: relative;
  user-select: none;
  touch-action: none;
}
.splitter::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: 0 2px;
  border-radius: 3px;
  background: rgba(255,255,255,0.35);
  transition: background 0.15s;
}
.splitter:hover::before, .splitter.dragging::before { background: rgba(255,255,255,0.7); }
body.col-resizing { cursor: col-resize !important; user-select: none; }
body.col-resizing * { user-select: none !important; }

@media (max-width: 900px) {
  .app-main { grid-template-columns: 1fr; }
  .splitter { display: none; }
}

/* Panels (non-slide) — left/right work panes */
.pane {
  background: rgba(255, 255, 255, 0.9);
  color: #2c5171;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.pane h2 {
  margin: 0 0 2px 0;
  font-family: 'Raleway', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: #2c5171;
  letter-spacing: 0.3px;
}

.pane-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

textarea.prompt {
  width: 100%;
  min-height: 140px;
  max-height: 40vh;
  padding: 10px;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  font-family: 'Figtree', system-ui, sans-serif;
  font-size: 0.85rem;
  line-height: 1.4;
  resize: vertical;
  background: #fff;
  color: #2c5171;
}
textarea.prompt:focus { outline: none; border-color: #4682b4; box-shadow: 0 0 0 3px rgba(70,130,180,0.15); }

textarea.code {
  width: 100%;
  flex: 1;
  min-height: 160px;
  padding: 10px;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  font-family: 'Poppins Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  line-height: 1.4;
  background: #f6f8fa;
  color: #24292f;
  resize: vertical;
}

select, input[type="text"], input[type="password"] {
  padding: 6px 10px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #fff;
  color: #2c5171;
  font-size: 0.8rem;
  font-family: inherit;
}

/* Compact stacked field: label on top, select below */
.field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.field > .field-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.4px; color: #4a6178; font-weight: 600; line-height: 1; }
.field > select { padding: 3px 6px; font-size: 0.75rem; line-height: 1.2; height: 26px; min-width: 0; width: 100%; }
.field-row { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.field-row .field { flex: 1 1 80px; }
.field-row .field.wide { flex: 1 1 100%; }

.btn {
  padding: 6px 14px;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  background: linear-gradient(135deg, #2c5171, #4682b4);
  color: #fff;
  transition: filter 0.15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn.secondary { background: #e9ecef; color: #2c5171; }
.btn.ghost { background: transparent; color: #2c5171; border: 1px solid #d0d7de; }
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
}
.btn-icon svg { width: 18px; height: 18px; display: block; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-icon.btn-sm { width: 28px; height: 28px; padding: 4px; }
.btn-icon.btn-sm svg { width: 16px; height: 16px; }

.btn-dl { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; }
.btn-dl svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.btn-dl .dl-label { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.3px; }
.pane-row.btn-row { gap: 6px; flex-wrap: nowrap; align-items: center; }
.pane-row.btn-row label { flex: 0 0 auto; white-space: nowrap; }

label { font-size: 0.78rem; color: #2c5171; font-weight: 500; display: flex; align-items: center; gap: 6px; }

.preview {
  flex: 1;
  min-height: 200px;
  background: #fafafa;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview svg { max-width: 100%; max-height: 100%; height: auto; cursor: default; }
.preview svg .pib-host { cursor: pointer; }
.preview svg a { cursor: pointer; }
.preview .placeholder { color: #6e7681; font-size: 0.85rem; font-style: italic; }
.preview { position: relative; }

#code.drag-over { outline: 2px dashed #4682b4; outline-offset: -2px; background: #f0f7ff; }

/* HTML tooltip overlay (always on top, escapes SVG paint order) */
.pib-tip-overlay {
  position: fixed;
  z-index: 99999;
  pointer-events: none;
  background: #1f2937;
  color: #f9fafb;
  font: 12px/1.4 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: 8px 10px;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  max-width: 260px;
  white-space: normal;
  word-wrap: break-word;
  display: none;
}
.pib-tip-overlay.show { display: block; }

#bpmn-editor {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  position: relative;
  min-height: 600px;
  height: 70vh;
}
#bpmn-editor #bpmn-canvas {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  outline: none;
}
#bpmn-editor svg,
#bpmn-canvas svg { max-width: none; max-height: none; height: 100%; width: 100%; }
#bpmn-editor .djs-container { width: 100%; height: 100%; }

.bpmn-attrs {
  display: flex;
  gap: 8px;
  padding: 6px 8px;
  background: #f6f8fa;
  border-bottom: 1px solid #d0d7de;
  align-items: end;
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.bpmn-attrs .field { flex: 1 1 160px; }
.bpmn-attrs .field.wide { flex: 1 1 100%; }
.bpmn-attrs input { padding: 3px 6px; font-size: 0.75rem; height: 26px; width: 100%; }
.bpmn-attrs textarea {
  padding: 4px 6px;
  font-size: 0.75rem;
  width: 100%;
  min-height: 44px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #fff;
  color: #2c5171;
}
.bpmn-attrs .attr-target { font-size: 0.7rem; color: #4a6178; padding: 0 2px 2px 2px; min-width: 0; }
.bpmn-attrs .attr-target b { color: #2c5171; }

.btn-icon.active, .btn-icon[aria-pressed="true"] {
  background: linear-gradient(135deg, #2c5171, #4682b4);
  color: #fff;
  border-color: transparent;
}
.pib-tip-overlay { white-space: normal; }
.pib-tip-overlay a { color: #93c5fd; text-decoration: underline; pointer-events: auto; }
.pib-tip-overlay img { max-width: 100%; height: auto; display: block; }
.pib-tip-overlay code, .pib-tip-overlay kbd { background: rgba(255,255,255,0.1); padding: 1px 4px; border-radius: 3px; }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.72rem;
  color: #57606a;
  line-height: 1;
}
.meta span strong { color: #2c5171; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.3px;
}
.badge.ok { background: #d1f3e0; color: #1a7f3e; }
.badge.err { background: #ffd7d5; color: #cf222e; }
.badge.info { background: #d1e7f3; color: #0969da; }

/* Slide panel */
.slide-panel {
  position: fixed;
  top: 0;
  right: -520px;
  width: 45%;
  max-width: 520px;
  height: 100vh;
  height: 100dvh;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(24px) saturate(180%);
  color: #2c5171;
  box-shadow: -10px 0 40px rgba(0,0,0,0.3);
  transition: right 0.3s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}
.slide-panel.open { right: 0; }
@media (max-width: 768px) { .slide-panel { width: 100%; max-width: none; } }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #e1e4e8;
  font-weight: 600;
  font-family: 'Raleway', sans-serif;
}
.panel-close {
  background: transparent; border: none; color: #57606a; cursor: pointer;
  font-size: 1.2rem; padding: 4px 8px; border-radius: 6px;
}
.panel-close:hover { background: #f0f0f0; }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group input, .form-group select { width: 100%; }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 999;
}
.backdrop.open { opacity: 1; pointer-events: auto; }

/* Footer */
.app-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  height: 42px;
  background: rgba(0,0,0,0.18);
  backdrop-filter: blur(18px);
  font-size: 0.75rem;
  color: rgba(255,255,255,0.85);
}
.app-footer a { color: rgba(255,255,255,0.95); text-decoration: none; font-weight: 500; }
.app-footer a:hover { text-decoration: underline; }
.app-footer .footer-sep { color: rgba(255,255,255,0.4); }

/* Toast */
.toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 10px 18px;
  background: rgba(44,81,113,0.95);
  color: #fff;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 2000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  transition: transform 0.25s, opacity 0.25s;
  opacity: 0;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.err { background: rgba(207,34,46,0.95); }
.toast.ok { background: rgba(26,127,62,0.95); }

/* Doc scan results list */
.doc-diagrams-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}
.doc-diagram-card {
  background: #fff;
  border: 1px solid #e1e4e8;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  line-height: 1;
}
.doc-diagram-card strong { color: #2c5171; font-size: 0.88rem; line-height: 1.2; }
.doc-diagram-card small { color: #57606a; font-size: 0.72rem; }
.doc-diagram-card .mini-svg {
  max-height: 120px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  background: #fafafa;
  border-radius: 6px;
  padding: 4px;
}
.doc-diagram-card .mini-svg svg { max-height: 110px; max-width: 100%; }

/* Help content */
.help-section { line-height: 1.5; font-size: 0.85rem; }
.help-section h3 { margin: 12px 0 4px; color: #2c5171; font-size: 0.95rem; }
.help-section kbd { background: #f0f0f0; padding: 1px 6px; border-radius: 4px; font-size: 0.8rem; font-family: monospace; }

/* Canvas overlay (Excalidraw) */
.canvas-overlay {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 1500;
  display: none;
  flex-direction: column;
}
.canvas-overlay.open { display: flex; }
.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: linear-gradient(135deg, #2c5171, #4682b4);
  color: #fff;
  height: 48px;
  flex: 0 0 auto;
}
.canvas-toolbar-title { display:flex; align-items:center; gap:8px; font-weight:600; font-size:0.9rem; }
.canvas-toolbar-actions { display:flex; gap:6px; }
.canvas-toolbar .btn { background: rgba(255,255,255,0.2); color:#fff; }
.canvas-toolbar .btn:hover { background: rgba(255,255,255,0.32); }
.canvas-toolbar .btn.secondary { background: rgba(0,0,0,0.25); }
#canvas-host { flex: 1; min-height: 0; position: relative; background: #fafafa; }
.canvas-loading {
  position: absolute;
  inset: 48px 0 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(255,255,255,0.95);
  color: #2c5171;
  font-size: 0.95rem;
  z-index: 10;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-left: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
