/* CSS variables matching premium light-theme */
    :root {
        --bg: #f8fafc;
        --sidebar-bg: #ffffff;
        --surface: #ffffff;
        --border: #e2e8f0;
        --border-bright: #cbd5e1;
        --text: #0f172a;
        --text-dim: #64748b;
        --accent: #4f46e5; /* Indigo */
        --accent-dim: rgba(79, 70, 229, 0.08);
        --green: #059669; /* Emerald */
        --green-dim: rgba(5, 150, 105, 0.08);
        --amber: #d97706; /* Amber */
        --amber-dim: rgba(217, 119, 6, 0.08);
        --red: #dc2626; /* Red */
        --red-dim: rgba(220, 38, 38, 0.08);
        --cyan: #0891b2; /* Cyan */
        --cyan-dim: rgba(8, 145, 178, 0.08);
        
        --font-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
        --font-mono: 'JetBrains Mono', monospace;
    }

    * { box-sizing: border-box; margin: 0; padding: 0; }
    
    body {
        font-family: var(--font-sans);
        background: radial-gradient(ellipse at bottom right, #f1f5f9, var(--bg));
        color: var(--text);
        min-height: 100vh;
        display: grid;
        grid-template-columns: 280px 1fr;
        line-height: 1.6;
        overflow-x: hidden;
    }

    /* SIDEBAR STYLE */
    aside.app-sidebar {
        background: var(--sidebar-bg);
        border-right: 1px solid var(--border);
        padding: 1.5rem 1rem;
        display: flex;
        flex-direction: column;
        height: 100vh;
        position: sticky;
        top: 0;
        overflow-y: auto;
        z-index: 20;
    }

    .sidebar-header {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding-bottom: 1.25rem;
        border-bottom: 1px solid var(--border);
        margin-bottom: 1rem;
    }

    .logo-icon { font-size: 1.8rem; }

    .logo-text h1 {
        font-size: 1.05rem;
        font-weight: 800;
        background: linear-gradient(135deg, #4f46e5, #818cf8);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    .logo-text p {
        font-size: 0.62rem;
        color: var(--text-dim);
        letter-spacing: 0.5px;
        text-transform: uppercase;
    }

    .sidebar-nav {
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
        flex-grow: 1;
    }

    .menu-title {
        font-size: 0.68rem;
        font-weight: 700;
        color: var(--text-dim);
        letter-spacing: 1px;
        margin: 0.75rem 0 0.35rem 0.25rem;
        text-transform: uppercase;
    }

    .nav-item {
        display: flex;
        align-items: center;
        gap: 0.65rem;
        padding: 0.65rem 0.75rem;
        border-radius: 0.5rem;
        color: var(--text-dim);
        text-decoration: none;
        font-size: 0.8rem;
        font-weight: 600;
        border: 1px solid transparent;
        transition: all 0.2s ease;
        cursor: pointer;
    }

    .nav-item:hover, .nav-item.active {
        background: rgba(0, 0, 0, 0.02);
        color: var(--text);
        border-color: var(--border);
    }

    .nav-item.active {
        background: var(--accent-dim);
        color: #4f46e5;
        border-color: rgba(79, 70, 229, 0.2);
    }

    /* MAIN APP CONTENT */
    main.app-main {
        display: flex;
        flex-direction: column;
        height: 100vh;
        overflow-y: auto;
    }

    .top-bar {
        background: rgba(248, 250, 252, 0.85);
        border-bottom: 1px solid var(--border);
        padding: 0.85rem 2rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: sticky;
        top: 0;
        backdrop-filter: blur(10px);
        z-index: 10;
    }

    .breadcrumb {
        font-weight: 700;
        font-size: 0.92rem;
        background: linear-gradient(135deg, #0f172a, #475569);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    .quick-links {
        display: flex;
        gap: 0.5rem;
    }

    .btn-link {
        font-size: 0.75rem;
        color: var(--text-dim);
        text-decoration: none;
        padding: 0.4rem 0.75rem;
        border: 1px solid var(--border);
        border-radius: 0.35rem;
        background: rgba(0, 0, 0, 0.02);
        transition: all 0.25s;
        font-weight: 600;
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }

    .btn-link:hover {
        color: var(--text);
        border-color: var(--border-bright);
        background: rgba(0, 0, 0, 0.05);
    }

    .btn-link.highlight {
        color: var(--accent);
        border-color: rgba(79, 70, 229, 0.3);
        background: var(--accent-dim);
    }

    .btn-link.highlight:hover {
        background: rgba(79, 70, 229, 0.2);
        border-color: rgba(79, 70, 229, 0.5);
    }

    .content-area {
        padding: 2rem;
        max-width: 100%;
        width: 100%;
        margin: 0;
        box-sizing: border-box;
        flex-grow: 1;
        display: flex;
        flex-direction: column;
    }

    /* Glass Cards */
    .glass-card {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 0.75rem;
        padding: 1.5rem;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.03);
        margin-bottom: 1.5rem;
        transition: border-color 0.25s ease;
    }

    .glass-card:hover {
        border-color: var(--border-bright);
    }

    .glass-card h2 {
        font-size: 1.25rem;
        font-weight: 750;
        margin-bottom: 1rem;
        display: flex;
        align-items: center;
        gap: 0.5rem;
        color: var(--text);
    }

    .btn {
      background: var(--accent);
      border: 1px solid rgba(0, 0, 0, 0.05);
      color: #fff;
      padding: 8px 16px;
      border-radius: 6px;
      cursor: pointer;
      font-size: 0.75rem;
      font-weight: 700;
      transition: all 0.2s ease;
      display: inline-flex;
      align-items: center;
      gap: 5px;
      text-decoration: none;
      box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2);
    }

    .btn:hover {
      background: #4338ca;
      transform: translateY(-1px);
    }

    .btn-secondary {
      background: var(--surface);
      border: 1px solid var(--border);
      color: var(--text);
      box-shadow: none;
    }

    .btn-secondary:hover {
      background: rgba(0, 0, 0, 0.02);
      border-color: var(--border-bright);
    }

    .btn-success {
      background: var(--green);
      box-shadow: 0 2px 4px rgba(5, 150, 105, 0.2);
    }

    .btn-success:hover {
      background: #047857;
    }

    /* Info card templates grid */
    .template-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 15px;
      margin-top: 15px;
    }

    .info-card {
      border: 1px solid var(--border);
      background: #ffffff;
      border-radius: 8px;
      padding: 12px;
      transition: border-color 0.2s;
    }

    .info-card:hover {
      border-color: var(--border-bright);
    }

    .info-card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-weight: 700;
      font-size: 0.8rem;
      border-bottom: 1px solid var(--border);
      padding-bottom: 6px;
      margin-bottom: 8px;
    }

    .badge {
      font-family: var(--font-mono);
      font-size: 0.62rem;
      padding: 2px 6px;
      border-radius: 4px;
      font-weight: 700;
      border: 0.5px solid transparent;
    }

    .badge-primary { background: var(--accent-dim); color: var(--accent); border-color: rgba(79, 70, 229, 0.1); }
    .badge-warning { background: var(--amber-dim); color: var(--amber); border-color: rgba(217, 119, 6, 0.1); }
    .badge-success { background: var(--green-dim); color: var(--green); border-color: rgba(5, 150, 105, 0.1); }
    .badge-cyan { background: var(--cyan-dim); color: var(--cyan); border-color: rgba(8, 145, 178, 0.1); }

    .step-item {
      display: flex;
      gap: 6px;
      font-size: 0.75rem;
      padding: 4px 6px;
      background: rgba(0,0,0,0.01);
      border-radius: 4px;
      margin-bottom: 4px;
    }

    .step-item .number {
      font-family: var(--font-mono);
      font-weight: 700;
      color: var(--text-dim);
    }

    /* BOM Editor Cards */
    .bom-component-card {
      border: 1px solid var(--border);
      border-radius: 8px;
      background: #ffffff;
      padding: 14px;
      margin-bottom: 12px;
    }

    .bom-component-name {
      font-weight: 750;
      font-size: 0.82rem;
      border-bottom: 1px dashed var(--border);
      padding-bottom: 8px;
      margin-bottom: 10px;
      display: flex;
      justify-content: space-between;
    }

    .bom-steps-editor {
      display: flex;
      flex-direction: column;
      gap: 6px;
    }

    .editor-step-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background: rgba(0,0,0,0.005);
      padding: 6px 12px;
      border-radius: 6px;
      border: 1px solid var(--border);
      font-size: 0.78rem;
    }

    .editor-step-row input[type="number"] {
      width: 60px;
      padding: 2px 4px;
      border: 1px solid var(--border);
      border-radius: 4px;
      font-family: var(--font-mono);
      font-size: 0.75rem;
      text-align: center;
    }

    .btn-icon-del {
      background: transparent;
      border: none;
      cursor: pointer;
      color: var(--red);
      font-size: 0.85rem;
      padding: 2px;
      transition: opacity 0.2s;
    }

    .btn-icon-del:hover {
      opacity: 0.7;
    }

    /* Timeline horizontal pipelines */
    .group-container {
      border: 1px solid var(--border);
      background: #ffffff;
      border-radius: 8px;
      margin-bottom: 15px;
      padding: 12px;
    }

    .group-title {
      font-weight: 750;
      font-size: 0.82rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 10px;
    }

    .progress-bar-container {
      height: 6px;
      background: #f1f5f9;
      border-radius: 9999px;
      overflow: hidden;
      margin-bottom: 14px;
      cursor: pointer;
    }

    .progress-bar-fill {
      height: 100%;
      background: linear-gradient(90deg, var(--accent), var(--cyan));
      border-radius: 9999px;
      transition: width 0.3s ease;
    }

    .pipeline-view {
      display: flex;
      align-items: center;
      overflow-x: auto;
      padding: 10px 0;
      gap: 5px;
    }

    .pipeline-node {
      border: 1px solid var(--border);
      border-radius: 8px;
      background: #ffffff;
      padding: 8px 12px;
      font-size: 0.75rem;
      text-align: center;
      min-width: 110px;
      position: relative;
      cursor: pointer;
      transition: all 0.2s;
      box-shadow: 0 2px 4px rgba(0,0,0,0.01);
    }

    .pipeline-node:hover {
      border-color: var(--border-bright);
      transform: translateY(-1px);
    }

    .pipeline-node.completed {
      background: var(--green-dim);
      border-color: rgba(5, 150, 105, 0.2);
      color: var(--green);
    }

    .pipeline-node.active {
      background: var(--accent-dim);
      border-color: rgba(79, 70, 229, 0.2);
      color: var(--accent);
      font-weight: 700;
      animation: pulseBorder 1.5s infinite alternate;
    }

    .pipeline-node.new-task {
      background: var(--cyan-dim);
      border-color: rgba(8, 145, 178, 0.2);
      color: var(--cyan);
    }

    @keyframes pulseBorder {
      from { box-shadow: 0 0 0 0px rgba(79, 70, 229, 0.1); }
      to { box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15); }
    }

    .pipeline-node-name {
      font-weight: 700;
      margin-bottom: 2px;
    }

    .pipeline-node-qty {
      font-size: 0.62rem;
      color: var(--text-dim);
    }

    .pipeline-node.completed .pipeline-node-qty {
      color: var(--green);
    }

    .pipeline-connector-wrap {
      display: flex;
      align-items: center;
      gap: 3px;
      color: var(--text-dim);
      font-size: 0.75rem;
    }

    .btn-insert-here {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 999px;
      width: 18px;
      height: 18px;
      font-size: 0.65rem;
      font-weight: 700;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      color: var(--accent);
      transition: all 0.2s;
    }

    .btn-insert-here:hover {
      background: var(--accent);
      color: #fff;
      border-color: var(--accent);
    }

    .node-actions {
      position: absolute;
      top: -6px;
      right: -6px;
      background: var(--red);
      color: #fff;
      border-radius: 999px;
      width: 14px;
      height: 14px;
      font-size: 0.6rem;
      font-weight: 800;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      opacity: 0;
      transition: opacity 0.2s;
    }

    .pipeline-node:hover .node-actions {
      opacity: 1;
    }

    /* Live console box */
    .console-box {
      font-family: var(--font-mono);
      font-size: 0.7rem;
      background: #0f172a;
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 12px;
      color: #e2e8f0;
      height: 140px;
      overflow-y: auto;
      margin-top: 15px;
      box-shadow: inset 0 2px 8px rgba(0,0,0,0.2);
    }

    /* Toast notification */
    .toast-alert {
      position: fixed;
      bottom: 25px;
      right: 25px;
      padding: 12px 24px;
      background: var(--green);
      color: #fff;
      border-radius: 6px;
      font-size: 0.78rem;
      font-weight: 700;
      display: none;
      z-index: 100;
      box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    }

    /* Metrics and Report layout */
    .report-metric-card {
      background: #ffffff;
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 15px;
      display: flex;
      flex-direction: column;
      gap: 4px;
    }

    .sim-view {
      display: none;
    }
    .sim-view.active {
      display: block;
    }
    /* Hierarchical Factory Map Styles */
    .factory-hierarchy-container {
      display: flex;
      flex-direction: column;
      gap: 20px;
      margin-top: 15px;
    }
    .workshop-block {
      background: #f8fafc;
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 15px;
    }
    .workshop-header {
      font-size: 0.8rem;
      font-weight: 800;
      color: var(--accent);
      margin-bottom: 12px;
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .teams-container {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
      gap: 12px;
    }
    .team-card {
      background: #ffffff;
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 10px;
    }
    .team-header {
      font-size: 0.72rem;
      font-weight: 700;
      color: var(--text);
      border-bottom: 1px solid var(--border);
      padding-bottom: 4px;
      margin-bottom: 8px;
    }
    .workers-list {
      display: flex;
      flex-direction: column;
      gap: 6px;
    }
    .worker-node {
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 6px 10px;
      font-size: 0.65rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      transition: all 0.3s ease;
      background: #fafafa;
    }
    .worker-node.active-path {
      border: 1.5px solid var(--accent);
      background: var(--accent-dim);
      box-shadow: 0 0 8px rgba(79, 70, 229, 0.12);
    }
    .worker-node.active-path .node-seq-badge {
      background: var(--accent);
      color: #ffffff;
      border: 1px solid var(--accent);
    }
    .node-seq-badge {
      background: var(--border);
      color: var(--text-dim);
      border-radius: 999px;
      width: 16px;
      height: 16px;
      font-size: 0.58rem;
      font-weight: 800;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .form-select {
      display: block;
      width: 100%;
      height: 28px;
      padding: 4px 8px;
      font-size: 0.75rem;
      font-weight: 600;
      line-height: 1.5;
      color: var(--text);
      background-color: var(--bg);
      border: 1px solid var(--border);
      border-radius: 6px;
      transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
    }
    .form-select:focus {
      border-color: var(--accent);
      outline: 0;
    }

    /* SVG routing connectors & animations */
    .routing-svg-line {
      stroke: var(--accent);
      stroke-width: 3;
      fill: none;
      stroke-dasharray: 8, 8;
      animation: dashflow 1.2s linear infinite;
      transition: stroke 0.3s ease;
    }
    
    @keyframes dashflow {
      from {
        stroke-dashoffset: 16;
      }
      to {
        stroke-dashoffset: 0;
      }
    }

    /* Simulation active package indicator */
    #sim-package {
      position: absolute;
      width: 24px;
      height: 24px;
      background: var(--amber);
      border: 3.5px solid #ffffff;
      border-radius: 50%;
      box-shadow: 0 0 12px var(--amber), 0 0 4px rgba(0, 0, 0, 0.4);
      z-index: 100;
      display: none;
      transition: left 0.8s cubic-bezier(0.25, 1, 0.5, 1), top 0.8s cubic-bezier(0.25, 1, 0.5, 1);
      pointer-events: none;
    }

    #sim-package::after {
      content: '📦';
      font-size: 0.72rem;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    /* BOM and Factory side-by-side Tree Layout styling */
    .bom-factory-layout {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
        margin-top: 15px;
    }
    
    .tree-card {
        background: #ffffff;
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 20px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.02);
        display: flex;
        flex-direction: column;
        min-height: 520px;
    }
    
    .tree-card h3 {
        font-size: 0.8rem;
        font-weight: 800;
        margin-top: 0;
        margin-bottom: 15px;
        border-bottom: 1px solid var(--border-light);
        padding-bottom: 8px;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    .tree-view {
        font-size: 0.72rem;
        display: flex;
        flex-direction: column;
        gap: 8px;
        position: relative;
    }
    
    .tree-node {
        padding: 6px 12px;
        border-radius: 6px;
        background: #f8fafc;
        border: 1px solid var(--border-light);
        display: flex;
        align-items: center;
        gap: 8px;
        position: relative;
        transition: all 0.25s ease;
    }
    
    .tree-node.product {
        background: #f5f3ff; /* Soft Violet */
        border: 2px solid #8b5cf6; /* Strong Purple Border */
        color: #4c1d95; /* Deep Purple Text */
        font-weight: 800;
        box-shadow: 0 2px 6px rgba(139, 92, 246, 0.1);
    }
    
    .tree-node.subassembly {
        background: #f0f9ff; /* Soft Light Blue */
        border: 2px solid #0284c7; /* Strong Blue Border */
        color: #0369a1; /* Deep Sky Blue Text */
        font-weight: 700;
        box-shadow: 0 2px 6px rgba(2, 132, 199, 0.1);
    }
    
    .tree-node.part {
        background: #f0fdf4; /* Soft Light Green */
        border: 2px solid #16a34a; /* Strong Green Border */
        color: #14532d; /* Deep Green Text */
        font-weight: 600;
        box-shadow: 0 2px 6px rgba(22, 163, 74, 0.1);
    }
    
    .tree-branch {
        padding-left: 20px;
        border-left: 1px dashed #cbd5e1;
        margin-left: 12px;
        display: flex;
        flex-direction: column;
        gap: 8px;
        margin-top: 4px;
        position: relative;
    }
    
    /* Embedded steps list styling */
    .embedded-steps {
        display: flex;
        flex-direction: column;
        gap: 4px;
        margin-top: 4px;
        padding-left: 15px;
        width: 100%;
    }
    
    .step-item {
        padding: 6px 12px;
        border-radius: 4px;
        background: #ffffff;
        border: 1.5px solid var(--border-light);
        font-size: 0.68rem;
        color: var(--text-dim);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 8px;
        transition: all 0.2s ease;
        position: relative;
    }
    
    .step-item:hover {
        border-color: var(--accent);
        color: var(--accent);
        background: var(--accent-dim);
    }
    
    .step-item.active {
        background: #fffbeb !important;
        border-color: var(--amber) !important;
        color: #b45309 !important;
        font-weight: 700;
        box-shadow: 0 2px 8px rgba(245, 158, 11, 0.15);
    }
    
    .step-item.highlight-glow {
        background: var(--accent-dim) !important;
        border-color: var(--accent) !important;
        color: var(--accent) !important;
        box-shadow: 0 0 10px rgba(79, 70, 229, 0.2);
    }
    
    /* Factory Tree Styles */
    .factory-workshop {
        background: #f1f5f9;
        border-color: #cbd5e1;
        color: #334155;
        font-weight: 700;
    }
    
    .factory-team {
        background: #ffffff;
        border-color: var(--border-light);
        color: var(--text);
        font-weight: 600;
    }
    
    .factory-station {
        background: #ecfeff;
        border-color: #a5f3fc;
        color: #0369a1;
        padding: 6px 12px;
        border-radius: 4px;
        cursor: pointer;
        transition: all 0.25s ease;
    }
    
    .factory-station:hover {
        border-color: var(--accent);
        background: var(--accent-dim);
    }
    
    .factory-station.active {
        background: #fee2e2 !important;
        border-color: #ef4444 !important;
        color: #991b1b !important;
        font-weight: 700;
        box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
    }
    
    .factory-station.highlight-glow {
        background: var(--accent-dim) !important;
        border-color: var(--accent) !important;
        color: var(--accent) !important;
        box-shadow: 0 0 10px rgba(79, 70, 229, 0.2);
    }

    /* Step mismatch warning style - Auto glows red without hover */
    .step-item.mismatch {
        border: 2px solid #f87171 !important;
        background: #fee2e2 !important;
        color: #991b1b !important;
        box-shadow: 0 0 8px rgba(239, 68, 68, 0.25) !important;
        animation: mismatchPulse 2s infinite alternate;
    }
    .step-item.mismatch.highlight-glow,
    .step-item.mismatch.active {
        background: #fecaca !important;
        border-color: #ef4444 !important;
        color: #7f1d1d !important;
        box-shadow: 0 0 14px rgba(239, 68, 68, 0.5) !important;
    }

    /* Editor row mismatch style */
    .editor-step-row.row-mismatch {
        background: #fef2f2 !important;
        border-color: #fca5a5 !important;
        box-shadow: inset 3px 0 0 #ef4444;
    }

    @keyframes mismatchPulse {
        from {
            box-shadow: 0 0 4px rgba(239, 68, 68, 0.15);
            border-color: #fca5a5;
        }
        to {
            box-shadow: 0 0 12px rgba(239, 68, 68, 0.45);
            border-color: #ef4444;
        }
    }