@import url('/css/theme.css');

:root {
  --fb-bg: var(--cb-bg, #F0F4F8);
  --fb-surface: var(--cb-surface, #FFFFFF);
  --fb-surface-2: var(--cb-surface-2, #F5F8FB);
  --fb-border: var(--cb-border, #D1DDE8);
  --fb-text: var(--cb-primary-dark, #1E3A5F);
  --fb-text-soft: var(--cb-muted, #6B8299);
  --fb-muted: var(--cb-muted, #6B8299);
  --fb-accent: var(--cb-primary-dark, #1E3A5F);
  --fb-radius: var(--cb-radius-sm, 6px);
  --fb-header-h: 64px;
  --fb-status-h: 36px;
  --fb-palette-w: 240px;
  --fb-props-w: 320px;
  --fb-node-entry: #4CD964;
  --fb-node-text: #1E3A5F;
  --fb-node-choice: #7c6cf0;
  --fb-node-handoff: #F5A623;
  --fb-node-end: #E74C3C;
}

* { box-sizing: border-box; margin: 0; }

.fb-app {
  font-family: var(--cb-font);
  background: var(--cb-bg-mesh, var(--fb-bg));
  color: var(--fb-text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.fb-app h1,
.fb-app h2,
.fb-app h3,
.fb-app strong,
.fb-brand-text strong,
.fb-node-drag strong,
.fb-empty-canvas h3 {
  color: var(--fb-text);
}

.fb-app select option {
  background: var(--fb-surface);
  color: var(--fb-text);
}

.hidden { display: none !important; }

/* ── Login ── */
.fb-login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(30, 58, 95, 0.35);
  backdrop-filter: blur(8px);
}

.fb-login-box {
  width: min(400px, 92vw);
  padding: 2rem;
  border-radius: var(--fb-radius);
  border: 1px solid var(--fb-border);
  background: var(--fb-surface);
  box-shadow: var(--cb-shadow-glow);
}

.fb-login-box h2 {
  font-size: 1.25rem;
  margin-bottom: 0.35rem;
  color: var(--fb-text);
}

.fb-login-box p {
  color: var(--fb-text-soft);
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
}

.fb-login-box label {
  display: block;
  font-size: 0.78rem;
  color: var(--fb-text-soft);
  margin: 0.65rem 0 0.3rem;
}

.fb-login-box input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--fb-radius);
  border: 1px solid var(--fb-border);
  background: var(--fb-bg);
  color: var(--fb-text);
  font-family: inherit;
}

/* ── Header ── */
.fb-header {
  height: var(--fb-header-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--fb-border);
  background: var(--cb-primary-light);
  flex-shrink: 0;
}

.fb-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 180px;
}

.fb-brand-logo {
  width: 38px;
  height: 38px;
  border-radius: var(--fb-radius);
  background: var(--cb-primary-dark);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.8rem;
  color: #fff;
}

.fb-brand-text strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
}

.fb-brand-text span {
  font-size: 0.72rem;
  color: var(--fb-text-soft);
}

.fb-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--fb-text-soft);
}

.fb-breadcrumb a {
  color: var(--fb-text-soft);
  text-decoration: none;
  transition: color 0.15s;
}

.fb-breadcrumb a:hover { color: var(--fb-accent); }

.fb-breadcrumb .sep { opacity: 0.4; }

.fb-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.fb-select-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.fb-select-wrap label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fb-text-soft);
  padding-left: 0.15rem;
}

.fb-select-wrap select {
  min-width: 140px;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--fb-border);
  background: var(--fb-bg);
  color: var(--fb-text);
  font-family: inherit;
  font-size: 0.82rem;
}

