/* ============================================================
   AI Design Platform — Custom Styles
   Tailwind CDN handles utilities; this file covers custom
   components that can't be expressed with Tailwind alone.
   ============================================================ */

/* ---------- Root Variables ---------- */
:root {
  --color-canvas-bg: #0f172a;
  --color-node-bg: #1e293b;
  --color-node-border: #334155;
  --color-input: #3b82f6;
  --color-model: #8b5cf6;
  --color-utility: #f59e0b;
  --color-output: #10b981;
  --color-accent: #6366f1;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #0f172a; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ---------- Node Canvas ---------- */
.node-canvas-wrapper {
  position: relative;
  overflow: auto;
  width: 100%;
  height: 100%;
  background: var(--color-canvas-bg);
  cursor: default;
}

.node-canvas {
  position: relative;
  width: 3000px;
  height: 2000px;
  background-image:
    radial-gradient(circle, #1e293b 1px, transparent 1px);
  background-size: 28px 28px;
}

/* ---------- Workflow Node ---------- */
.workflow-node {
  position: absolute;
  min-width: 200px;
  max-width: 240px;
  background: var(--color-node-bg);
  border: 2px solid var(--color-node-border);
  border-radius: 10px;
  cursor: default;
  user-select: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  z-index: 10;
  transition: box-shadow 0.15s;
}

.workflow-node.selected {
  box-shadow:
    0 0 0 2px var(--color-accent),
    0 4px 20px rgba(0, 0, 0, 0.5);
}

.workflow-node.running .node-status {
  background: #fbbf24;
  animation: blink 0.6s ease-in-out infinite;
}

.workflow-node.done .node-status { background: #10b981; }
.workflow-node.error .node-status { background: #ef4444; }

/* ---------- Node Header ---------- */
.node-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px 8px 0 0;
  cursor: move;
  user-select: none;
}

.node-icon { font-size: 14px; flex-shrink: 0; }

.node-label {
  flex: 1;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-status {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: transparent;
  flex-shrink: 0;
}

.node-delete {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}
.node-delete:hover {
  color: #fff;
  background: rgba(239, 68, 68, 0.4);
}

/* ---------- Node Body & Ports ---------- */
.node-body {
  padding: 8px 10px;
}

.port-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
  min-height: 20px;
}

.output-row { justify-content: flex-end; }

.port {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #475569;
  background: var(--color-node-bg);
  cursor: crosshair;
  flex-shrink: 0;
  transition: transform 0.12s, background 0.12s, border-color 0.12s;
  position: relative;
}

.port:hover { transform: scale(1.4); }
.input-port  { border-color: var(--color-input); }
.output-port { border-color: var(--color-output); }

.port.port-connected  { background: #334155; }
.port.connecting-source { background: var(--color-accent); border-color: var(--color-accent); transform: scale(1.4); }

/* pulse on compatible input ports during connection mode */
.connecting-mode .input-port {
  animation: port-pulse 1s ease-in-out infinite;
}

.port-label {
  font-size: 11px;
  color: #64748b;
  white-space: nowrap;
}

/* ---------- SVG Overlay ---------- */
.node-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  overflow: visible;
}

.connection-path {
  pointer-events: stroke;
  cursor: pointer;
  transition: stroke 0.15s, stroke-width 0.15s;
}

.connection-path:hover {
  stroke: #ef4444 !important;
  stroke-width: 3px;
}

/* ---------- Node Palette ---------- */
.palette-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: grab;
  user-select: none;
  border: 1px solid #1e293b;
  background: #0f172a;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
}
.palette-item:hover {
  background: #1e293b;
  border-color: #334155;
}
.palette-item:active { transform: scale(0.97); }

/* ---------- Config Panel ---------- */
.config-panel {
  width: 280px;
  min-width: 280px;
  background: #0f172a;
  border-left: 1px solid #1e293b;
  overflow-y: auto;
  display: flex;
  flex-direction: direction;
  flex-direction: column;
}

.config-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.config-input {
  width: 100%;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 12px;
  padding: 6px 8px;
  outline: none;
  transition: border-color 0.15s;
}
.config-input:focus { border-color: var(--color-accent); }
.config-input::placeholder { color: #475569; }

textarea.config-input { resize: vertical; min-height: 60px; }

/* ---------- Role Cards (Landing) ---------- */
.role-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 36px 48px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  cursor: pointer;
}
.role-card:hover {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.4);
  transform: translateY(-3px);
}
.role-card .role-icon { font-size: 48px; }
.role-card h2 { font-size: 20px; font-weight: 700; color: #f1f5f9; }
.role-card p  { font-size: 13px; color: #64748b; }

/* ---------- Workflow Card ---------- */
.workflow-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 18px;
  transition: border-color 0.15s, transform 0.15s;
}
.workflow-card:hover {
  border-color: #475569;
  transform: translateY(-2px);
}

/* ---------- Status Badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge-draft     { background: rgba(100, 116, 139, 0.2); color: #94a3b8; }
.badge-published { background: rgba(16, 185, 129, 0.15); color: #34d399; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

/* ---------- Toast ---------- */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  animation: slide-in 0.2s ease;
}
.toast-success { background: #059669; }
.toast-error   { background: #dc2626; }
.toast-info    { background: #4f46e5; }

/* ---------- Client Form ---------- */
.client-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 6px;
}
.client-input {
  width: 100%;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #f1f5f9;
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
}
.client-input:focus { border-color: var(--color-accent); }
.client-input::placeholder { color: #475569; }

/* ---------- Result Block ---------- */
.result-block {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 16px;
}
.result-block h3 {
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.result-text {
  color: #e2e8f0;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.result-image {
  max-width: 100%;
  border-radius: 8px;
  display: block;
}

/* ---------- Progress Bar ---------- */
.progress-node {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #0f172a;
  font-size: 13px;
  color: #94a3b8;
  border-left: 3px solid #334155;
}
.progress-node.running { border-color: #fbbf24; color: #fbbf24; }
.progress-node.done    { border-color: #10b981; color: #10b981; }
.progress-node.error   { border-color: #ef4444; color: #ef4444; }

/* ---------- Animations ---------- */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}
@keyframes port-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,0.4); }
  50%       { box-shadow: 0 0 0 4px rgba(99,102,241,0); transform: scale(1.3); }
}
@keyframes slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.spin { animation: spin 0.8s linear infinite; display: inline-block; }

/* ---------- Client Shell ---------- */
:root {
  --client-shell-topbar-height: 72px;
  --client-shell-sidebar-width: 92px;
  --client-shell-bottom-nav-height: 78px;
  --client-shell-bg: #f5f7fc;
  --client-shell-surface: rgba(255, 255, 255, 0.9);
  --client-shell-line: rgba(191, 200, 219, 0.7);
  --client-shell-text: #182338;
  --client-shell-muted: #64748b;
  --client-shell-accent: #5b6cff;
  --client-shell-accent-soft: rgba(91, 108, 255, 0.1);
}

body.client-shell-page {
  background:
    radial-gradient(circle at top left, rgba(91, 108, 255, 0.08), transparent 24%),
    linear-gradient(180deg, #f9fbff 0%, var(--client-shell-bg) 100%);
  padding-top: var(--client-shell-topbar-height);
  padding-left: var(--client-shell-sidebar-width);
}

body.client-shell-page > nav {
  display: none;
}

#client-shell-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 80;
  height: var(--client-shell-topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px 14px 22px;
  border-bottom: 1px solid var(--client-shell-line);
  background: rgba(248, 250, 255, 0.86);
  backdrop-filter: blur(18px);
}

.client-shell-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.client-shell-brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(91, 108, 255, 0.14);
  background: linear-gradient(135deg, #ffffff 0%, #eef2ff 100%);
  box-shadow: 0 8px 18px rgba(91, 108, 255, 0.08);
  color: var(--client-shell-accent);
  font-size: 18px;
  font-weight: 700;
}

.client-shell-brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.client-shell-brand-title {
  color: var(--client-shell-text);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.client-shell-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.client-shell-pill,
.client-shell-icon-btn,
.client-shell-avatar {
  border: 1px solid var(--client-shell-line);
  background: var(--client-shell-surface);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
}

.client-shell-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--client-shell-muted);
  font-size: 13px;
  font-weight: 600;
}

.client-shell-pill strong {
  color: var(--client-shell-text);
}

.client-shell-icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--client-shell-accent);
  text-decoration: none;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.client-shell-icon-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(91, 108, 255, 0.34);
}

.client-shell-avatar {
  min-width: 42px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--client-shell-text);
  font-size: 14px;
  font-weight: 700;
}

.client-shell-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#client-shell-sidebar {
  position: fixed;
  left: 0;
  top: var(--client-shell-topbar-height);
  bottom: 0;
  z-index: 70;
  width: var(--client-shell-sidebar-width);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 12px;
  border-right: 1px solid var(--client-shell-line);
  background: rgba(247, 249, 254, 0.88);
  backdrop-filter: blur(14px);
}

