@import "@turbostarter/ui/globals.css";
@import "@turbostarter/ui-web/globals.css";

@source "../../../../../packages/ui";

@layer base {
  @import "@xyflow/react/dist/style.css";

  :root {
    /* Canvas */
    --canvas-bg: oklch(0.985 0.002 247);
    --canvas-grid: oklch(0.92 0.004 286 / 30%);
    /* Nodes */
    --node-bg: oklch(1 0 0);
    --node-border: oklch(0.85 0.01 260);
    --node-selected: oklch(0.623 0.214 260);
    --node-hover: oklch(0.623 0.214 260 / 12%);
    /* Edges */
    --edge-default: oklch(0.65 0.01 286);
    --edge-selected: oklch(0.623 0.214 260);
    /* AI (placeholders for future epics) */
    --ai-accent: oklch(0.623 0.214 260);
    /* Diagram type accents */
    --diagram-bpmn: oklch(0.623 0.214 260);
    --diagram-er: oklch(0.606 0.25 293);
    --diagram-orgchart: oklch(0.723 0.219 150);
    --diagram-architecture: oklch(0.552 0.016 286);
    --diagram-sequence: oklch(0.795 0.184 86);
    --diagram-flowchart: oklch(0.645 0.246 16);
    /* BPMN element-specific colors */
    --bpmn-start-event: #2ecc71;
    --bpmn-end-event: #e74c3c;
    --bpmn-timer-event: #3498db;
    --bpmn-message-event: #f39c12;
    --bpmn-gateway: #3498db;
    --bpmn-data-object: #f39c12;
  }

  .dark {
    --canvas-bg: oklch(0.16 0.005 285);
    --canvas-grid: oklch(0.92 0.004 286 / 15%);
    --node-bg: oklch(0.24 0.006 286);
    --node-border: oklch(0.35 0.01 260);
    --node-selected: oklch(0.623 0.214 260);
    --node-hover: oklch(0.623 0.214 260 / 12%);
    --edge-default: oklch(0.55 0.01 286);
    --edge-selected: oklch(0.623 0.214 260);
    --bpmn-start-event: #27ae60;
    --bpmn-end-event: #c0392b;
    --bpmn-timer-event: #5dade2;
    --bpmn-message-event: #f5b041;
    --bpmn-gateway: #5dade2;
    --bpmn-data-object: #f5b041;
  }

  /* ELK layout animation — only active during auto-layout transitions */
  .react-flow__node.layouting {
    transition: transform 200ms ease-out;
  }

  /* ── BPMN Node Styles ─────────────────────────────────────────────────── */

  .bpmn-activity {
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-bpmn);
    border-radius: 8px;
    padding: 8px 12px;
    min-width: 200px;
    max-width: 280px;
    font-size: 12px;
    cursor: pointer;
  }

  .bpmn-activity-tag {
    font-weight: 600;
    font-size: 11px;
    color: var(--diagram-bpmn);
    margin-bottom: 4px;
  }

  .bpmn-activity-label {
    color: var(--foreground);
    line-height: 1.4;
  }

  .bpmn-subprocess {
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-bpmn);
    border-radius: 8px;
    padding: 8px 12px 20px;
    min-width: 200px;
    max-width: 280px;
    font-size: 12px;
    position: relative;
    cursor: pointer;
  }

  .bpmn-subprocess-marker {
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--diagram-bpmn);
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--diagram-bpmn);
    line-height: 1;
  }

  .bpmn-event-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
  }

  .bpmn-event-label {
    margin-top: 4px;
    font-size: 11px;
    color: var(--muted-foreground);
    text-align: center;
    max-width: 140px;
    word-wrap: break-word;
    line-height: 1.3;
  }

  .bpmn-gateway-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
  }

  .bpmn-data-object-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
  }

  .bpmn-annotation {
    border-left: 2px solid var(--muted-foreground);
    padding: 6px 10px;
    font-size: 11px;
    color: var(--muted-foreground);
    max-width: 220px;
    cursor: pointer;
  }

  .bpmn-annotation-text {
    line-height: 1.4;
  }

  /* ── BPMN Pool & Lane Styles ──────────────────────────────────────────── */

  .bpmn-pool {
    border: 2px solid var(--node-border);
    border-radius: 4px;
    background: transparent;
    pointer-events: none;
    position: relative;
  }

  .bpmn-pool-label {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 32px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-weight: 600;
    font-size: 12px;
    color: var(--foreground);
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--node-border);
    pointer-events: auto;
  }

  .bpmn-lane {
    border-top: 1px solid var(--node-border);
    background: transparent;
    pointer-events: none;
    position: relative;
  }

  .bpmn-lane-label {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 24px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-size: 11px;
    color: var(--muted-foreground);
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px dashed var(--node-border);
    pointer-events: auto;
  }

  /* ── BPMN Group Styles ───────────────────────────────────────────────── */

  .bpmn-group {
    border: 2px dashed var(--node-border);
    border-radius: 8px;
    background: transparent;
    pointer-events: none;
    position: relative;
  }

  .bpmn-group-label {
    position: absolute;
    top: -10px;
    left: 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted-foreground);
    background: var(--canvas-bg);
    padding: 0 6px;
    pointer-events: auto;
  }

  /* ── E-R Entity Styles ──────────────────────────────────────────────── */

  .er-entity {
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-er);
    border-radius: 6px;
    min-width: 220px;
    font-size: 12px;
    overflow: hidden;
    cursor: pointer;
  }

  .er-entity-header {
    background: var(--diagram-er);
    color: white;
    font-weight: 600;
    font-size: 13px;
    padding: 6px 12px;
  }

  .er-entity-body {
    padding: 4px 0;
  }

  .er-entity-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 11px;
    line-height: 20px;
  }

  .er-entity-row:hover {
    background: color-mix(in oklch, var(--diagram-er) 5%, transparent);
  }

  .er-entity-indicator {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    font-size: 12px;
  }

  .er-entity-col-name {
    font-weight: 500;
    color: var(--foreground);
    flex: 1;
    min-width: 0;
  }

  .er-entity-col-type {
    color: var(--muted-foreground);
    font-size: 10px;
    flex-shrink: 0;
  }

  .er-entity-constraint {
    color: var(--diagram-er);
    font-size: 10px;
    font-weight: 600;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
  }

  .er-entity-empty {
    color: var(--muted-foreground);
    font-style: italic;
    justify-content: center;
    padding: 8px 10px;
  }

  .er-cardinality {
    background: var(--node-bg);
    border: 1px solid var(--diagram-er);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 10px;
    font-weight: 600;
    color: var(--diagram-er);
  }

  /* ── Org Chart Person Styles ─────────────────────────────────────────── */

  .oc-person {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-orgchart);
    border-left: 4px solid var(--diagram-orgchart);
    border-radius: 8px;
    padding: 10px 14px;
    min-width: 240px;
    max-width: 320px;
    cursor: pointer;
  }

  .oc-person:hover {
    background: color-mix(in oklch, var(--diagram-orgchart) 5%, var(--node-bg));
  }

  .oc-person-avatar {
    font-size: 24px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: color-mix(in oklch, var(--diagram-orgchart) 10%, transparent);
    border-radius: 50%;
  }

  .oc-person-info {
    min-width: 0;
    flex: 1;
  }

  .oc-person-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--foreground);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .oc-person-role {
    font-size: 11px;
    color: var(--muted-foreground);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .oc-person-dept {
    font-size: 10px;
    color: var(--diagram-orgchart);
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ── Architecture Diagram Styles ────────────────────────────────────── */

  .arch-node-icon {
    font-size: 20px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .arch-node-info {
    min-width: 0;
    flex: 1;
  }

  .arch-node-label {
    font-weight: 600;
    font-size: 12px;
    color: var(--foreground);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .arch-node-meta {
    font-size: 10px;
    color: var(--muted-foreground);
    line-height: 1.3;
    font-family: var(--font-mono, ui-monospace, monospace);
  }

  .arch-edge-label {
    font-size: 10px;
    color: var(--diagram-architecture);
    background: var(--node-bg);
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid var(--diagram-architecture);
    font-family: var(--font-mono, ui-monospace, monospace);
    pointer-events: none;
    position: absolute;
  }

  .arch-service {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-architecture);
    border-radius: 8px;
    padding: 10px 14px;
    min-width: 160px;
    max-width: 240px;
    cursor: pointer;
  }

  .arch-service:hover {
    background: color-mix(in oklch, var(--diagram-architecture) 8%, var(--node-bg));
  }

  .arch-database {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-architecture);
    border-top: none;
    border-radius: 0 0 4px 4px;
    padding: 20px 14px 10px;
    min-width: 120px;
    max-width: 200px;
    position: relative;
    cursor: pointer;
  }

  .arch-database::before {
    content: "";
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    height: 20px;
    background: color-mix(in oklch, var(--diagram-architecture) 15%, var(--node-bg));
    border: 1.5px solid var(--diagram-architecture);
    border-radius: 50% / 100%;
  }

  .arch-database:hover {
    background: color-mix(in oklch, var(--diagram-architecture) 8%, var(--node-bg));
  }

  .arch-queue {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-architecture);
    padding: 10px 20px;
    min-width: 140px;
    max-width: 220px;
    transform: skewX(-8deg);
    cursor: pointer;
  }

  .arch-queue > * {
    transform: skewX(8deg);
  }

  .arch-queue:hover {
    background: color-mix(in oklch, var(--diagram-architecture) 8%, var(--node-bg));
  }

  .arch-lb {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-architecture);
    width: 100px;
    height: 100px;
    transform: rotate(45deg);
    cursor: pointer;
  }

  .arch-lb > * {
    transform: rotate(-45deg);
  }

  .arch-lb:hover {
    background: color-mix(in oklch, var(--diagram-architecture) 8%, var(--node-bg));
  }

  .arch-external {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--node-bg);
    border: 2px dashed var(--diagram-architecture);
    border-radius: 20px;
    padding: 10px 16px;
    min-width: 140px;
    max-width: 220px;
    cursor: pointer;
  }

  .arch-external:hover {
    background: color-mix(in oklch, var(--diagram-architecture) 8%, var(--node-bg));
  }

  /* ── Sequence Diagram Styles ────────────────────────────────────────── */

  .seq-participant {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 160px;
  }

  .seq-participant-box {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-sequence);
    border-radius: 6px;
    padding: 8px 14px;
    width: 100%;
    cursor: pointer;
    z-index: 1;
  }

  .seq-participant-box:hover {
    background: color-mix(in oklch, var(--diagram-sequence) 8%, var(--node-bg));
  }

  .seq-participant-icon {
    font-size: 18px;
    flex-shrink: 0;
  }

  .seq-participant-label {
    font-weight: 600;
    font-size: 12px;
    color: var(--foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .seq-lifeline {
    width: 0;
    border-left: 2px dashed var(--diagram-sequence);
    opacity: 0.5;
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
  }

  .seq-activation {
    position: absolute;
    width: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: color-mix(in oklch, var(--diagram-sequence) 20%, var(--node-bg));
    border: 1.5px solid var(--diagram-sequence);
    border-radius: 2px;
    z-index: 1;
  }

  .seq-fragment {
    background: color-mix(in oklch, var(--diagram-sequence) 4%, transparent);
    border: 1.5px solid var(--diagram-sequence);
    border-radius: 4px;
    width: 100%;
    height: 100%;
    position: relative;
  }

  .seq-fragment-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-bottom: 1px solid var(--diagram-sequence);
    border-right: 1px solid var(--diagram-sequence);
    border-bottom-right-radius: 8px;
    width: fit-content;
  }

  .seq-fragment-type {
    font-weight: 700;
    font-size: 11px;
    color: var(--diagram-sequence);
    text-transform: uppercase;
    font-family: monospace;
  }

  .seq-fragment-guard {
    font-size: 11px;
    color: var(--muted-foreground);
    font-family: monospace;
  }

  .seq-edge-label {
    font-size: 11px;
    color: var(--diagram-sequence);
    background: var(--node-bg);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: monospace;
    pointer-events: none;
    white-space: nowrap;
  }

  .seq-edge-label-positioned {
    position: absolute;
  }

  /* ── Flowchart Diagram Styles ─────────────────────────────────── */

  .flow-process {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-flowchart);
    border-radius: 6px;
    padding: 10px 16px;
    min-width: 120px;
    cursor: pointer;
  }
  .flow-process:hover {
    background: color-mix(in oklch, var(--diagram-flowchart) 8%, var(--node-bg));
  }

  .flow-decision {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 140px;
    height: 80px;
    cursor: pointer;
  }

  .flow-decision-diamond {
    width: 90px;
    height: 90px;
    transform: rotate(45deg);
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-flowchart);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .flow-decision-diamond:hover {
    background: color-mix(in oklch, var(--diagram-flowchart) 8%, var(--node-bg));
  }

  .flow-decision-label {
    transform: rotate(-45deg);
    font-weight: 600;
    font-size: 11px;
    color: var(--foreground);
    text-align: center;
    max-width: 80px;
    word-wrap: break-word;
    line-height: 1.3;
  }

  .flow-terminal {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-flowchart);
    border-radius: 999px;
    padding: 10px 24px;
    min-width: 100px;
    cursor: pointer;
  }
  .flow-terminal:hover {
    background: color-mix(in oklch, var(--diagram-flowchart) 8%, var(--node-bg));
  }
  .flow-terminal-start {
    border-color: var(--diagram-flowchart);
    border-width: 2px;
  }
  .flow-terminal-end {
    border-color: var(--diagram-flowchart);
    border-width: 2.5px;
  }

  .flow-io {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .flow-io-skew {
    display: flex;
    align-items: center;
    background: var(--node-bg);
    border: 1.5px solid var(--diagram-flowchart);
    padding: 10px 20px;
    transform: skewX(-10deg);
    min-width: 120px;
  }
  .flow-io-skew:hover {
    background: color-mix(in oklch, var(--diagram-flowchart) 8%, var(--node-bg));
  }
  .flow-io-skew .flow-node-label {
    transform: skewX(10deg);
  }

  .flow-subprocess {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--node-bg);
    border: 2px solid var(--diagram-flowchart);
    border-radius: 6px;
    padding: 4px;
    cursor: pointer;
  }
  .flow-subprocess:hover {
    background: color-mix(in oklch, var(--diagram-flowchart) 8%, var(--node-bg));
  }

  .flow-subprocess-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--diagram-flowchart);
    border-radius: 4px;
    padding: 8px 14px;
    width: 100%;
  }

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

  .flow-node-label {
    font-weight: 600;
    font-size: 12px;
    color: var(--foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .flow-edge-label {
    font-size: 11px;
    color: var(--diagram-flowchart);
    background: var(--node-bg);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid color-mix(in oklch, var(--diagram-flowchart) 30%, transparent);
    font-weight: 600;
    pointer-events: none;
    white-space: nowrap;
  }

  /* ── Path Highlighting ────────────────────────────────────────────────── */

  .react-flow__node.dimmed,
  .react-flow__edge.dimmed {
    opacity: 0.2;
    transition: opacity 200ms ease-out;
  }

  .react-flow__node.highlighted {
    filter: drop-shadow(0 0 6px var(--node-selected));
    transition: filter 200ms ease-out;
  }
}