.fb-context-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: var(--cb-primary-light);
  border: 1px solid var(--cb-border);
  font-size: 0.75rem;
  color: var(--fb-accent);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fb-flow-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.fb-flow-badge.draft {
  background: rgba(251, 191, 36, 0.12);
  color: var(--cb-warning);
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.fb-flow-badge.active {
  background: rgba(52, 211, 153, 0.12);
  color: var(--cb-success);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.fb-actions {
  display: flex;
  gap: 0.4rem;
}

/* ── Layout ── */
.fb-main {
  flex: 1;
  display: flex;
  min-height: 0;
}

.fb-palette {
  width: var(--fb-palette-w);
  border-right: 1px solid var(--fb-border);
  background: var(--fb-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fb-panel-head {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--fb-border);
  background: var(--cb-primary-light);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fb-text);
}

.fb-palette-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

.fb-node-drag {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.5rem;
  border-radius: var(--fb-radius);
  border: 1px solid var(--fb-border);
  background: var(--fb-surface-2);
  cursor: grab;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.fb-node-drag:active { cursor: grabbing; }

.fb-node-drag:hover {
  border-color: var(--fb-accent);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.fb-node-drag-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.fb-node-drag.entry .fb-node-drag-icon { background: rgba(52, 211, 153, 0.15); }
.fb-node-drag.text .fb-node-drag-icon { background: rgba(91, 143, 255, 0.15); }
.fb-node-drag.choice .fb-node-drag-icon { background: rgba(167, 139, 250, 0.15); }
.fb-node-drag.handoff .fb-node-drag-icon { background: rgba(251, 191, 36, 0.15); }
.fb-node-drag.end .fb-node-drag-icon { background: rgba(248, 113, 113, 0.15); }

.fb-node-drag strong {
  display: block;
  font-size: 0.82rem;
  margin-bottom: 0.15rem;
  color: var(--fb-text);
  font-weight: 600;
}

.fb-node-drag small {
  font-size: 0.72rem;
  color: var(--fb-text-soft);
  line-height: 1.4;
}

.fb-palette-hint {
  margin-top: 0.75rem;
  padding: 0.65rem;
  border-radius: var(--fb-radius);
  background: var(--cb-primary-light);
  border: 1px dashed var(--fb-border);
  font-size: 0.72rem;
  color: var(--fb-text-soft);
  line-height: 1.45;
}

.fb-shortcuts {
  margin-top: 0.75rem;
  font-size: 0.68rem;
  color: var(--fb-text-soft);
  line-height: 1.6;
}

.fb-shortcuts kbd {
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: var(--fb-bg);
  border: 1px solid var(--fb-border);
  font-family: inherit;
  font-size: 0.65rem;
}

/* ── Canvas ── */
.fb-canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.fb-canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--fb-border);
  background: var(--fb-surface-2);
}

.fb-canvas-toolbar .spacer { flex: 1; }

.fb-zoom-label {
  font-size: 0.75rem;
  color: var(--fb-muted);
  min-width: 3rem;
  text-align: center;
}

.fb-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: var(--fb-bg);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(30, 58, 95, 0.12) 1px, transparent 0);
  background-size: 24px 24px;
}

#drawflow {
  width: 100%;
  height: 100%;
}

.fb-empty-canvas {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  pointer-events: none;
  z-index: 2;
}

.fb-empty-canvas.hidden { display: none; }

.fb-empty-icon {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: var(--cb-gradient-soft);
  border: 1px solid var(--fb-border);
  display: grid;
  place-items: center;
  font-size: 2rem;
  margin-bottom: 1rem;
}

.fb-empty-canvas h3 {
  font-size: 1.1rem;
  margin-bottom: 0.35rem;
  color: var(--fb-text);
}

.fb-empty-canvas p {
  color: var(--fb-text-soft);
  font-size: 0.88rem;
  max-width: 320px;
}

/* ── Drawflow overrides (WMS light theme) ── */
.drawflow,
.drawflow .drawflow-node,
.drawflow .drawflow-node .drawflow_content_node,
.drawflow .drawflow-node .drawflow_content_node * {
  color: var(--fb-text) !important;
}

.drawflow .drawflow-node {
  background: transparent !important;
  border: none !important;
  min-width: 0 !important;
  width: auto !important;
  padding: 0 !important;
  color: var(--fb-text) !important;
}