.client-shell-nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  border: 1px solid transparent;
  border-radius: 22px;
  color: var(--client-shell-muted);
  text-decoration: none;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.client-shell-nav-link:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.78);
  border-color: rgba(91, 108, 255, 0.14);
  color: var(--client-shell-text);
}

.client-shell-nav-link.is-active {
  background: var(--client-shell-accent-soft);
  border-color: rgba(91, 108, 255, 0.22);
  color: var(--client-shell-accent);
  box-shadow: 0 10px 24px rgba(91, 108, 255, 0.12);
}

.client-shell-nav-icon {
  width: 40px;
  height: 40px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.72);
  font-size: 20px;
}

.client-shell-nav-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.client-shell-nav-text {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

#client-shell-mobile-nav {
  display: none;
}

body.client-shell-page.client-shell-with-app #app {
  height: calc(100vh - var(--client-shell-topbar-height) - 24px);
  margin: 12px;
}

body.client-shell-page.client-shell-with-main main {
  padding-top: 20px;
  padding-bottom: 24px;
}

@media (max-width: 1024px) {
  body.client-shell-page {
    padding-left: 0;
    padding-bottom: var(--client-shell-bottom-nav-height);
  }

  #client-shell-sidebar {
    display: none;
  }

  #client-shell-topbar {
    padding-inline: 16px;
  }

  body.client-shell-page.client-shell-with-app #app {
    height: auto;
    margin: 12px;
  }

  #client-shell-mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 85;
    display: grid;
    gap: 8px;
    padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
    border-top: 1px solid var(--client-shell-line);
    background: rgba(248, 250, 255, 0.92);
    backdrop-filter: blur(18px);
  }

  .client-shell-mobile-link {
    display: flex;
    min-height: 56px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border-radius: 18px;
    color: var(--client-shell-muted);
    text-decoration: none;
    font-size: 11px;
    font-weight: 700;
  }

  .client-shell-mobile-link.is-active {
    color: var(--client-shell-accent);
    background: var(--client-shell-accent-soft);
  }
}

@media (max-width: 640px) {
  :root {
    --client-shell-topbar-height: 64px;
  }

  .client-shell-brand-title {
    font-size: 16px;
  }

  .client-shell-pill {
    padding: 8px 12px;
    font-size: 12px;
  }

  .client-shell-toolbar {
    gap: 8px;
  }
}