.drawflow .drawflow-node.selected .fb-node {
  box-shadow: 0 0 0 2px var(--cb-primary-light), 0 0 0 4px var(--fb-accent), 0 8px 24px rgba(30, 58, 95, 0.15);
}

.drawflow .connection .main-path {
  stroke: rgba(30, 58, 95, 0.45) !important;
  stroke-width: 2px !important;
  fill: none !important;
}

.drawflow .connection .main-path:hover {
  stroke: var(--fb-accent) !important;
  stroke-width: 2.5px !important;
}

.drawflow .drawflow-node .input,
.drawflow .drawflow-node .output {
  width: 12px !important;
  height: 12px !important;
  border: 2px solid var(--fb-surface) !important;
  background: var(--fb-accent) !important;
  box-shadow: 0 0 0 2px rgba(30, 58, 95, 0.15);
}

.drawflow .drawflow-node .input:hover,
.drawflow .drawflow-node .output:hover {
  background: var(--cb-primary-2) !important;
  transform: scale(1.15);
}

.drawflow .drawflow-content {
  padding: 0 !important;
}

#drawflow .drawflow {
  min-width: 100%;
  min-height: 100%;
}

.drawflow .drawflow-delete {
  background: var(--fb-node-end) !important;
  color: #fff !important;
  border: 2px solid var(--fb-bg) !important;
}

.fb-node {
  min-width: 200px;
  max-width: 268px;
  border-radius: var(--fb-radius);
  border: 1px solid var(--fb-border);
  background: var(--fb-surface);
  overflow: hidden;
  box-shadow: var(--cb-shadow);
}

.fb-node-accent {
  height: 4px;
  width: 100%;
}

.fb-node.entry .fb-node-accent { background: linear-gradient(90deg, var(--fb-node-entry), #6ee7b7); }
.fb-node.text .fb-node-accent { background: linear-gradient(90deg, var(--fb-node-text), #93c5fd); }
.fb-node.choice .fb-node-accent { background: linear-gradient(90deg, var(--fb-node-choice), #c4b5fd); }
.fb-node.handoff .fb-node-accent { background: linear-gradient(90deg, var(--fb-node-handoff), #fde68a); }
.fb-node.end .fb-node-accent { background: linear-gradient(90deg, var(--fb-node-end), #fca5a5); }

.fb-node-body {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.95rem 1rem 1.05rem;
}

.fb-node-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--fb-radius);
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  flex-shrink: 0;
  background: var(--cb-primary-light);
  border: 1px solid var(--fb-border);
}

.fb-node-copy {
  min-width: 0;
  flex: 1;
}

.fb-node-type {
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fb-text-soft);
  margin-bottom: 0.4rem;
}

.fb-node .preview {
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.78rem;
  color: var(--fb-text);
  line-height: 1.5;
  word-break: break-word;
}

.fb-node strong {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
  color: var(--fb-text);
}

/* ── Properties ── */
.fb-props {
  width: var(--fb-props-w);
  border-left: 1px solid var(--fb-border);
  background: var(--fb-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fb-props-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.15rem 1.25rem 1.5rem;
}

.fb-props-empty {
  text-align: center;
  padding: 2.5rem 1.25rem;
  color: var(--fb-text-soft);
}

.fb-props-empty p {
  color: var(--fb-text-soft);
  line-height: 1.55;
}

.fb-props-empty-icon {
  font-size: 2rem;
  opacity: 0.5;
  margin-bottom: 0.85rem;
}

#props-form {
  display: flex;
  flex-direction: column;
}

.fb-type-badge {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.fb-type-badge.entry { background: rgba(52, 211, 153, 0.18); color: #6ee7b7; border: 1px solid rgba(52, 211, 153, 0.25); }
.fb-type-badge.text { background: rgba(91, 143, 255, 0.18); color: #93c5fd; border: 1px solid rgba(91, 143, 255, 0.25); }
.fb-type-badge.choice { background: rgba(167, 139, 250, 0.18); color: #c4b5fd; border: 1px solid rgba(167, 139, 250, 0.25); }
.fb-type-badge.handoff { background: rgba(251, 191, 36, 0.18); color: #fde68a; border: 1px solid rgba(251, 191, 36, 0.25); }
.fb-type-badge.end { background: rgba(248, 113, 113, 0.18); color: #fca5a5; border: 1px solid rgba(248, 113, 113, 0.25); }

.fb-props label,
#props-form label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--fb-text-soft);
  margin: 1.15rem 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#prop-text-wrap,
#prop-choice-wrap {
  display: flex;
  flex-direction: column;
}

.fb-props input,
.fb-props textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: var(--fb-radius);
  border: 1px solid var(--fb-border);
  background: var(--fb-surface);
  color: var(--fb-text);
  font-family: inherit;
  font-size: 0.86rem;
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.fb-props input:focus,
.fb-props textarea:focus {
  outline: none;
  border-color: var(--fb-accent);
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.12);
}

.fb-props input[readonly] {
  opacity: 0.75;
  cursor: default;
  background: var(--fb-surface-2);
}

.fb-props textarea {
  min-height: 132px;
  resize: vertical;
}

#prop-options {
  min-height: 148px;
}

.fb-props-actions {
  display: flex;
  gap: 0.65rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--fb-border);
}

.fb-props-actions .btn {
  flex: 1;
  min-height: 38px;
  font-weight: 600;
}

.fb-props .btn-danger {
  background: rgba(231, 76, 60, 0.1);
  color: var(--cb-danger);
  border: 1px solid rgba(231, 76, 60, 0.3);
}

.fb-props .btn-danger:hover {
  background: var(--cb-danger);
  color: #fff;
  border-color: var(--cb-danger);
}

/* ── Status bar ── */
.fb-status {
  height: var(--fb-status-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  border-top: 1px solid var(--fb-border);
  background: var(--fb-surface);
  font-size: 0.75rem;
  color: var(--fb-text-soft);
  flex-shrink: 0;
}

.fb-status-msg {
  flex: 1;
  color: var(--fb-text);
}

.fb-status-stats strong {
  color: var(--fb-text);
  font-weight: 600;
}

.fb-status-stats {
  display: flex;
  gap: 1rem;
}

.fb-status-stats span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.fb-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cb-success);
}

.fb-status-dot.warn { background: var(--cb-warning); }

.fb-status-dot.err { background: var(--cb-danger); }

/* ── Toast ── */
.fb-toast-wrap {
  position: fixed;
  bottom: calc(var(--fb-status-h) + 1rem);
  right: 1rem;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.fb-toast {
  padding: 0.65rem 1rem;
  border-radius: var(--fb-radius);
  font-size: 0.85rem;
  border: 1px solid var(--fb-border);
  background: var(--fb-surface);
  color: var(--fb-text);
  box-shadow: var(--cb-shadow);
  animation: fb-toast-in 0.25s ease;
}

.fb-toast.success { border-color: rgba(52, 211, 153, 0.4); }
.fb-toast.error { border-color: rgba(248, 113, 113, 0.4); }

@keyframes fb-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fb-loading {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: grid;
  place-items: center;
  background: rgba(30, 58, 95, 0.25);
  backdrop-filter: blur(4px);
}

.fb-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--fb-border);
  border-top-color: var(--fb-accent);
  border-radius: 50%;
  animation: fb-spin 0.7s linear infinite;
}

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

@media (max-width: 1100px) {
  .fb-palette { width: 200px; }
  .fb-props { width: 260px; }
  .fb-context-chip { display: none; }
}

@media (max-width: 860px) {
  .fb-palette { display: none; }
  .fb-props { position: absolute; right: 0; top: 0; bottom: var(--fb-status-h); z-index: 10; box-shadow: -8px 0 32px rgba(0,0,0,0.4); }
}
